fix(cmp): formatting using lspkind

This commit is contained in:
Simon Lasbrugnas 2024-11-11 04:11:20 +01:00
parent 9935cf346f
commit 2c087db1a7
Signed by untrusted user who does not match committer: simon
GPG key ID: 86039876BA6ED8DE

View file

@ -1,9 +1,9 @@
local cmp = require("cmp")
local defaults = require("cmp.config.default")()
local lspkind = require "lspkind"
require("custom.snippets")
cmp.setup({
preselect = cmp.PreselectMode.None,
completion = {
completeopt = "menu,menuone,noinsert",
},
@ -13,6 +13,13 @@ cmp.setup({
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.abort(),
['<C-g>'] = function()
if cmp.visible_docs() then
cmp.close_docs()
else
cmp.open_docs()
end
end,
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
@ -25,28 +32,30 @@ cmp.setup({
end,
},
sources = cmp.config.sources({
{ name = "luasnip", priority = 100 },
{ name = "nvim_lsp" },
{ name = "path" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "buffer", group_index = 10 },
{ name = "lazydev", group_index = 0, }
}),
sorting = defaults.sorting,
formatting = {
expandable_indicator = true,
fields = { "kind", "abbr", "menu" },
format = lspkind.cmp_format({
mode = 'text_symbol', -- show only symbol annotations
maxwidth = {
-- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
-- can also be a function to dynamically calculate max width such as
-- menu = function() return math.floor(0.45 * vim.o.columns) end,
menu = 50, -- leading text (labelDetails)
abbr = 50, -- actual suggestion item
},
ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
show_labelDetails = true, -- show labelDetails in menu. Disabled by default
-- The function below will be called before any actual modifications from lspkind
-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
before = function(_, vim_item)
mode = 'symbol_text',
maxwidth = 50,
ellipsis_char = '...',
show_labelDetails = true,
before = function(entry, vim_item)
vim_item.menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
luasnip = "[Snippet]",
path = "[Path]",
lazydev = "[Lazy]",
})[entry.source.name]
return vim_item
end
})
}
})