feat(LSP): lspkind and sources

This commit is contained in:
NotAShelf 2023-04-18 01:48:44 +03:00
commit 104c21c904
No known key found for this signature in database
GPG key ID: F0D14CCB5ED5AA22
11 changed files with 143 additions and 50 deletions

View file

@ -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") ''