plugins/lspkind: migrate to mkNeovimPlugin

Signed-off-by: saygo-png <saygo.mail@proton.me>
This commit is contained in:
saygo-png 2025-07-16 16:35:16 +02:00
parent 3d09c8eace
commit 2b0037a6ea
No known key found for this signature in database
GPG key ID: 86B6FCCC3563C00B
2 changed files with 58 additions and 70 deletions

View file

@ -2,93 +2,64 @@
lib, lib,
helpers, helpers,
config, config,
pkgs,
... ...
}: }:
with lib;
let let
cfg = config.plugins.lspkind; inherit (lib) types;
in in
{ lib.nixvim.plugins.mkNeovimPlugin {
options.plugins.lspkind = lib.nixvim.plugins.neovim.extraOptionsOptions // { name = "lspkind";
enable = mkEnableOption "lspkind.nvim"; 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" { # The plugin does not call setup when integrating with cmp, so it has to be conditional.
default = [ callSetup = false;
"vimPlugins"
"lspkind-nvim"
];
};
mode = helpers.defaultNullOpts.mkEnum [ # TODO: introduced 2025-07-16: remove after 25.11
"text" inherit (import ./deprecations.nix lib) deprecateExtraOptions optionsRenamedToSettings;
"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";
extraOptions = {
cmp = { cmp = {
enable = mkOption { enable = lib.mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
description = "Integrate with nvim-cmp"; 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)"; after = helpers.mkNullOrOption types.str "Function to run after calculating the formatting. function(entry, vim_item, kind)";
}; };
}; };
config = extraConfig = cfg: {
let assertions = lib.nixvim.mkAssertions "plugins.lspkind" {
doCmp = cfg.cmp.enable && config.plugins.cmp.enable; assertion = cfg.cmp.enable -> config.plugins.cmp.enable;
options = { message = ''
inherit (cfg) mode preset; Cmp integration (cmp.enable) is enabled but the cmp plugin is not.
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) '' plugins.lspkind.luaConfig.content = lib.optionalString (!cfg.cmp.enable) ''
require('lspkind').init(${lib.nixvim.toLuaObject options}) require('lspkind').init(${lib.nixvim.toLuaObject cfg.settings})
''; '';
plugins.cmp.settings.formatting.format = plugins.cmp.settings.formatting.format =
let
format' =
if cfg.cmp.after != null then if cfg.cmp.after != null then
'' ''
function(entry, vim_item) function(entry, vim_item)
local kind = require('lspkind').cmp_format(${lib.nixvim.toLuaObject options})(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) return (${cfg.cmp.after})(entry, vim_item, kind)
end end
'' ''
else else
'' ''
require('lspkind').cmp_format(${lib.nixvim.toLuaObject options}) require('lspkind').cmp_format(${lib.nixvim.toLuaObject cfg.settings})
''; '';
in
lib.optionalString cfg.cmp.enable format';
}; };
} }

View file

@ -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"
];
}