mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
helpers: Add types for lua function & lua code
This allows to display `lua function string` and `lua code string` in the documentation for related options.
This commit is contained in:
parent
0e52776433
commit
4d14c098b6
1 changed files with 21 additions and 14 deletions
|
@ -81,24 +81,19 @@ with lib; rec {
|
||||||
|
|
||||||
mkNullOrLua = desc:
|
mkNullOrLua = desc:
|
||||||
lib.mkOption {
|
lib.mkOption {
|
||||||
type = lib.types.nullOr lib.types.str;
|
type = lib.types.nullOr nixvimTypes.strLua;
|
||||||
default = null;
|
default = null;
|
||||||
description = desc;
|
description = desc;
|
||||||
apply = mkRaw;
|
apply = mkRaw;
|
||||||
};
|
};
|
||||||
|
|
||||||
mkNullOrLuaFn = desc: let
|
mkNullOrLuaFn = desc:
|
||||||
fnDesc = "(lua function)";
|
lib.mkOption {
|
||||||
in
|
type = lib.types.nullOr nixvimTypes.strLuaFn;
|
||||||
mkNullOrLua (
|
default = null;
|
||||||
if desc == ""
|
description = desc;
|
||||||
then fnDesc
|
apply = mkRaw;
|
||||||
else ''
|
};
|
||||||
${desc}
|
|
||||||
|
|
||||||
${fnDesc}
|
|
||||||
''
|
|
||||||
);
|
|
||||||
|
|
||||||
defaultNullOpts = let
|
defaultNullOpts = let
|
||||||
maybeRaw = t: lib.types.either t nixvimTypes.rawLua;
|
maybeRaw = t: lib.types.either t nixvimTypes.rawLua;
|
||||||
|
@ -364,7 +359,16 @@ with lib; rec {
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
|
|
||||||
nixvimTypes =
|
nixvimTypes = let
|
||||||
|
strLikeType = description:
|
||||||
|
mkOptionType {
|
||||||
|
name = "str";
|
||||||
|
inherit description;
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = lib.isString;
|
||||||
|
merge = lib.options.mergeEqualOption;
|
||||||
|
};
|
||||||
|
in
|
||||||
{
|
{
|
||||||
rawLua = mkOptionType {
|
rawLua = mkOptionType {
|
||||||
name = "rawType";
|
name = "rawType";
|
||||||
|
@ -412,6 +416,9 @@ with lib; rec {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
strLua = strLikeType "lua code string";
|
||||||
|
strLuaFn = strLikeType "lua function string";
|
||||||
}
|
}
|
||||||
# Allow to do `with nixvimTypes;` instead of `with types;`
|
# Allow to do `with nixvimTypes;` instead of `with types;`
|
||||||
// types;
|
// types;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue