lazy: add setupOpts support

This commit is contained in:
Pei Yang Ching 2024-07-24 12:52:47 +02:00
parent fab27790ea
commit 06f11946fd
2 changed files with 34 additions and 3 deletions

View file

@ -65,10 +65,27 @@
# type= str; # type= str;
# } # }
# Non-lz.n options
package = mkOption { package = mkOption {
type = pluginType; 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
before = mkOption { before = mkOption {
type = nullOr luaInline; type = nullOr luaInline;
description = "Code to run before plugin is loaded"; description = "Code to run before plugin is loaded";

View file

@ -3,15 +3,29 @@
config, config,
... ...
}: let }: let
inherit (builtins) toJSON;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.attrsets) mapAttrsToList; inherit (lib.attrsets) mapAttrsToList;
inherit (lib.generators) mkLuaInline;
inherit (lib.strings) optionalString;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.lazy; cfg = config.vim.lazy;
toLuaLznSpec = name: plugin: toLuaLznSpec = name: spec:
(removeAttrs plugin ["package"]) (removeAttrs spec ["package" "setupModule" "setupOpts"])
// {"@1" = name;}; // {
"@1" = name;
after = mkLuaInline ''
function()
${
optionalString (spec.setupModule != null)
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"
}
${optionalString (spec.after != null) spec.after}
end
'';
};
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
in { in {
config.vim = mkIf cfg.enable { config.vim = mkIf cfg.enable {