Skip to content

Commit 6cf9520

Browse files
committed
lib/neovim-plugin: support lazy loading luaConfig.content
1 parent cf7e026 commit 6cf9520

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/neovim-plugin.nix

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@
113113
'';
114114
internal = true;
115115
};
116+
117+
lazyLoad = lib.mkOption {
118+
default = {
119+
enable = false;
120+
};
121+
description = ''
122+
Lazy load configuration settings.
123+
'';
124+
type = lib.types.submodule {
125+
options = {
126+
enable = lib.mkOption {
127+
default = false;
128+
type = lib.types.bool;
129+
description = ''
130+
Whether to lazy load the plugin.
131+
132+
If you enable this, the plugin's lua configuration will need to be manually loaded by other means.
133+
134+
A usage would be passing the plugin's luaConfig to the `plugins.lz-n.plugins` configuration.
135+
'';
136+
};
137+
};
138+
};
139+
};
116140
}
117141
// lib.optionalAttrs hasSettings {
118142
settings = lib.nixvim.mkSettingsOption {
@@ -162,7 +186,7 @@
162186
(lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; })
163187

164188
# Write the lua configuration `luaConfig.content` to the config file
165-
(setLuaConfig cfg.luaConfig.content)
189+
(lib.mkIf (!cfg.lazyLoad.enable) (setLuaConfig cfg.luaConfig.content))
166190
])
167191
)
168192
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
lazy-load-plugin =
3+
{ config, ... }:
4+
{
5+
plugins = {
6+
lz-n = {
7+
enable = true;
8+
plugins = [
9+
{
10+
__unkeyed-1 = "neotest";
11+
after.__raw = ''
12+
function()
13+
${config.plugins.neotest.luaConfig.content}
14+
end
15+
'';
16+
keys = [
17+
{
18+
__unkeyed-1 = "<leader>nt";
19+
__unkeyed-3 = "<CMD>Neotest summary<CR>";
20+
desc = "Summary toggle";
21+
}
22+
];
23+
24+
}
25+
];
26+
};
27+
28+
neotest = {
29+
enable = true;
30+
lazyLoad.enable = true;
31+
};
32+
};
33+
};
34+
}

0 commit comments

Comments
 (0)