2022-11-10 18:22:45 +00:00
|
|
|
{
|
2023-11-06 15:04:08 +01:00
|
|
|
lib,
|
|
|
|
helpers,
|
2023-02-20 11:42:13 +01:00
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.plugins.lspkind;
|
|
|
|
in
|
|
|
|
{
|
2024-01-25 16:15:55 +01:00
|
|
|
options.plugins.lspkind = helpers.neovim-plugin.extraOptionsOptions // {
|
2023-03-15 12:06:11 +01:00
|
|
|
enable = mkEnableOption "lspkind.nvim";
|
2023-01-19 10:45:15 +00:00
|
|
|
|
2024-05-17 14:09:20 +02:00
|
|
|
package = helpers.mkPluginPackageOption "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:22:45 +00:00
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2022-11-10 18:22:45 +00:00
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config =
|
|
|
|
let
|
2024-02-03 23:22:06 +01:00
|
|
|
doCmp = cfg.cmp.enable && config.plugins.cmp.enable;
|
2023-02-20 11:42:13 +01:00
|
|
|
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
|
|
|
}
|
2024-05-05 19:39:35 +02:00
|
|
|
// (
|
|
|
|
if doCmp then
|
2023-02-20 11:42:13 +01:00
|
|
|
{
|
|
|
|
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
|
2024-05-05 19:39:35 +02:00
|
|
|
{ }
|
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})
|
|
|
|
'';
|
|
|
|
|
2024-02-03 23:22:06 +01:00
|
|
|
plugins.cmp.settings.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)
|
|
|
|
|
2024-04-27 18:25:53 -04:00
|
|
|
return (${cfg.cmp.after})(entry, vim_item, 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
|
|
|
};
|
|
|
|
}
|