lib/lua-types: init

An initial set of option types for representing values serialisable into
lua.
This commit is contained in:
Matt Sturgeon 2025-04-24 17:36:16 +01:00 committed by Gaétan Lepage
parent 9328f4437d
commit 57b61e4267
2 changed files with 67 additions and 0 deletions

View file

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

66
lib/lua-types.nix Normal file
View file

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