Skip to content

Commit efd52d4

Browse files
committed
plugins/lz-n: make sub-options type anything
1 parent 6ac95b4 commit efd52d4

File tree

2 files changed

+146
-98
lines changed

2 files changed

+146
-98
lines changed

plugins/pluginmanagers/lz-n.nix

Lines changed: 131 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,6 @@
77
...
88
}:
99
with lib;
10-
let
11-
lzPluginType =
12-
with helpers.nixvimTypes;
13-
let
14-
maybeRawStrOrList = oneOf [
15-
str
16-
(listOf (maybeRaw str))
17-
rawLua
18-
];
19-
in
20-
submodule {
21-
freeformType = attrsOf anything;
22-
options = {
23-
__unkeyed = mkOption {
24-
type = str;
25-
description = ''
26-
The "unkeyed" attribute is the plugin's name.
27-
This is passed to `load` function and should normally match the repo name of the plugin.
28-
29-
More specifically, this is the name of the folder in `/pack/opt/{name}` that is loaded with `load` (`packadd` by default).
30-
See `:h packadd`.
31-
'';
32-
};
33-
enabled = helpers.defaultNullOpts.mkStrLuaFnOr bool true ''
34-
When false, or if the function returns false, then this plugin will not be included in the spec.
35-
This option corresponds to the `enabled` property of lz.n.
36-
'';
37-
beforeAll = helpers.mkNullOrLuaFn "Always executed before any plugins are loaded.";
38-
before = helpers.mkNullOrLuaFn "Executed before this plugin is loaded.";
39-
after = helpers.mkNullOrLuaFn "Executed after this plugin is loaded.";
40-
event = helpers.mkNullOrOption maybeRawStrOrList "Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua";
41-
cmd = helpers.mkNullOrOption maybeRawStrOrList "Lazy-load on command.";
42-
ft = helpers.mkNullOrOption maybeRawStrOrList "Lazy-load on filetype.";
43-
colorscheme = helpers.mkNullOrOption maybeRawStrOrList "Lazy-load on colorscheme.";
44-
keys = helpers.mkNullOrOption' {
45-
type = maybeRawStrOrList;
46-
description = "Lazy-load on key mapping. Mode is `n` by default.";
47-
example = [
48-
"<C-a>"
49-
(helpers.mkRaw ''{ "<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle" }'')
50-
];
51-
};
52-
priority = helpers.defaultNullOpts.mkUnsignedInt (lib.literalMD "`50` (or `1000` if `colorscheme` is set)") ''
53-
Only useful for start plugins (not lazy-loaded) to force loading certain plugins first.
54-
'';
55-
load = helpers.mkNullOrLuaFn "Can be used to override the `vim.g.lz_n.load()` function for this plugin.";
56-
};
57-
};
58-
in
5910
helpers.neovim-plugin.mkNeovimPlugin config {
6011
name = "lz-n";
6112
originalName = "lz.n";
@@ -76,50 +27,139 @@ helpers.neovim-plugin.mkNeovimPlugin config {
7627

7728
callSetup = false; # Does not use setup
7829

79-
extraOptions = {
80-
plugins = mkOption {
81-
description = ''
82-
List of plugin specs provided to the `require('lz.n').load` function.
83-
Plugin specs can be ${helpers.nixvimTypes.rawLua.description}.
84-
'';
85-
default = [ ];
86-
type = types.listOf lzPluginType;
87-
example = [
88-
{
89-
__unkeyed = "neo-tree.nvim";
90-
enabled = ''
91-
function()
92-
return true
93-
end
94-
'';
95-
keys = helpers.mkRaw ''{ "<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle" }'';
96-
after = ''
97-
function()
98-
require("neo-tree").setup()
99-
end
100-
'';
101-
}
102-
{
103-
__unkeyed = "telescope.nvim";
104-
cmd = [ "Telescope" ];
105-
keys = [
106-
(helpers.mkRaw ''{ "<leader>fa", "<CMD>Telescope autocommands<CR>", desc = "Telescope autocommands" }'')
107-
(helpers.mkRaw ''{ "<leader>fb", "<CMD>Telescope buffers<CR>", desc = "Telescope buffers" }'')
108-
];
109-
}
110-
{
111-
__unkeyed = "onedarker.nvim";
112-
colorscheme = [ "onedarker" ];
113-
}
114-
(helpers.mkRaw ''
30+
extraOptions =
31+
let
32+
lzPluginType =
33+
with helpers.nixvimTypes;
34+
submodule {
35+
freeformType = attrsOf anything;
36+
options = {
37+
__unkeyed = mkOption {
38+
type = str;
39+
description = ''
40+
The "unkeyed" attribute is the plugin's name.
41+
This is passed to `load` function and should normally match the repo name of the plugin.
42+
43+
More specifically, this is the name of the folder in `/pack/opt/{name}` that is loaded with `load` (`packadd` by default).
44+
See `:h packadd`.
45+
'';
46+
};
47+
enabled = helpers.defaultNullOpts.mkStrLuaFnOr bool true ''
48+
When false, or if the function returns false, then this plugin will not be included in the spec.
49+
This option corresponds to the `enabled` property of lz.n.
50+
'';
51+
beforeAll = helpers.mkNullOrLuaFn "Always executed before any plugins are loaded.";
52+
before = helpers.mkNullOrLuaFn "Executed before this plugin is loaded.";
53+
after = helpers.mkNullOrLuaFn "Executed after this plugin is loaded.";
54+
load = helpers.mkNullOrLuaFn "Can be used to override the `vim.g.lz_n.load()` function for this plugin.";
55+
56+
priority = helpers.defaultNullOpts.mkUnsignedInt (lib.literalMD "`50` (or `1000` if `colorscheme` is set)") ''
57+
Only useful for start plugins (not lazy-loaded) to force loading certain plugins first.
58+
'';
59+
event = helpers.mkNullOrOption' {
60+
type = anything;
61+
description = "Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua";
62+
example = [
63+
"BufEnter *.lua"
64+
"DeferredUIEnter"
65+
];
66+
};
67+
cmd = helpers.mkNullOrOption' {
68+
type = anything;
69+
description = "Lazy-load on command.";
70+
example = [
71+
"Neotree"
72+
"Telescope"
73+
];
74+
};
75+
ft = helpers.mkNullOrOption' {
76+
type = anything;
77+
description = "Lazy-load on filetype.";
78+
example = [ "tex" ];
79+
};
80+
colorscheme = helpers.mkNullOrOption' {
81+
type = anything;
82+
description = "Lazy-load on colorscheme.";
83+
example = "onedarker";
84+
};
85+
keys = helpers.mkNullOrOption' {
86+
type = listOf anything;
87+
description = "Lazy-load on key mapping. Mode is `n` by default.";
88+
example = [
89+
"<C-a>"
90+
[
91+
"<C-x>"
92+
"g<C-x>"
93+
]
94+
{
95+
__unkeyed-1 = "<leader>fb";
96+
__unkeyed-2 = "<CMD>Telescope buffers<CR>";
97+
desc = "Telescope buffers";
98+
}
99+
(helpers.mkRaw ''{ "<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle" }'')
100+
];
101+
};
102+
};
103+
};
104+
in
105+
{
106+
plugins = mkOption {
107+
description = ''
108+
List of plugin specs provided to the `require('lz.n').load` function.
109+
Plugin specs can be ${helpers.nixvimTypes.rawLua.description}.
110+
'';
111+
default = [ ];
112+
type = types.listOf lzPluginType;
113+
example = [
115114
{
116-
"crates.nvim",
117-
ft = "toml",
118-
},
119-
'')
120-
];
115+
__unkeyed = "neo-tree.nvim";
116+
enabled = ''
117+
function()
118+
return true
119+
end
120+
'';
121+
keys = [
122+
{
123+
__unkeyed-1 = "<leader>ft";
124+
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
125+
desc = "NeoTree toggle";
126+
}
127+
];
128+
after = ''
129+
function()
130+
require("neo-tree").setup()
131+
end
132+
'';
133+
}
134+
{
135+
__unkeyed = "telescope.nvim";
136+
cmd = [ "Telescope" ];
137+
keys = [
138+
{
139+
__unkeyed-1 = "<leader>fa";
140+
__unkeyed-2 = "<CMD>Telescope autocommands<CR>";
141+
desc = "Telescope autocommands";
142+
}
143+
{
144+
__unkeyed-1 = "<leader>fb";
145+
__unkeyed-2 = "<CMD>Telescope buffers<CR>";
146+
desc = "Telescope buffers";
147+
}
148+
];
149+
}
150+
{
151+
__unkeyed = "onedarker.nvim";
152+
colorscheme = [ "onedarker" ];
153+
}
154+
(helpers.mkRaw ''
155+
{
156+
"crates.nvim",
157+
ft = "toml",
158+
},
159+
'')
160+
];
161+
};
121162
};
122-
};
123163

