lazy: use listOf plugins instead of attr

This commit is contained in:
Pei Yang Ching 2024-08-24 14:28:14 +02:00
parent cb99286189
commit 299639065c
4 changed files with 32 additions and 16 deletions

View file

@ -8,6 +8,15 @@ isMaximal: {
logFile = "/tmp/nvim.log";
};
lazy = {
plugins = [
{
package = "vim-repeat";
keys = ".";
}
];
};
spellcheck = {
enable = isMaximal;
};

View file

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

View file

@ -3,7 +3,7 @@
config,
...
}: let
inherit (builtins) toJSON typeOf head length;
inherit (builtins) toJSON typeOf head length tryEval;
inherit (lib.modules) mkIf;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.generators) mkLuaInline;
@ -31,7 +31,14 @@
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"])
// {
"@1" = name;
@ -64,12 +71,12 @@
then map toLuzLznKeySpec spec.keys
else spec.keys;
};
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
lznSpecs = map toLuaLznSpec cfg.plugins;
in {
config.vim = mkIf cfg.enable {
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"] ''
require('lz.n').load(${toLuaObject lznSpecs})

View file

@ -1,7 +1,7 @@
{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) enum;
inherit (lib.nvim.types) lznPluginTableType;
inherit (lib.types) enum listOf;
inherit (lib.nvim.types) lznPluginType;
in {
options.vim.lazy = {
enable = mkEnableOption "plugin lazy-loading" // {default = true;};
@ -12,17 +12,17 @@ in {
};
plugins = mkOption {
default = {};
type = lznPluginTableType;
default = [];
type = listOf lznPluginType;
description = "list of plugins to lazy load";
example = ''
{
toggleterm-nvim = {
[
{
package = "toggleterm-nvim";
after = lib.generators.mkLuaInline "function() require('toggleterm').setup{} end";
cmd = ["ToggleTerm"];
};
}
}
]
'';
};
};