|
2 | 2 | lib,
|
3 | 3 | helpers,
|
4 | 4 | config,
|
5 |
| - pkgs, |
6 | 5 | ...
|
7 | 6 | }:
|
8 |
| -with lib; |
9 | 7 | let
|
10 |
| - cfg = config.plugins.lspkind; |
| 8 | + inherit (lib) types; |
11 | 9 | 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."; |
22 | 16 |
|
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; |
29 | 19 |
|
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; |
36 | 22 |
|
| 23 | + extraOptions = { |
37 | 24 | cmp = {
|
38 |
| - enable = mkOption { |
| 25 | + enable = lib.mkOption { |
39 | 26 | type = types.bool;
|
40 | 27 | default = true;
|
41 | 28 | description = "Integrate with nvim-cmp";
|
42 | 29 | };
|
43 | 30 |
|
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 |
| - |
50 | 31 | after = helpers.mkNullOrOption types.str "Function to run after calculating the formatting. function(entry, vim_item, kind)";
|
51 | 32 | };
|
52 | 33 | };
|
53 | 34 |
|
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. |
78 | 40 | '';
|
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 |
| - ''; |
93 | 41 | };
|
| 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 | + }; |
94 | 62 | }
|
0 commit comments