Skip to content

Commit 1b3bda7

Browse files
committed
plugins/zk: switch to mkNeovimPlugin
1 parent 38e3849 commit 1b3bda7

File tree

2 files changed

+117
-46
lines changed

2 files changed

+117
-46
lines changed

plugins/utils/zk.nix

Lines changed: 103 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,128 @@
66
...
77
}:
88
with lib;
9-
{
10-
options.plugins.zk = {
11-
enable = mkEnableOption "zk.nvim, a plugin to integrate with zk";
9+
helpers.neovim-plugin.mkNeovimPlugin config {
10+
name = "zk";
11+
originalName = "zk.nvim";
12+
defaultPackage = pkgs.vimPlugins.zk-nvim;
13+
14+
maintainers = [ maintainers.GaetanLepage ];
1215

13-
package = helpers.mkPluginPackageOption "zk.nvim" pkgs.vimPlugins.zk-nvim;
16+
# TODO: introduced 2024-06-28. Remove after 24.11 release.
17+
optionsRenamedToSettings = [
18+
"picker"
19+
[
20+
"lsp"
21+
"config"
22+
]
23+
[
24+
"lsp"
25+
"autoAttach"
26+
"enabled"
27+
]
28+
[
29+
"lsp"
30+
"autoAttach"
31+
"filetypes"
32+
]
33+
];
1434

35+
settingsOptions = {
1536
picker =
1637
helpers.defaultNullOpts.mkEnumFirstDefault
1738
[
1839
"select"
1940
"fzf"
41+
"fzf_lua"
42+
"minipick"
2043
"telescope"
2144
]
2245
''
23-
it's recommended to use "telescope" or "fzf"
46+
It is recommended to use `"telescope"`, `"fzf"`, `"fzf_lua"`, or `"minipick"`.
2447
'';
2548

2649
lsp = {
27-
config = helpers.neovim-plugin.extraOptionsOptions // {
28-
cmd = helpers.defaultNullOpts.mkListOf types.str [
50+
config =
51+
helpers.defaultNullOpts.mkNullable
52+
(types.submodule {
53+
freeformType = with types; attrsOf anything;
54+
options = {
55+
cmd = helpers.defaultNullOpts.mkListOf types.str [
56+
"zk"
57+
"lsp"
58+
] "Command to start the language server.";
59+
60+
name = helpers.defaultNullOpts.mkStr "zk" ''
61+
The name for this server.
62+
'';
63+
64+
on_attach = helpers.mkNullOrLuaFn ''
65+
Command to run when the client is attached.
66+
'';
67+
};
68+
})
69+
{
70+
cmd = [
71+
"zk"
72+
"lsp"
73+
];
74+
name = "zk";
75+
}
76+
''
77+
LSP configuration. See `:h vim.lsp.start_client()`.
78+
'';
79+
80+
auto_attach = {
81+
enabled = helpers.defaultNullOpts.mkBool true ''
82+
Automatically attach buffers in a zk notebook.
83+
'';
84+
85+
filetypes = helpers.defaultNullOpts.mkListOf types.str [ "markdown" ] ''
86+
Filetypes for which zk should automatically attach.
87+
'';
88+
};
89+
};
90+
};
91+
92+
settingsExample = {
93+
picker = "telescope";
94+
lsp = {
95+
config = {
96+
cmd = [
2997
"zk"
3098
"lsp"
31-
] "";
32-
name = helpers.defaultNullOpts.mkStr "zk" "";
99+
];
100+
name = "zk";
33101
};
34-
35-
autoAttach = {
36-
enabled = helpers.defaultNullOpts.mkBool true "automatically attach buffers in a zk notebook";
37-
filetypes = helpers.defaultNullOpts.mkListOf types.str [
38-
"markdown"
39-
] "matching the given filetypes";
102+
auto_attach = {
103+
enabled = true;
104+
filetypes = [ "markdown" ];
40105
};
41106
};
107+
42108
};
43-
config =
44-
let
45-
cfg = config.plugins.zk;
46-
setupOptions = {
47-
inherit (cfg) picker;
48-
lsp = {
49-
inherit (cfg.lsp) config;
50-
auto_attach = {
51-
inherit (cfg.lsp.autoAttach) enabled filetypes;
52-
};
53-
};
54-
};
55-
in
56-
mkIf cfg.enable {
57-
extraPlugins = [ cfg.package ];
58-
extraPackages = [ pkgs.zk ];
59109

60-
extraConfigLua = ''
61-
require("zk").setup(${helpers.toLuaObject setupOptions})
62-
'';
110+
extraOptions = {
111+
zkPackage = helpers.mkPackageOption {
112+
name = "zk";
113+
default = pkgs.zk;
63114
};
115+
};
116+
extraConfig = cfg: {
117+
extraPackages = [ cfg.zkPackage ];
118+
119+
warnings = flatten (
120+
mapAttrsToList
121+
(
122+
picker: pluginName:
123+
optional ((cfg.settings.picker == picker) && !config.plugins.${pluginName}.enable) ''
124+
Nixvim (plugins.zk): You have set `plugins.zk.settings.picker = "${picker}"` but `plugins.${pluginName}` is not enabled in your config.
125+
''
126+
)
127+
{
128+
fzf_lua = "fzf-lua";
129+
telescope = "telescope";
130+
}
131+
);
132+
};
64133
}

tests/test-sources/plugins/utils/zk.nix

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
defaults = {
77
plugins.zk = {
88
enable = true;
9-
picker = "select";
10-
lsp = {
11-
config = {
12-
cmd = [
13-
"zk"
14-
"lsp"
15-
];
16-
name = "zk";
17-
};
189

19-
autoAttach = {
20-
enabled = true;
21-
filetypes = [ "markdown" ];
10+
settings = {
11+
picker = "select";
12+
lsp = {
13+
config = {
14+
cmd = [
15+
"zk"
16+
"lsp"
17+
];
18+
name = "zk";
19+
};
20+
auto_attach = {
21+
enabled = true;
22+
filetypes = [ "markdown" ];
23+
};
2224
};
2325
};
2426
};

0 commit comments

Comments
 (0)