Skip to content

Commit 0049aca

Browse files
saygo-pngMattSturgeon
authored andcommitted
plugins/lspkind: migrate to mkNeovimPlugin
Signed-off-by: saygo-png <[email protected]>
1 parent 346ebc9 commit 0049aca

File tree

2 files changed

+55
-70
lines changed

2 files changed

+55
-70
lines changed

plugins/by-name/lspkind/default.nix

Lines changed: 38 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,61 @@
22
lib,
33
helpers,
44
config,
5-
pkgs,
65
...
76
}:
8-
with lib;
97
let
10-
cfg = config.plugins.lspkind;
8+
inherit (lib) types;
119
in
12-
{
13-
options.plugins.lspkind = lib.nixvim.plugins.neovim.extraOptionsOptions // {
14-
enable = mkEnableOption "lspkind.nvim";
15-
16-
package = lib.mkPackageOption pkgs "lspkind" {
17-
default = [
18-
"vimPlugins"
19-
"lspkind-nvim"
20-
];
21-
};
10+
lib.nixvim.plugins.mkNeovimPlugin {
11+
name = "lspkind";
12+
packPathName = "lspkind.nvim";
13+
package = "lspkind-nvim";
14+
maintainers = [ lib.maintainers.saygo-png ];
15+
description = "VS Code-like pictograms for Neovim LSP completion items.";
2216

23-
mode = helpers.defaultNullOpts.mkEnum [
24-
"text"
25-
"text_symbol"
26-
"symbol_text"
27-
"symbol"
28-
] "symbol_text" "Defines how annotations are shown";
17+
# The plugin does not call setup when integrating with cmp, so it has to be conditional.
18+
callSetup = false;
2919

30-
preset = helpers.defaultNullOpts.mkEnum [
31-
"default"
32-
"codicons"
33-
] "codicons" "Default symbol map";
34-
35-
symbolMap = helpers.mkNullOrOption (types.attrsOf types.str) "Override preset symbols";
20+
# TODO: introduced 2025-07-16: remove after 25.11
21+
inherit (import ./deprecations.nix lib) deprecateExtraOptions optionsRenamedToSettings;
3622

23+
extraOptions = {
3724
cmp = {
38-
enable = mkOption {
25+
enable = lib.mkOption {
3926
type = types.bool;
4027
default = true;
4128
description = "Integrate with nvim-cmp";
4229
};
4330

44-
maxWidth = helpers.mkNullOrOption types.int "Maximum number of characters to show in the popup";
45-
46-
ellipsisChar = helpers.mkNullOrOption types.str "Character to show when the popup exceeds maxwidth";
47-
48-
menu = helpers.mkNullOrOption (types.attrsOf types.str) "Show source names in the popup";
49-
5031
after = helpers.mkNullOrOption types.str "Function to run after calculating the formatting. function(entry, vim_item, kind)";
5132
};
5233
};
5334

54-
config =
55-
let
56-
doCmp = cfg.cmp.enable && config.plugins.cmp.enable;
57-
options = {
58-
inherit (cfg) mode preset;
59-
symbol_map = cfg.symbolMap;
60-
}
61-
// (
62-
if doCmp then
63-
{
64-
maxwidth = cfg.cmp.maxWidth;
65-
ellipsis_char = cfg.cmp.ellipsisChar;
66-
inherit (cfg.cmp) menu;
67-
}
68-
else
69-
{ }
70-
)
71-
// cfg.extraOptions;
72-
in
73-
mkIf cfg.enable {
74-
extraPlugins = [ cfg.package ];
75-
76-
extraConfigLua = optionalString (!doCmp) ''
77-
require('lspkind').init(${lib.nixvim.toLuaObject options})
35+
extraConfig = cfg: {
36+
assertions = lib.nixvim.mkAssertions "plugins.lspkind" {
37+
assertion = cfg.cmp.enable -> config.plugins.cmp.enable;
38+
message = ''
39+
Cmp integration (cmp.enable) is enabled but the cmp plugin is not.
7840
'';
79-
80-
plugins.cmp.settings.formatting.format =
81-
if cfg.cmp.after != null then
82-
''
83-
function(entry, vim_item)
84-
local kind = require('lspkind').cmp_format(${lib.nixvim.toLuaObject options})(entry, vim_item)
85-
86-
return (${cfg.cmp.after})(entry, vim_item, kind)
87-
end
88-
''
89-
else
90-
''
91-
require('lspkind').cmp_format(${lib.nixvim.toLuaObject options})
92-
'';
9341
};
42+
43+
plugins.lspkind.luaConfig.content = lib.mkIf (!cfg.cmp.enable) ''
44+
require('lspkind').init(${lib.nixvim.toLuaObject cfg.settings})
45+
'';
46+
47+
plugins.cmp.settings.formatting.format = lib.mkIf cfg.cmp.enable (
48+
if cfg.cmp.after != null then
49+
''
50+
function(entry, vim_item)
51+
local kind = require('lspkind').cmp_format(${lib.nixvim.toLuaObject cfg.settings})(entry, vim_item)
52+
53+
return (${cfg.cmp.after})(entry, vim_item, kind)
54+
end
55+
''
56+
else
57+
''
58+
require('lspkind').cmp_format(${lib.nixvim.toLuaObject cfg.settings})
59+
''
60+
);
61+
};
9462
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
lib: {
2+
deprecateExtraOptions = true;
3+
optionsRenamedToSettings =
4+
let
5+
mkOptionPaths = map (lib.splitString ".");
6+
in
7+
mkOptionPaths [
8+
"mode"
9+
"preset"
10+
"maxWidth"
11+
"symbolMap"
12+
13+
"cmp.maxWidth"
14+
"cmp.ellipsisChar"
15+
"cmp.menu"
16+
];
17+
}

0 commit comments

Comments
 (0)