diff --git a/lib/default.nix b/lib/default.nix index 2b86d67a..904d5a0e 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -21,6 +21,7 @@ lib.makeExtensible ( deprecation = call ./deprecation.nix { }; keymaps = call ./keymap-helpers.nix { }; lua = call ./to-lua.nix { }; + lua-types = call ./lua-types.nix { }; modules = call ./modules.nix { inherit flake; }; options = call ./options.nix { }; plugins = call ./plugins { }; diff --git a/lib/lua-types.nix b/lib/lua-types.nix new file mode 100644 index 00000000..d78741f7 --- /dev/null +++ b/lib/lua-types.nix @@ -0,0 +1,66 @@ +{ lib }: +let + inherit (lib) types; + inherit (lib.nixvim) lua-types; + + # Primitive types that can be represented in lua + primitives = { + inherit (types) + bool + float + int + path + str + ; + }; +in +{ + anything = types.either lua-types.primitive (lua-types.tableOf lua-types.anything) // { + description = "lua value"; + descriptionClass = "noun"; + }; + + # TODO: support merging list+attrs -> unkeyedAttrs + tableOf = + elemType: + assert lib.strings.hasPrefix "lua" elemType.description; + types.oneOf [ + (types.listOf elemType) + (types.attrsOf elemType) + types.luaInline + types.rawLua + ] + // { + description = "lua table of ${ + lib.types.optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType + }"; + descriptionClass = "composite"; + }; + + primitive = + types.nullOr ( + types.oneOf ( + [ + types.luaInline + types.rawLua + ] + ++ builtins.attrValues primitives + ) + ) + // { + description = "lua primitive"; + descriptionClass = "noun"; + }; +} +// builtins.mapAttrs ( + _: wrappedType: + types.oneOf [ + wrappedType + types.luaInline + types.rawLua + ] + // { + description = "lua ${wrappedType.description}"; + descriptionClass = "noun"; + } +) primitives