lib: add basic lz.n plugin spec type

This commit is contained in:
Pei Yang Ching 2024-06-25 17:47:33 +02:00 committed by Pei Yang Ching
parent baf216bb0f
commit efd20adfd9
1 changed files with 73 additions and 8 deletions

View File

@ -6,8 +6,7 @@
inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf;
# Get the names of all flake inputs that start with the given prefix.
fromInputs = {
inputs,
@ -51,8 +50,79 @@
};
};
};
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};
lznPluginType = submodule {
options = {
## Should probably infer from the actual plugin somehow
## In general this is the name passed to packadd, so the dir name of the plugin
# name = mkOption {
# type= str;
# }
package = pluginType;
before = mkOption {
type = nullOr luaInline;
description = "Code to run before plugin is loaded";
default = null;
};
after = mkOption {
type = nullOr luaInline;
description = "Code to run after plugin is loaded";
default = null;
};
event = mkOption {
description = "Lazy-load on event";
default = "null";
type = let
event = submodule {
options = {
event = mkOption {
type = nullOr (either str (listOf str));
description = "Exact event name";
example = "BufEnter";
};
pattern = mkOption {
type = nullOr (either str (listOf str));
description = "Event pattern";
example = "BufEnter *.lua";
};
};
};
in
oneOf [str (listOf str) event];
};
cmd = mkOption {
description = "Lazy-load on command";
default = null;
type = nullOr (either str (listOf str));
};
ft = mkOption {
description = "Lazy-load on filetype";
default = null;
type = nullOr (either str (listOf str));
};
keys = mkOption {
description = "Lazy-load on key mapping";
default = null;
type = nullOr (either str (listOf str)); # TODO: support lz.n.KeysSpec
};
# TODO: enabled, beforeAll, colorscheme, priority, load
};
};
in {
inherit extraPluginType fromInputs pluginType;
inherit extraPluginType fromInputs pluginType luaInline lznPluginType;
pluginsOpt = {
description,
@ -64,11 +134,6 @@ in {
type = pluginsType;
};
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};
/*
opts is a attrset of options, example:
```