124164
extraConfig = cfg: {
125165
globals.lz_n = modules.mkAliasAndWrapDefsWithPriority id options.plugins.lz-n.settings;

tests/test-sources/plugins/pluginmanagers/lz-n.nix

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ in
4343
return true
4444
end
4545
'';
46-
keys = helpers.mkRaw ''
47-
{{"<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle"}}
48-
'';
46+
keys = [
47+
{
48+
__unkeyed-1 = "<leader>ft";
49+
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
50+
desc = "NeoTree toggle";
51+
}
52+
];
4953
after = # lua
5054
''
5155
function()
@@ -74,17 +78,21 @@ in
7478
plugins.lz-n = {
7579
enable = true;
7680
plugins = [
77-
# enabled, on keys as rawLua
81+
# enabled, on keys
7882
{
7983
__unkeyed = "neo-tree.nvim";
8084
enabled = ''
8185
function()
8286
return true
8387
end
8488
'';
85-
keys = helpers.mkRaw ''
86-
{{"<leader>ft", "<CMD>Neotree toggle<CR>", desc = "NeoTree toggle"}}
87-
'';
89+
keys = [
90+
{
91+
__unkeyed-1 = "<leader>ft";
92+
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
93+
desc = "NeoTree toggle";
94+
}
95+
];
8896
after = # lua
8997
''
9098
function()

0 commit comments

Comments
 (0)