2022-11-10 18:22:45 +00:00
|
|
|
{
|
2023-02-20 11:42:13 +01:00
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.plugins.lspkind;
|
|
|
|
helpers = import ../helpers.nix {inherit lib;};
|
|
|
|
in {
|
2023-03-15 12:06:11 +01:00
|
|
|
options.plugins.lspkind =
|
|
|
|
helpers.extraOptionsOptions
|
|
|
|
// {
|
|
|
|
enable = mkEnableOption "lspkind.nvim";
|
2023-01-19 10:45:15 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
package = helpers.mkPackageOption "lspkind" pkgs.vimPlugins.lspkind-nvim;
|
2023-01-19 10:45:15 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
mode =
|
|
|
|
helpers.defaultNullOpts.mkEnum
|
|
|
|
["text" "text_symbol" "symbol_text" "symbol"]
|
|
|
|
"symbol_text"
|
|
|
|
"Defines how annotations are shown";
|
2022-11-10 18:22:45 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
preset = helpers.defaultNullOpts.mkEnum ["default" "codicons"] "codicons" "Default symbol map";
|
2022-11-10 18:22:45 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
symbolMap = helpers.mkNullOrOption (types.attrsOf types.str) "Override preset symbols";
|
2022-11-10 18:22:45 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
cmp = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Integrate with nvim-cmp";
|
|
|
|
};
|
2022-11-10 18:22:45 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
maxWidth =
|
|
|
|
helpers.mkNullOrOption types.int
|
|
|
|
"Maximum number of characters to show in the popup";
|
2022-11-10 18:22:45 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
ellipsisChar =
|
|
|
|
helpers.mkNullOrOption types.str
|
|
|
|
"Character to show when the popup exceeds maxwidth";
|
2022-11-10 18:35:52 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
menu = helpers.mkNullOrOption (types.attrsOf types.str) "Show source names in the popup";
|
2022-11-10 18:53:16 +00:00
|
|
|
|
2023-03-15 12:06:11 +01:00
|
|
|
after =
|
|
|
|
helpers.mkNullOrOption types.str
|
|
|
|
"Function to run after calculating the formatting. function(entry, vim_item, kind)";
|
2022-11-10 18:53:16 +00:00
|
|
|
};
|
2022-11-10 18:22:45 +00:00
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
|
|
|
doCmp = cfg.cmp.enable && config.plugins.nvim-cmp.enable;
|
|
|
|
options =
|
|
|
|
{
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg) mode preset;
|
2022-11-10 18:22:45 +00:00
|
|
|
symbol_map = cfg.symbolMap;
|
2023-02-20 11:42:13 +01:00
|
|
|
}
|
|
|
|
// (
|
|
|
|
if doCmp
|
|
|
|
then {
|
|
|
|
maxwidth = cfg.cmp.maxWidth;
|
|
|
|
ellipsis_char = cfg.cmp.ellipsisChar;
|
2023-05-22 15:45:47 +05:30
|
|
|
inherit (cfg.cmp) menu;
|
2023-02-20 11:42:13 +01:00
|
|
|
}
|
|
|
|
else {}
|
2023-03-15 12:06:11 +01:00
|
|
|
)
|
|
|
|
// cfg.extraOptions;
|
2023-02-20 11:42:13 +01:00
|
|
|
in
|
2022-11-10 18:22:45 +00:00
|
|
|
mkIf cfg.enable {
|
2023-02-20 11:42:13 +01:00
|
|
|
extraPlugins = [cfg.package];
|
2022-11-10 18:22:45 +00:00
|
|
|
|
|
|
|
extraConfigLua = optionalString (!doCmp) ''
|
|
|
|
require('lspkind').init(${helpers.toLuaObject options})
|
|
|
|
'';
|
|
|
|
|
2022-11-10 18:53:16 +00:00
|
|
|
plugins.nvim-cmp.formatting.format =
|
2023-02-20 11:42:13 +01:00
|
|
|
if cfg.cmp.after != null
|
|
|
|
then ''
|
2022-11-10 18:53:16 +00:00
|
|
|
function(entry, vim_item)
|
|
|
|
local kind = require('lspkind').cmp_format(${helpers.toLuaObject options})(entry, vim_item)
|
|
|
|
|
2022-11-10 19:05:44 +00:00
|
|
|
return (${cfg.cmp.after})(entry, vim_after, kind)
|
2022-11-10 18:53:16 +00:00
|
|
|
end
|
2023-02-20 11:42:13 +01:00
|
|
|
''
|
|
|
|
else ''
|
2022-11-10 18:53:16 +00:00
|
|
|
require('lspkind').cmp_format(${helpers.toLuaObject options})
|
|
|
|
'';
|
2022-11-10 18:22:45 +00:00
|
|
|
};
|
|
|
|
}
|