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:
traxys 2024-01-01 23:32:55 +01:00 committed by Gaétan Lepage
parent 0e52776433
commit 4d14c098b6

View file

@ -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;