mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 02:11:33 +00:00
feat(LSP): lspkind and sources
This commit is contained in:
parent
2df414b577
commit
104c21c904
11 changed files with 143 additions and 50 deletions
|
@ -7,8 +7,27 @@
|
|||
with lib;
|
||||
with builtins; let
|
||||
cfg = config.vim.autocomplete;
|
||||
lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
|
||||
builtSources =
|
||||
concatMapStringsSep "\n" (x: "{ name = '${x}'},") cfg.sources;
|
||||
concatMapStringsSep
|
||||
"\n"
|
||||
(n: "{ name = '${n}'},")
|
||||
(attrNames cfg.sources);
|
||||
|
||||
builtMaps =
|
||||
concatStringsSep
|
||||
"\n"
|
||||
(mapAttrsToList
|
||||
(n: v:
|
||||
if v == null
|
||||
then ""
|
||||
else "${n} = '${v}',")
|
||||
cfg.sources);
|
||||
|
||||
dagPlacement =
|
||||
if lspkindEnabled
|
||||
then nvim.dag.entryAfter ["lspkind"]
|
||||
else nvim.dag.entryAnywhere;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
|
@ -18,14 +37,28 @@ in {
|
|||
"cmp-path"
|
||||
];
|
||||
|
||||
vim.autocomplete.sources = [
|
||||
"nvim-cmp"
|
||||
"vsnip"
|
||||
"buffer"
|
||||
"path"
|
||||
];
|
||||
vim.autocomplete.sources = {
|
||||
"nvim-cmp" = null;
|
||||
"vsnip" = "[VSnip]";
|
||||
"buffer" = "[Buffer]";
|
||||
"crates" = "[Crates]";
|
||||
"path" = "[Path]";
|
||||
};
|
||||
|
||||
vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
|
||||
local nvim_cmp_menu_map = function(entry, vim_item)
|
||||
-- name for each source
|
||||
vim_item.menu = ({
|
||||
${builtMaps}
|
||||
})[entry.source.name]
|
||||
print(vim_item.menu)
|
||||
return vim_item
|
||||
end
|
||||
|
||||
${optionalString lspkindEnabled ''
|
||||
lspkind_opts.before = ${cfg.formatting.format}
|
||||
''}
|
||||
|
||||
vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (nvim.dag.entryAnywhere ''
|
||||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
|
@ -80,23 +113,12 @@ in {
|
|||
completeopt = 'menu,menuone,noinsert',
|
||||
},
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
-- type of kind
|
||||
vim_item.kind = ${
|
||||
optionalString (config.vim.visuals.lspkind.enable)
|
||||
"require('lspkind').presets.default[vim_item.kind] .. ' ' .."
|
||||
} vim_item.kind
|
||||
|
||||
-- name for each source
|
||||
vim_item.menu = ({
|
||||
buffer = "[Buffer]",
|
||||
nvim_lsp = "[LSP]",
|
||||
vsnip = "[VSnip]",
|
||||
crates = "[Crates]",
|
||||
path = "[Path]",
|
||||
})[entry.source.name]
|
||||
return vim_item
|
||||
end,
|
||||
format =
|
||||
${
|
||||
if lspkindEnabled
|
||||
then "lspkind.cmp_format(lspkind_opts)"
|
||||
else cfg.formatting.format
|
||||
},
|
||||
}
|
||||
})
|
||||
${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") ''
|
||||
|
|
|
@ -5,11 +5,7 @@
|
|||
...
|
||||
}:
|
||||
with lib;
|
||||
with builtins; let
|
||||
cfg = config.vim.autocomplete;
|
||||
builtSources =
|
||||
concatMapStringsSep "\n" (x: "{ name = '${x}'},") cfg.sources;
|
||||
in {
|
||||
with builtins; {
|
||||
options.vim = {
|
||||
autocomplete = {
|
||||
enable = mkOption {
|
||||
|
@ -25,9 +21,40 @@ in {
|
|||
};
|
||||
|
||||
sources = mkOption {
|
||||
description = "List of source names for nvim-cmp";
|
||||
type = with types; listOf str;
|
||||
default = [];
|
||||
description = nvim.nmd.asciiDoc ''
|
||||
Attribute set of source names for nvim-cmp.
|
||||
|
||||
If an attribute set is provided, then the menu value of
|
||||
`vim_item` in the format will be set to the value (if
|
||||
utilizing the `nvim_cmp_menu_map` function).
|
||||
|
||||
Note: only use a single attribute name per attribute set
|
||||
'';
|
||||
type = with types; attrsOf (nullOr str);
|
||||
default = {};
|
||||
example = ''
|
||||
{nvim-cmp = null; buffer = "[Buffer]";}
|
||||
'';
|
||||
};
|
||||
|
||||
formatting = {
|
||||
format = mkOption {
|
||||
description = nvim.nmd.asciiDoc ''
|
||||
The function used to customize the appearance of the completion menu.
|
||||
|
||||
If <<opt-vim.lsp.lspkind.enable>> is true, then the function
|
||||
will be called before modifications from lspkind.
|
||||
|
||||
Default is to call the menu mapping function.
|
||||
'';
|
||||
type = types.str;
|
||||
default = "nvim_cmp_menu_map";
|
||||
example = ''
|
||||
function(entry, vim_item)
|
||||
return vim_item
|
||||
end
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue