mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-27 11:08:53 +02:00
lib/options: inline mkDefaultDesc
into mkDesc
And add function documentation.
This commit is contained in:
parent
d15fade62b
commit
57003fea4e
1 changed files with 36 additions and 16 deletions
|
@ -56,26 +56,46 @@ rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
defaultNullOpts = rec {
|
defaultNullOpts = rec {
|
||||||
# Description helpers
|
/**
|
||||||
mkDefaultDesc =
|
Build a description with a plugin default.
|
||||||
defaultValue:
|
|
||||||
let
|
|
||||||
default =
|
|
||||||
# Assume a string default is already formatted as intended,
|
|
||||||
# historically strings were the only type accepted here.
|
|
||||||
# TODO consider deprecating this behavior so we can properly quote strings
|
|
||||||
if isString defaultValue then defaultValue else generators.toPretty { } defaultValue;
|
|
||||||
in
|
|
||||||
"Plugin default:"
|
|
||||||
+ (
|
|
||||||
# Detect whether `default` is multiline or inline:
|
|
||||||
if hasInfix "\n" default then "\n\n```nix\n${default}\n```" else " `${default}`"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
The [default] can be any value, and it will be formatted using `lib.generators.toPretty`.
|
||||||
|
|
||||||
|
If [default] is a String, it will not be formatted.
|
||||||
|
This behavior will likely change in the future.
|
||||||
|
|
||||||
|
# Example
|
||||||
|
```nix
|
||||||
|
mkDesc 1 "foo"
|
||||||
|
=> ''
|
||||||
|
foo
|
||||||
|
|
||||||
|
Plugin default: `1`
|
||||||
|
''
|
||||||
|
```
|
||||||
|
|
||||||
|
# Type
|
||||||
|
```
|
||||||
|
mkDesc :: Any -> String -> String
|
||||||
|
```
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
- [default] The plugin's default
|
||||||
|
- [desc] The option's description
|
||||||
|
*/
|
||||||
mkDesc =
|
mkDesc =
|
||||||
default: desc:
|
default: desc:
|
||||||
let
|
let
|
||||||
defaultDesc = mkDefaultDesc default;
|
# Assume a string default is already formatted as intended,
|
||||||
|
# historically strings were the only type accepted here.
|
||||||
|
# TODO deprecate this behavior so we can properly quote strings
|
||||||
|
defaultString = if isString default then default else generators.toPretty { } default;
|
||||||
|
defaultDesc =
|
||||||
|
"Plugin default:"
|
||||||
|
+ (
|
||||||
|
# Detect whether `default` is multiline or inline:
|
||||||
|
if hasInfix "\n" defaultString then "\n\n```nix\n${defaultString}\n```" else " `${defaultString}`"
|
||||||
|
);
|
||||||
in
|
in
|
||||||
if desc == "" then
|
if desc == "" then
|
||||||
defaultDesc
|
defaultDesc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue