Skip to content

lib/lua-types: init #3213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down
66 changes: 66 additions & 0 deletions lib/lua-types.nix
Original file line number Diff line number Diff line change
@@ -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";
};
Comment on lines +18 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure you thought about priorities, but I think adding parentheses would greatly help with readability.


# 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
1 change: 1 addition & 0 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ rec {
{ type, ... }@args: mkNullOrOption' (args // { type = with types; either strLuaFn type; });
mkNullOrStrLuaFnOr = type: description: mkNullOrStrLuaFnOr' { inherit type description; };

# TODO: use lib.nixvim.lua-types
defaultNullOpts =
let
# Ensures that default is null and defaultText is not set
Expand Down