Skip to content

Commit

Permalink
lib/neovim-plugin: support lazy loading luaConfig.content
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Dec 2, 2024
1 parent e680b36 commit 6f73273
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/neovim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@
'';
internal = true;
};

lazyLoad = lib.mkOption {
default = {
enable = false;
};
description = ''
Lazy load configuration settings.
'';
type = lib.types.submodule {
options = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to lazy load the plugin.
If you enable this, the plugin's lua configuration will need to be manually loaded by other means.
A usage would be passing the plugin's luaConfig to the `plugins.lz-n.plugins` configuration.
'';
};
};
};
};
}
// lib.optionalAttrs hasSettings {
settings = lib.nixvim.mkSettingsOption {
Expand Down Expand Up @@ -157,7 +181,9 @@
])
++ (lib.optionals hasConfigAttrs [
(lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; })
(lib.optionalAttrs (configLocation != null) (setLuaConfig cfg.luaConfig.content))
(lib.mkIf (!cfg.lazyLoad.enable) (
lib.optionalAttrs (configLocation != null) (setLuaConfig cfg.luaConfig.content)
))
])
)
);
Expand Down
34 changes: 34 additions & 0 deletions tests/test-sources/plugins/lazy-load.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
lazy-load-plugin =
{ config, ... }:
{
plugins = {
lz-n = {
enable = true;
plugins = [
{
__unkeyed-1 = "neotest";
after.__raw = ''
function()
${config.plugins.neotest.luaConfig.content}
end
'';
keys = [
{
__unkeyed-1 = "<leader>nt";
__unkeyed-3 = "<CMD>Neotest summary<CR>";
desc = "Summary toggle";
}
];

}
];
};

neotest = {
enable = true;
lazyLoad.enable = true;
};
};
};
}

0 comments on commit 6f73273

Please sign in to comment.