Compare commits

...

3 commits

Author SHA1 Message Date
Pei Yang Ching
5887fa8e8b lazy: move lz.n submodules out of lib 2024-08-25 00:27:14 +02:00
Pei Yang Ching
590590be3f flake: update lz.n and lzn-auto-require 2024-08-25 00:27:14 +02:00
Pei Yang Ching
ff38aeb820 lazy: use listOf plugins instead of attr 2024-08-25 00:27:14 +02:00
5 changed files with 216 additions and 209 deletions

View file

@ -846,11 +846,11 @@
"plugin-lz-n": { "plugin-lz-n": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1719989949, "lastModified": 1724402266,
"narHash": "sha256-oHwmlLgdJJDz5+gs1KLAa2MHQAadM/JYmHGfep9yl28=", "narHash": "sha256-JLCJPiRUt0RFDR/WYZMjkm/keaDo+QNwTII2GyiDAhk=",
"owner": "nvim-neorocks", "owner": "nvim-neorocks",
"repo": "lz.n", "repo": "lz.n",
"rev": "4c790ba2c3789f580aa019712bbe3112f85e73a0", "rev": "fc67ba432830f499c0afadd35f2942c8620aaf1a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -862,11 +862,11 @@
"plugin-lzn-auto-require": { "plugin-lzn-auto-require": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1723928740, "lastModified": 1724239920,
"narHash": "sha256-CMWy+btqUaXUWSO4jZYDfBcNiYMFyRb8jtIdi072WP8=", "narHash": "sha256-wNtja4vbfzgVwVh8fw6cfTHxcxPOqr6z4nl5Fjj2d0I=",
"owner": "horriblename", "owner": "horriblename",
"repo": "lzn-auto-require", "repo": "lzn-auto-require",
"rev": "1b9f6527e32bf196ce239f7a8b9a54d342605511", "rev": "c74fa9be2203438aab7fd132310abdb181426c66",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -6,7 +6,8 @@
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix; inherit (lib.strings) hasPrefix removePrefix;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool int; inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr;
# Get the names of all flake inputs that start with the given prefix. # Get the names of all flake inputs that start with the given prefix.
fromInputs = { fromInputs = {
inputs, inputs,
@ -50,193 +51,8 @@
}; };
}; };
}; };
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};
lznKeysSpec = submodule {
options = {
desc = mkOption {
description = "Description of the key map";
type = nullOr str;
default = null;
};
noremap = mkOption {
description = "TBD";
type = bool;
default = false;
};
expr = mkOption {
description = "TBD";
type = bool;
default = false;
};
nowait = mkOption {
description = "TBD";
type = bool;
default = false;
};
ft = mkOption {
description = "TBD";
type = nullOr (listOf str);
default = null;
};
key = mkOption {
type = str;
description = "Key to bind to";
};
action = mkOption {
type = nullOr str;
default = null;
description = "Action to trigger.";
};
lua = mkOption {
type = bool;
default = false;
description = "If true the action is treated as a lua function instead of a vim command.";
};
mode = mkOption {
description = "Modes to bind in";
type = listOf str;
default = ["n" "x" "s" "o"];
};
};
};
lznPluginTableType = attrsOf lznPluginType;
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;
# }
# Non-lz.n options
package = mkOption {
type = pluginType;
description = "Plugin package";
};
setupModule = mkOption {
type = nullOr str;
description = "Lua module to run setup function on.";
default = null;
};
setupOpts = mkOption {
type = submodule {freeformType = attrsOf anything;};
description = "Options to pass to the setup function";
default = {};
};
# lz.n options
enabled = mkOption {
type = nullOr (either bool str);
description = "When false, or if the lua function returns false, this plugin will not be included in the spec";
default = null;
};
beforeAll = mkOption {
type = nullOr str;
description = "Lua code to run before any plugins are loaded. This will be wrapped in a function.";
default = null;
};
before = mkOption {
type = nullOr str;
description = "Lua code to run before plugin is loaded. This will be wrapped in a function.";
default = null;
};
after = mkOption {
type = nullOr str;
description = "Lua code to run after plugin is loaded. This will be wrapped in a function.";
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
nullOr (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 (oneOf [str (listOf lznKeysSpec) (listOf str)]);
example = ''
keys = [
{lhs = "<leader>s"; rhs = ":NvimTreeToggle<cr>"; desc = "Toggle NvimTree"}
]
'';
};
colorscheme = mkOption {
description = "Lazy-load on colorscheme.";
type = nullOr (either str (listOf str));
default = null;
};
priority = mkOption {
type = nullOr int;
description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first.";
default = null;
};
load = mkOption {
type = nullOr str;
default = null;
description = ''
Lua code to override the `vim.g.lz_n.load()` function for a single plugin.
This will be wrapped in a function
'';
};
};
};
in { in {
inherit extraPluginType fromInputs pluginType luaInline lznPluginType lznPluginTableType; inherit extraPluginType fromInputs pluginType;
pluginsOpt = { pluginsOpt = {
description, description,
@ -248,6 +64,11 @@ in {
type = pluginsType; type = pluginsType;
}; };
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};
/* /*
opts is a attrset of options, example: opts is a attrset of options, example:
``` ```

View file

@ -21,8 +21,8 @@ in {
}; };
vim.lazy = { vim.lazy = {
plugins = { plugins = [
nvim-tree-lua = { {
package = "nvim-tree-lua"; package = "nvim-tree-lua";
setupModule = "nvim-tree"; setupModule = "nvim-tree";
inherit (cfg) setupOpts; inherit (cfg) setupOpts;
@ -34,8 +34,8 @@ in {
(mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description) (mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
(mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description) (mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
]; ];
}; }
}; ];
}; };
vim.pluginRC.nvimtreelua = entryAnywhere '' vim.pluginRC.nvimtreelua = entryAnywhere ''

View file

@ -3,7 +3,7 @@
config, config,
... ...
}: let }: let
inherit (builtins) toJSON typeOf head length; inherit (builtins) toJSON typeOf head length tryEval;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.attrsets) mapAttrsToList; inherit (lib.attrsets) mapAttrsToList;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
@ -31,7 +31,14 @@
inherit desc noremap expr nowait ft mode; inherit desc noremap expr nowait ft mode;
}; };
toLuaLznSpec = name: spec: toLuaLznSpec = spec: let
name =
if typeOf spec.package == "string"
then spec.package
else if (spec.package ? pname && (tryEval spec.package.pname).success)
then spec.package.pname
else spec.package.name;
in
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"]) (removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
// { // {
"@1" = name; "@1" = name;
@ -64,12 +71,12 @@
then map toLuzLznKeySpec spec.keys then map toLuzLznKeySpec spec.keys
else spec.keys; else spec.keys;
}; };
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; lznSpecs = map toLuaLznSpec cfg.plugins;
in { in {
config.vim = mkIf cfg.enable { config.vim = mkIf cfg.enable {
startPlugins = ["lz-n" "lzn-auto-require"]; startPlugins = ["lz-n" "lzn-auto-require"];
optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins; optPlugins = map (plugin: plugin.package) cfg.plugins;
luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] '' luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] ''
require('lz.n').load(${toLuaObject lznSpecs}) require('lz.n').load(${toLuaObject lznSpecs})

View file

@ -1,7 +1,186 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) enum; inherit (lib.types) enum listOf submodule nullOr str bool int attrsOf anything either oneOf;
inherit (lib.nvim.types) lznPluginTableType; inherit (lib.nvim.types) pluginType;
lznKeysSpec = submodule {
options = {
desc = mkOption {
description = "Description of the key map";
type = nullOr str;
default = null;
};
noremap = mkOption {
description = "TBD";
type = bool;
default = false;
};
expr = mkOption {
description = "TBD";
type = bool;
default = false;
};
nowait = mkOption {
description = "TBD";
type = bool;
default = false;
};
ft = mkOption {
description = "TBD";
type = nullOr (listOf str);
default = null;
};
key = mkOption {
type = str;
description = "Key to bind to";
};
action = mkOption {
type = nullOr str;
default = null;
description = "Action to trigger.";
};
lua = mkOption {
type = bool;
default = false;
description = "If true the action is treated as a lua function instead of a vim command.";
};
mode = mkOption {
description = "Modes to bind in";
type = listOf str;
default = ["n" "x" "s" "o"];
};
};
};
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;
# }
# Non-lz.n options
package = mkOption {
type = pluginType;
description = "Plugin package";
};
setupModule = mkOption {
type = nullOr str;
description = "Lua module to run setup function on.";
default = null;
};
setupOpts = mkOption {
type = submodule {freeformType = attrsOf anything;};
description = "Options to pass to the setup function";
default = {};
};
# lz.n options
enabled = mkOption {
type = nullOr (either bool str);
description = "When false, or if the lua function returns false, this plugin will not be included in the spec";
default = null;
};
beforeAll = mkOption {
type = nullOr str;
description = "Lua code to run before any plugins are loaded. This will be wrapped in a function.";
default = null;
};
before = mkOption {
type = nullOr str;
description = "Lua code to run before plugin is loaded. This will be wrapped in a function.";
default = null;
};
after = mkOption {
type = nullOr str;
description = "Lua code to run after plugin is loaded. This will be wrapped in a function.";
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
nullOr (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 (oneOf [str (listOf lznKeysSpec) (listOf str)]);
example = ''
keys = [
{lhs = "<leader>s"; rhs = ":NvimTreeToggle<cr>"; desc = "Toggle NvimTree"}
]
'';
};
colorscheme = mkOption {
description = "Lazy-load on colorscheme.";
type = nullOr (either str (listOf str));
default = null;
};
priority = mkOption {
type = nullOr int;
description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first.";
default = null;
};
load = mkOption {
type = nullOr str;
default = null;
description = ''
Lua code to override the `vim.g.lz_n.load()` function for a single plugin.
This will be wrapped in a function
'';
};
};
};
in { in {
options.vim.lazy = { options.vim.lazy = {
enable = mkEnableOption "plugin lazy-loading" // {default = true;}; enable = mkEnableOption "plugin lazy-loading" // {default = true;};
@ -12,17 +191,17 @@ in {
}; };
plugins = mkOption { plugins = mkOption {
default = {}; default = [];
type = lznPluginTableType; type = listOf lznPluginType;
description = "list of plugins to lazy load"; description = "list of plugins to lazy load";
example = '' example = ''
{ [
toggleterm-nvim = { {
package = "toggleterm-nvim"; package = "toggleterm-nvim";
after = lib.generators.mkLuaInline "function() require('toggleterm').setup{} end"; after = lib.generators.mkLuaInline "function() require('toggleterm').setup{} end";
cmd = ["ToggleTerm"]; cmd = ["ToggleTerm"];
}; }
} ]
''; '';
}; };
}; };