Closed vxpm closed 8 months ago
Has just ran into the same issue but in my case it is a bit more cursed and drastically effect UX.
Config:
local cmp = require("cmp")
local luasnip = require("luasnip")
local lspkind = require("lspkind")
require("luasnip/loaders/from_vscode").lazy_load()
local cmp_select = { behavior = cmp.SelectBehavior.Select }
vim.opt.completeopt = "menu,menuone,noselect"
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(cmp_select),
["<C-j>"] = cmp.mapping.select_next_item(cmp_select),
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = false }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" }, -- lsp
{ name = "luasnip" }, -- snippets
{ name = "buffer" }, -- text within current buffer
{ name = "path" }, -- file system paths
}),
formatting = {
format = lspkind.cmp_format({
mode = "symbol",
maxwidth = 50,
ellipsis_char = "...",
}),
},
window = {
completion = {
border = "rounded",
},
documentation = { border = "rounded" },
},
})
Found a solution that has nothing to do with lspkind. I combined lspkind with solution suggested in https://github.com/hrsh7th/nvim-cmp/discussions/609#discussioncomment-5727678. Also removed "menu" field from nvim-cmp config. In the end my config looks like this:
local cmp = require("cmp")
local luasnip = require("luasnip")
local lspkind = require("lspkind")
require("luasnip/loaders/from_vscode").lazy_load()
local cmp_select = { behavior = cmp.SelectBehavior.Select }
vim.opt.completeopt = "menu,menuone,noselect"
local format_fn = function(entry, item)
item.menu = ""
local fixed_width = 40
local content = item.abbr
if fixed_width then
vim.o.pumwidth = fixed_width
end
local win_width = vim.api.nvim_win_get_width(0)
local max_content_width = fixed_width and fixed_width - 10 or math.floor(win_width * 0.2)
if #content > max_content_width then
item.abbr = vim.fn.strcharpart(content, 0, max_content_width - 3) .. "..."
else
item.abbr = content .. (" "):rep(max_content_width - #content)
end
return item
end
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(cmp_select),
["<C-j>"] = cmp.mapping.select_next_item(cmp_select),
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" }, -- lsp
{ name = "luasnip" }, -- snippets
{ name = "buffer" }, -- text within current buffer
{ name = "path" }, -- file system paths
}),
formatting = {
fields = { "abbr", "kind" },
format = lspkind.cmp_format({
maxwidth = 40,
ellipsis_char = "...",
before = format_fn,
}),
},
window = {
completion = {
border = "rounded",
},
documentation = { border = "rounded" },
},
})
Result: Although, documentation may seem too large it does not cause any problem cause it adjusts it size.
i don't think this is a real solution, however. removing menu
just hides the problem. @onsails are you sure this can be marked as completed?
Hi, @vxpm can you talk more about why this is not solved?
The labelDetails
become optional. You could turn it on with show_labelDetails = true
.
Hi, @vxpm can you talk more about why this is not solved?
The
labelDetails
become optional. You could turn it on withshow_labelDetails = true
.
oh!! sorry, it is indeed solved. it completely flew over my head that #75 exists and that's why the issue was closed - i only saw stepanchous reply. oops.
thank you for solving it!
although #72 makes sense, it would be nice to be able to opt into the old behaviour.
at 57610d5ab560c073c465d6faf0c19f200cb67e6e (before the merge):
at d11d58c3fc3edbd8c0112b5850ef4ed553d98752 (after the merge):