[英]Nvim-cmp is adding multiple times the same sources
I'm using nvim-cmp
to have a contextual window to display my LSP suggestions and my snippets but when I open multiple buffers, I have an issue: the same source is added multiple times to nvim-cmp
causing the same result to be repeated in the popup.我正在使用nvim-cmp
有一个上下文 window 来显示我的 LSP 建议和我的片段但是当我打开多个缓冲区时,我遇到了一个问题:相同的源被多次添加到nvim-cmp
导致重复相同的结果在弹出窗口中。
For example, here is the result of :CmpStatus
: after a few minutes of work.例如,这是:CmpStatus
的结果:经过几分钟的工作。
# ready source names
- vsnip
- buffer
- nvim_lsp:pylsp
- vsnip
- nvim_lsp:pylsp
- nvim_lsp:pylsp
Here is my nvim-cmp
config:这是我的nvim-cmp
配置:
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
...
sources = {
{ name = 'vsnip' },
{ name = 'nvim_lua' },
{ name = 'nvim_lsp' },
{ name = 'buffer', keyword_length = 3 }
},
}
Does anyone know how to adress this issue?有谁知道如何解决这个问题? Is it a problem with my configuration?是我的配置有问题吗?
In your cmp configuration, you can use the dup
keyword for vim_item
with the formatting
option / format
function.在您的 cmp 配置中,您可以将vim_item
的dup
关键字与formatting
选项 / format
function 一起使用。 See help for complete-item
for explanations ( :help complete-item
).有关解释,请参阅complete-item
的帮助 ( :help complete-item
)。
cmp.setup({
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '[LSP]',
vsnip = '[Snippet]',
nvim_lua = '[Nvim Lua]',
buffer = '[Buffer]',
})[entry.source.name]
vim_item.dup = ({
vsnip = 0,
nvim_lsp = 0,
nvim_lua = 0,
buffer = 0,
})[entry.source.name] or 0
return vim_item
end
}
})
You can see details in this feature request for nvim-cmp
plugin.您可以在nvim-cmp
插件的此功能请求中查看详细信息。
I had the same problem and managed to solve the issue by realizing that cmp is somehow installed twice.我遇到了同样的问题,并通过意识到 cmp 以某种方式安装了两次而设法解决了这个问题。
Try removing or better first renaming the cmp-packages in the plugged directory, for example尝试删除或更好地首先重命名插入目录中的 cmp-packages,例如
cmp-nvim-lsp
to cmp-nvim-lsp_not
cmp-nvim-lsp
到cmp-nvim-lsp_not
cml-nvim-buffer
to cmp-nvim-buffer_not
etc. cml-nvim-buffer
到cmp-nvim-buffer_not
等。
This did the job for me.这为我完成了工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.