diff --git a/plugins/by-name/lspkind/default.nix b/plugins/by-name/lspkind/default.nix index dba668f1..c05cf392 100644 --- a/plugins/by-name/lspkind/default.nix +++ b/plugins/by-name/lspkind/default.nix @@ -2,93 +2,64 @@ lib, helpers, config, - pkgs, ... }: -with lib; let - cfg = config.plugins.lspkind; + inherit (lib) types; in -{ - options.plugins.lspkind = lib.nixvim.plugins.neovim.extraOptionsOptions // { - enable = mkEnableOption "lspkind.nvim"; +lib.nixvim.plugins.mkNeovimPlugin { + name = "lspkind"; + packPathName = "lspkind.nvim"; + package = "lspkind-nvim"; + maintainers = [ lib.maintainers.saygo-png ]; + description = "VS Code-like pictograms for Neovim LSP completion items."; - package = lib.mkPackageOption pkgs "lspkind" { - default = [ - "vimPlugins" - "lspkind-nvim" - ]; - }; + # The plugin does not call setup when integrating with cmp, so it has to be conditional. + callSetup = false; - mode = helpers.defaultNullOpts.mkEnum [ - "text" - "text_symbol" - "symbol_text" - "symbol" - ] "symbol_text" "Defines how annotations are shown"; - - preset = helpers.defaultNullOpts.mkEnum [ - "default" - "codicons" - ] "codicons" "Default symbol map"; - - symbolMap = helpers.mkNullOrOption (types.attrsOf types.str) "Override preset symbols"; + # TODO: introduced 2025-07-16: remove after 25.11 + inherit (import ./deprecations.nix lib) deprecateExtraOptions optionsRenamedToSettings; + extraOptions = { cmp = { - enable = mkOption { + enable = lib.mkOption { type = types.bool; default = true; description = "Integrate with nvim-cmp"; }; - maxWidth = helpers.mkNullOrOption types.int "Maximum number of characters to show in the popup"; - - ellipsisChar = helpers.mkNullOrOption types.str "Character to show when the popup exceeds maxwidth"; - - menu = helpers.mkNullOrOption (types.attrsOf types.str) "Show source names in the popup"; - after = helpers.mkNullOrOption types.str "Function to run after calculating the formatting. function(entry, vim_item, kind)"; }; }; - config = - let - doCmp = cfg.cmp.enable && config.plugins.cmp.enable; - options = { - inherit (cfg) mode preset; - symbol_map = cfg.symbolMap; - } - // ( - if doCmp then - { - maxwidth = cfg.cmp.maxWidth; - ellipsis_char = cfg.cmp.ellipsisChar; - inherit (cfg.cmp) menu; - } - else - { } - ) - // cfg.extraOptions; - in - mkIf cfg.enable { - extraPlugins = [ cfg.package ]; - - extraConfigLua = optionalString (!doCmp) '' - require('lspkind').init(${lib.nixvim.toLuaObject options}) + extraConfig = cfg: { + assertions = lib.nixvim.mkAssertions "plugins.lspkind" { + assertion = cfg.cmp.enable -> config.plugins.cmp.enable; + message = '' + Cmp integration (cmp.enable) is enabled but the cmp plugin is not. ''; - - plugins.cmp.settings.formatting.format = - if cfg.cmp.after != null then - '' - function(entry, vim_item) - local kind = require('lspkind').cmp_format(${lib.nixvim.toLuaObject options})(entry, vim_item) - - return (${cfg.cmp.after})(entry, vim_item, kind) - end - '' - else - '' - require('lspkind').cmp_format(${lib.nixvim.toLuaObject options}) - ''; }; + + plugins.lspkind.luaConfig.content = lib.optionalString (!cfg.cmp.enable) '' + require('lspkind').init(${lib.nixvim.toLuaObject cfg.settings}) + ''; + + plugins.cmp.settings.formatting.format = + let + format' = + if cfg.cmp.after != null then + '' + function(entry, vim_item) + local kind = require('lspkind').cmp_format(${lib.nixvim.toLuaObject cfg.settings})(entry, vim_item) + + return (${cfg.cmp.after})(entry, vim_item, kind) + end + '' + else + '' + require('lspkind').cmp_format(${lib.nixvim.toLuaObject cfg.settings}) + ''; + in + lib.optionalString cfg.cmp.enable format'; + }; } diff --git a/plugins/by-name/lspkind/deprecations.nix b/plugins/by-name/lspkind/deprecations.nix new file mode 100644 index 00000000..d7a4eac4 --- /dev/null +++ b/plugins/by-name/lspkind/deprecations.nix @@ -0,0 +1,17 @@ +lib: { + deprecateExtraOptions = true; + optionsRenamedToSettings = + let + mkOptionPaths = map (lib.splitString "."); + in + mkOptionPaths [ + "mode" + "preset" + "maxWidth" + "symbolMap" + + "cmp.maxWidth" + "cmp.ellipsisChar" + "cmp.menu" + ]; +} diff --git a/tests/test-sources/plugins/by-name/lspkind/default.nix b/tests/test-sources/plugins/by-name/lspkind/default.nix index 3626b0d4..8f6c28a1 100644 --- a/tests/test-sources/plugins/by-name/lspkind/default.nix +++ b/tests/test-sources/plugins/by-name/lspkind/default.nix @@ -1,6 +1,9 @@ { empty = { - plugins.lspkind.enable = true; + plugins.lspkind = { + enable = true; + cmp.enable = false; + }; }; example = { @@ -17,14 +20,13 @@ defaults = { plugins.lspkind = { enable = true; - mode = "symbol_text"; - preset = "codicons"; - symbolMap = null; + settings = { + mode = "symbol_text"; + preset = "codicons"; + symbol_map = null; + }; cmp = { - enable = true; - maxWidth = 50; - ellipsisChar = "..."; - menu = null; + enable = false; after = null; }; };