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