Skip to content

Commit 3cfde15

Browse files
committed
lib/neovim-plugin: support lz-n lazy config
1 parent da30527 commit 3cfde15

File tree

3 files changed

+147
-15
lines changed

3 files changed

+147
-15
lines changed

lib/neovim-plugin.nix

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@
116116

117117
lazyLoad = lib.nixvim.mkLazyLoadOption {
118118
inherit originalName;
119-
lazyLoadDefaults = (
120-
lib.optionalAttrs (isColorscheme && colorscheme != null) { inherit colorscheme; }
121-
);
119+
lazyLoadDefaults = lib.optionalAttrs (isColorscheme && colorscheme != null) {
120+
inherit colorscheme;
121+
};
122122
};
123123
}
124124
// lib.optionalAttrs hasSettings {
@@ -171,6 +171,34 @@
171171
# Write the lua configuration `luaConfig.content` to the config file
172172
(lib.mkIf (!cfg.lazyLoad.enable) (setLuaConfig cfg.luaConfig.content))
173173
])
174+
++ (lib.optionals hasConfigAttrs [
175+
(lib.mkIf (cfg.lazyLoad.backend == "lz.n") {
176+
plugins.lz-n = {
177+
# infinite recursion?
178+
# enable = true;
179+
plugins = [
180+
{
181+
# TODO: handle this for every plugin properly
182+
__unkeyed-1 = originalName;
183+
# Use provided after, otherwise fallback to normal lua content
184+
after = if cfg.lazyLoad.after != null then cfg.lazyLoad.after else cfg.luaConfig.content;
185+
inherit (cfg.lazyLoad)
186+
enabled
187+
priority
188+
before
189+
beforeAll
190+
event
191+
cmd
192+
ft
193+
keys
194+
colorscheme
195+
extraSettings
196+
;
197+
}
198+
];
199+
};
200+
})
201+
])
174202
)
175203
);
176204
};

lib/options.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ rec {
360360
lazy-loading for ${originalName}
361361
'';
362362

363+
backend =
364+
mkEnumFirstDefault
365+
[
366+
"lz.n"
367+
]
368+
''
369+
The lazy-loading backend to use.
370+
'';
371+
363372
# Spec loading:
364373
enabled = mkStrLuaFnOr types.bool (lazyLoadDefaults.enabledInSpec or null) ''
365374
When false, or if the function returns false, then ${originalName} will not be included in the spec.
Lines changed: 107 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,129 @@
11
{
2-
lazy-load-plugin =
2+
lazy-load-neovim-plugin =
33
{ config, ... }:
44
{
55
plugins = {
6+
lz-n = {
7+
enable = true;
8+
};
9+
10+
neotest = {
11+
enable = true;
12+
lazyLoad = {
13+
enable = true;
14+
keys = [
15+
{
16+
__unkeyed-1 = "<leader>nt";
17+
__unkeyed-3 = "<CMD>Neotest summary<CR>";
18+
desc = "Summary toggle";
19+
}
20+
];
21+
};
22+
};
23+
};
24+
25+
assertions = [
26+
{
27+
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
28+
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
29+
}
30+
{
31+
assertion =
32+
let
33+
plugin = builtins.head config.plugins.lz-n.plugins;
34+
keys = if builtins.isList plugin.keys then plugin.keys else [ ];
35+
in
36+
(builtins.length keys) == 1;
37+
message = "`lz-n.plugins[0].keys` should have contained a configuration.";
38+
}
39+
];
40+
};
41+
42+
lazy-load-lz-n =
43+
{ config, ... }:
44+
{
45+
plugins = {
46+
codesnap = {
47+
enable = true;
48+
lazyLoad.enable = true;
49+
};
650
lz-n = {
751
enable = true;
852
plugins = [
953
{
10-
__unkeyed-1 = "neotest";
54+
__unkeyed-1 = "codesnap";
1155
after.__raw = ''
1256
function()
13-
${config.plugins.neotest.luaConfig.content}
57+
${config.plugins.codesnap.luaConfig.content}
1458
end
1559
'';
60+
cmd = [
61+
"CodeSnap"
62+
"CodeSnapSave"
63+
"CodeSnapHighlight"
64+
"CodeSnapSaveHighlight"
65+
];
1666
keys = [
1767
{
18-
__unkeyed-1 = "<leader>nt";
19-
__unkeyed-3 = "<CMD>Neotest summary<CR>";
20-
desc = "Summary toggle";
68+
__unkeyed-1 = "<leader>cc";
69+
__unkeyed-3 = "<cmd>CodeSnap<CR>";
70+
desc = "Copy";
71+
mode = "v";
72+
}
73+
{
74+
__unkeyed-1 = "<leader>cs";
75+
__unkeyed-3 = "<cmd>CodeSnapSave<CR>";
76+
desc = "Save";
77+
mode = "v";
78+
}
79+
{
80+
__unkeyed-1 = "<leader>ch";
81+
__unkeyed-3 = "<cmd>CodeSnapHighlight<CR>";
82+
desc = "Highlight";
83+
mode = "v";
84+
}
85+
{
86+
__unkeyed-1 = "<leader>cH";
87+
__unkeyed-3 = "<cmd>CodeSnapSaveHighlight<CR>";
88+
desc = "Save Highlight";
89+
mode = "v";
2190
}
2291
];
23-
2492
}
2593
];
2694
};
27-
28-
neotest = {
29-
enable = true;
30-
lazyLoad.enable = true;
31-
};
3295
};
96+
assertions = [
97+
{
98+
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
99+
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
100+
}
101+
{
102+
assertion =
103+
let
104+
plugin = builtins.head config.plugins.lz-n.plugins;
105+
keys = if builtins.isList plugin.keys then plugin.keys else [ ];
106+
in
107+
(builtins.length keys) == 4;
108+
message =
109+
let
110+
plugin = builtins.head config.plugins.lz-n.plugins;
111+
in
112+
"`lz-n.plugins[0].keys` should have contained 4 key configurations, but contained ${builtins.toJSON (plugin.keys)}";
113+
}
114+
{
115+
assertion =
116+
let
117+
plugin = builtins.head config.plugins.lz-n.plugins;
118+
cmd = if builtins.isList plugin.cmd then plugin.cmd else [ ];
119+
in
120+
(builtins.length cmd) == 4;
121+
message =
122+
let
123+
plugin = builtins.head config.plugins.lz-n.plugins;
124+
in
125+
"`lz-n.plugins[0].cmd` should have contained 4 cmd configurations, but contained ${builtins.toJSON (plugin.cmd)}";
126+
}
127+
];
33128
};
34129
}

0 commit comments

Comments
 (0)