mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
lib/lua-types: init
An initial set of option types for representing values serialisable into lua.
This commit is contained in:
parent
9328f4437d
commit
57b61e4267
2 changed files with 67 additions and 0 deletions
|
@ -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
66
lib/lua-types.nix
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue