2024-01-25 15:43:06 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
nixvimTypes,
|
2024-01-25 16:58:58 +01:00
|
|
|
nixvimUtils,
|
2024-01-25 15:43:06 +01:00
|
|
|
}:
|
2024-01-25 16:58:58 +01:00
|
|
|
with lib;
|
2024-05-05 19:39:35 +02:00
|
|
|
with nixvimUtils;
|
|
|
|
rec {
|
2024-01-25 15:43:06 +01:00
|
|
|
# Creates an option with a nullable type that defaults to null.
|
2024-05-31 19:14:45 +01:00
|
|
|
mkNullOrOption' =
|
|
|
|
{
|
|
|
|
type,
|
|
|
|
default ? null,
|
|
|
|
...
|
|
|
|
}@args:
|
|
|
|
lib.mkOption (
|
|
|
|
args
|
|
|
|
// {
|
|
|
|
type = lib.types.nullOr type;
|
|
|
|
inherit default;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
mkNullOrOption = type: description: mkNullOrOption' { inherit type description; };
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-31 18:41:49 +01:00
|
|
|
mkCompositeOption' =
|
|
|
|
{ options, ... }@args:
|
|
|
|
mkNullOrOption' (
|
|
|
|
(filterAttrs (n: _: n != "options") args) // { type = types.submodule { inherit options; }; }
|
|
|
|
);
|
|
|
|
mkCompositeOption = description: options: mkCompositeOption' { inherit description options; };
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-31 19:16:13 +01:00
|
|
|
mkNullOrStr' = args: mkNullOrOption' (args // { type = with nixvimTypes; maybeRaw str; });
|
|
|
|
mkNullOrStr = description: mkNullOrStr' { inherit description; };
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-31 19:16:50 +01:00
|
|
|
mkNullOrLua' =
|
|
|
|
args:
|
|
|
|
mkNullOrOption' (
|
|
|
|
args
|
|
|
|
// {
|
|
|
|
type = nixvimTypes.strLua;
|
|
|
|
apply = mkRaw;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
mkNullOrLua = description: mkNullOrLua' { inherit description; };
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-31 19:17:13 +01:00
|
|
|
mkNullOrLuaFn' =
|
|
|
|
args:
|
|
|
|
mkNullOrOption' (
|
|
|
|
args
|
|
|
|
// {
|
|
|
|
type = nixvimTypes.strLuaFn;
|
|
|
|
apply = mkRaw;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
mkNullOrLuaFn = description: mkNullOrLua' { inherit description; };
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-31 19:17:43 +01:00
|
|
|
mkNullOrStrLuaOr' =
|
|
|
|
{ type, ... }@args:
|
|
|
|
mkNullOrOption' (
|
|
|
|
args
|
|
|
|
// {
|
|
|
|
type = with nixvimTypes; either strLua type;
|
|
|
|
apply = v: if isString v then mkRaw v else v;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
mkNullOrStrLuaOr = type: description: mkNullOrStrLuaOr' { inherit type description; };
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-31 19:18:17 +01:00
|
|
|
mkNullOrStrLuaFnOr' =
|
|
|
|
{ type, ... }@args:
|
|
|
|
mkNullOrOption' (
|
|
|
|
args
|
|
|
|
// {
|
|
|
|
type = with nixvimTypes; either strLuaFn type;
|
|
|
|
apply = v: if isString v then mkRaw v else v;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
mkNullOrStrLuaFnOr = type: description: mkNullOrStrLuaFnOr' { inherit type description; };
|
2024-01-25 15:43:06 +01:00
|
|
|
|
|
|
|
defaultNullOpts = rec {
|
2024-05-31 16:26:24 +01:00
|
|
|
/**
|
|
|
|
Build a description with a plugin 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
|
|
|
|
```
|
2024-05-28 18:49:16 +01:00
|
|
|
|
2024-05-31 16:26:24 +01:00
|
|
|
# Arguments
|
|
|
|
- [default] The plugin's default
|
|
|
|
- [desc] The option's description
|
|
|
|
*/
|
2024-05-17 10:30:31 +02:00
|
|
|
mkDesc =
|
|
|
|
default: desc:
|
|
|
|
let
|
2024-05-31 16:26:24 +01:00
|
|
|
# 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}`"
|
|
|
|
);
|
2024-05-17 10:30:31 +02:00
|
|
|
in
|
|
|
|
if desc == "" then
|
|
|
|
defaultDesc
|
|
|
|
else
|
|
|
|
''
|
|
|
|
${desc}
|
|
|
|
|
|
|
|
${defaultDesc}
|
|
|
|
'';
|
|
|
|
|
2024-05-31 19:18:58 +01:00
|
|
|
mkNullable' =
|
|
|
|
{ default, description, ... }@args:
|
|
|
|
mkNullOrOption' (
|
|
|
|
args
|
|
|
|
// {
|
|
|
|
default = null;
|
|
|
|
description = mkDesc default description;
|
|
|
|
}
|
|
|
|
);
|
2024-05-05 19:39:35 +02:00
|
|
|
mkNullable =
|
2024-05-31 19:18:58 +01:00
|
|
|
type: default: description:
|
|
|
|
mkNullable' { inherit type default description; };
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-16 12:33:29 +02:00
|
|
|
mkNullableWithRaw = type: mkNullable (nixvimTypes.maybeRaw type);
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
mkStrLuaOr =
|
|
|
|
type: default: desc:
|
2024-05-17 10:30:31 +02:00
|
|
|
mkNullOrStrLuaOr type (mkDesc default desc);
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
mkStrLuaFnOr =
|
|
|
|
type: default: desc:
|
2024-05-17 10:30:31 +02:00
|
|
|
mkNullOrStrLuaFnOr type (mkDesc default desc);
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-17 10:30:31 +02:00
|
|
|
mkLua = default: desc: mkNullOrLua (mkDesc default desc);
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-17 10:30:31 +02:00
|
|
|
mkLuaFn = default: desc: mkNullOrLuaFn (mkDesc default desc);
|
2024-01-25 15:43:06 +01:00
|
|
|
|
2024-05-30 03:08:40 +01:00
|
|
|
mkNum = mkNullableWithRaw types.number;
|
|
|
|
mkInt = mkNullableWithRaw types.int;
|
2024-01-25 15:43:06 +01:00
|
|
|
# Positive: >0
|
2024-05-30 03:08:40 +01:00
|
|
|
mkPositiveInt = mkNullableWithRaw types.ints.positive;
|
2024-01-25 15:43:06 +01:00
|
|
|
# Unsigned: >=0
|
2024-05-30 03:08:40 +01:00
|
|
|
mkUnsignedInt = mkNullableWithRaw types.ints.unsigned;
|
|
|
|
mkBool = mkNullableWithRaw types.bool;
|
2024-05-29 09:47:01 +01:00
|
|
|
mkStr =
|
|
|
|
# TODO we should delegate rendering quoted string to `mkDefaultDesc`,
|
|
|
|
# once we remove its special case for strings.
|
|
|
|
default:
|
|
|
|
assert default == null || isString default;
|
|
|
|
mkNullableWithRaw types.str (generators.toPretty { } default);
|
2024-05-30 03:08:40 +01:00
|
|
|
mkAttributeSet = mkNullable nixvimTypes.attrs;
|
2024-01-25 15:43:06 +01:00
|
|
|
mkListOf = ty: default: mkNullable (with nixvimTypes; listOf (maybeRaw ty)) default;
|
|
|
|
mkAttrsOf = ty: default: mkNullable (with nixvimTypes; attrsOf (maybeRaw ty)) default;
|
2024-05-30 03:08:22 +01:00
|
|
|
mkEnum =
|
|
|
|
enumValues: default:
|
|
|
|
mkNullableWithRaw (types.enum enumValues) (
|
|
|
|
# TODO we should remove this once `mkDefaultDesc` no longer has a special case
|
|
|
|
if isString default then generators.toPretty { } default else default
|
|
|
|
);
|
2024-01-25 15:43:06 +01:00
|
|
|
mkEnumFirstDefault = enumValues: mkEnum enumValues (head enumValues);
|
2024-05-05 19:39:35 +02:00
|
|
|
mkBorder =
|
|
|
|
default: name: desc:
|
2024-05-16 12:33:29 +02:00
|
|
|
mkNullableWithRaw nixvimTypes.border default (
|
2024-05-05 19:39:35 +02:00
|
|
|
let
|
|
|
|
defaultDesc = ''
|
|
|
|
Defines the border to use for ${name}.
|
|
|
|
Accepts same border values as `nvim_open_win()`. See `:help nvim_open_win()` for more info.
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
if desc == "" then
|
|
|
|
defaultDesc
|
|
|
|
else
|
|
|
|
''
|
|
|
|
${desc}
|
|
|
|
${defaultDesc}
|
|
|
|
''
|
|
|
|
);
|
|
|
|
mkSeverity =
|
|
|
|
default: desc:
|
2024-01-25 15:43:06 +01:00
|
|
|
mkOption {
|
2024-05-05 19:39:35 +02:00
|
|
|
type =
|
|
|
|
with types;
|
|
|
|
nullOr (
|
|
|
|
either ints.unsigned (enum [
|
|
|
|
"error"
|
|
|
|
"warn"
|
|
|
|
"info"
|
|
|
|
"hint"
|
|
|
|
])
|
2024-01-25 15:43:06 +01:00
|
|
|
);
|
|
|
|
default = null;
|
2024-05-05 19:39:35 +02:00
|
|
|
apply = mapNullable (
|
|
|
|
value: if isInt value then value else mkRaw "vim.diagnostic.severity.${strings.toUpper value}"
|
|
|
|
);
|
2024-05-17 10:30:31 +02:00
|
|
|
description = mkDesc default desc;
|
2024-01-25 15:43:06 +01:00
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
mkLogLevel =
|
|
|
|
default: desc:
|
2024-01-25 15:43:06 +01:00
|
|
|
mkOption {
|
2024-05-05 19:39:35 +02:00
|
|
|
type = with types; nullOr (either ints.unsigned nixvimTypes.logLevel);
|
2024-01-25 15:43:06 +01:00
|
|
|
default = null;
|
2024-05-05 19:39:35 +02:00
|
|
|
apply = mapNullable (
|
|
|
|
value: if isInt value then value else mkRaw "vim.log.levels.${strings.toUpper value}"
|
|
|
|
);
|
2024-05-17 10:30:31 +02:00
|
|
|
description = mkDesc default desc;
|
2024-01-25 15:43:06 +01:00
|
|
|
};
|
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
mkHighlight =
|
|
|
|
default: name: desc:
|
|
|
|
mkNullable nixvimTypes.highlight default (if desc == "" then "Highlight settings." else desc);
|
2024-01-25 15:43:06 +01:00
|
|
|
};
|
|
|
|
|
2024-05-17 14:39:55 +02:00
|
|
|
mkPackageOption =
|
|
|
|
{
|
|
|
|
name ? null, # Can be null if a custom description is given.
|
|
|
|
default,
|
|
|
|
description ? null,
|
|
|
|
example ? null,
|
|
|
|
}:
|
|
|
|
mkOption {
|
|
|
|
type = with types; nullOr package;
|
|
|
|
inherit default example;
|
|
|
|
description =
|
|
|
|
if description == null then
|
|
|
|
''
|
|
|
|
Which package to use for `${name}`.
|
|
|
|
Set to `null` to disable its automatic installation.
|
|
|
|
''
|
|
|
|
else
|
|
|
|
description;
|
|
|
|
};
|
|
|
|
|
2024-05-17 14:09:20 +02:00
|
|
|
mkPluginPackageOption =
|
2024-05-05 19:39:35 +02:00
|
|
|
name: default:
|
2024-01-25 15:43:06 +01:00
|
|
|
mkOption {
|
|
|
|
type = types.package;
|
|
|
|
inherit default;
|
2024-05-17 14:09:20 +02:00
|
|
|
description = "Which package to use for the ${name} plugin.";
|
2024-01-25 15:43:06 +01:00
|
|
|
};
|
2024-02-12 16:11:34 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
mkSettingsOption =
|
|
|
|
{
|
|
|
|
options ? { },
|
|
|
|
description,
|
|
|
|
example ? null,
|
|
|
|
}:
|
2024-02-12 16:11:34 +01:00
|
|
|
mkOption {
|
2024-05-05 19:39:35 +02:00
|
|
|
type =
|
|
|
|
with types;
|
2024-02-12 16:11:34 +01:00
|
|
|
submodule {
|
2024-02-13 00:03:07 +01:00
|
|
|
freeformType = attrsOf anything;
|
2024-02-12 16:11:34 +01:00
|
|
|
inherit options;
|
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
default = { };
|
2024-02-12 16:11:34 +01:00
|
|
|
inherit description;
|
|
|
|
example =
|
2024-05-05 19:39:35 +02:00
|
|
|
if example == null then
|
|
|
|
{
|
|
|
|
foo_bar = 42;
|
|
|
|
hostname = "localhost:8080";
|
|
|
|
callback.__raw = ''
|
|
|
|
function()
|
|
|
|
print('nixvim')
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
example;
|
2024-02-12 16:11:34 +01:00
|
|
|
};
|
2024-01-25 15:43:06 +01:00
|
|
|
}
|