plugins/lspkind: refactoring + tests (#259)

This commit is contained in:
Gaétan Lepage 2023-03-15 12:06:11 +01:00 committed by GitHub
parent 86f4067159
commit e33e62ff61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 45 deletions

View file

@ -8,61 +8,45 @@ with lib; let
cfg = config.plugins.lspkind; cfg = config.plugins.lspkind;
helpers = import ../helpers.nix {inherit lib;}; helpers = import ../helpers.nix {inherit lib;};
in { in {
options.plugins.lspkind = { options.plugins.lspkind =
enable = mkEnableOption "lspkind.nvim"; helpers.extraOptionsOptions
// {
enable = mkEnableOption "lspkind.nvim";
package = helpers.mkPackageOption "lspkind" pkgs.vimPlugins.lspkind-nvim; package = helpers.mkPackageOption "lspkind" pkgs.vimPlugins.lspkind-nvim;
mode = mkOption { mode =
type = with types; nullOr (enum ["text" "text_symbol" "symbol_text" "symbol"]); helpers.defaultNullOpts.mkEnum
default = null; ["text" "text_symbol" "symbol_text" "symbol"]
description = "Defines how annotations are shown"; "symbol_text"
}; "Defines how annotations are shown";
preset = mkOption { preset = helpers.defaultNullOpts.mkEnum ["default" "codicons"] "codicons" "Default symbol map";
type = with types; nullOr (enum ["default" "codicons"]);
default = null;
description = "Default symbol map";
};
symbolMap = mkOption { symbolMap = helpers.mkNullOrOption (types.attrsOf types.str) "Override preset symbols";
type = with types; nullOr (attrsOf str);
default = null;
description = "Override preset symbols";
};
cmp = { cmp = {
enable = mkOption { enable = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
description = "Integrate with nvim-cmp"; description = "Integrate with nvim-cmp";
}; };
maxWidth = mkOption { maxWidth =
type = with types; nullOr int; helpers.mkNullOrOption types.int
default = null; "Maximum number of characters to show in the popup";
description = "Maximum number of characters to show in the popup";
};
ellipsisChar = mkOption { ellipsisChar =
type = with types; nullOr str; helpers.mkNullOrOption types.str
default = null; "Character to show when the popup exceeds maxwidth";
description = "Character to show when the popup exceeds maxwidth";
};
menu = mkOption { menu = helpers.mkNullOrOption (types.attrsOf types.str) "Show source names in the popup";
type = with types; nullOr (attrsOf str);
default = null;
description = "Show source names in the popup";
};
after = mkOption { after =
type = with types; nullOr types.str; helpers.mkNullOrOption types.str
default = null; "Function to run after calculating the formatting. function(entry, vim_item, kind)";
description = "Function to run after calculating the formatting. function(entry, vim_item, kind)";
}; };
}; };
};
config = let config = let
doCmp = cfg.cmp.enable && config.plugins.nvim-cmp.enable; doCmp = cfg.cmp.enable && config.plugins.nvim-cmp.enable;
@ -80,7 +64,8 @@ in {
menu = cfg.cmp.menu; menu = cfg.cmp.menu;
} }
else {} else {}
); )
// cfg.extraOptions;
in in
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];

23
tests/plugins/lspkind.nix Normal file
View file

@ -0,0 +1,23 @@
{
# Empty configuration
empty = {
plugins.lspkind.enable = true;
};
# All the upstream default options of lspkind
defaults = {
plugins.lspkind = {
enable = true;
mode = "symbol_text";
preset = "codicons";
symbolMap = null;
cmp = {
enable = true;
maxWidth = 50;
ellipsisChar = "...";
menu = null;
after = null;
};
};
};
}