Feature Request: Dedup items
When several sources return the same items, cmp will display duplicate entries. Is there a way of deduping the suggestions list?
Minimal config based on this
if has('vim_starting')
set encoding=utf-8
endif
scriptencoding utf-8
if &compatible
set nocompatible
endif
let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/autoload/plug.vim')
execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end
execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
call plug#end()
PlugInstall | quit
" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
local buffer = require "cmp_buffer"
cmp.register_source('extra', buffer.new())
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<CR>'] = cmp.mapping.confirm({ select = true })
},
sources = {
{ name = "buffer" },
{ name = "extra" },
{ name = "buffer" },
{ name = "extra" },
},
}
EOF
To Reproduce
- nvim init.vim -u init.vim
- Start typing
bufanywhere - You get
cmp-buffersuggested several times.
Expected behavior
cmp-buffer will be suggested only once.
Why was the buffer source specified twice? (Is it just example?)
Yes, to illustrate the issue
{
{ name = 'buffer', NEW_KEY_NAME = true or false }
}
What the name do you think better?
I probably did not wxplain myself... The problem is when two different sources have the same suggestion.
The use of cmp-buffer twice here is just to illustrate.
On Fri, 12 Nov 2021, 14:20 hrsh7th, @.***> wrote:
{ { name = 'buffer', NEW_KEY_NAME = true or false } }
What the name do you think better?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hrsh7th/nvim-cmp/issues/511#issuecomment-967070225, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFXXC4XHZGPULQXUYXOA7LULUBCRANCNFSM5H2NE7IQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Or so you propose to filter all items from the same KEY together?
On Fri, 12 Nov 2021, 14:34 Nir Tzachar, @.***> wrote:
I probably did not wxplain myself... The problem is when two different sources have the same suggestion.
The use of cmp-buffer twice here is just to illustrate.
On Fri, 12 Nov 2021, 14:20 hrsh7th, @.***> wrote:
{ { name = 'buffer', NEW_KEY_NAME = true or false } }
What the name do you think better?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hrsh7th/nvim-cmp/issues/511#issuecomment-967070225, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFXXC4XHZGPULQXUYXOA7LULUBCRANCNFSM5H2NE7IQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I think the issue is solved when I set dup = 0 in my source.
Is there a better solution?
I'm planning to remove CompletionItem.dup field and introduce the SourceConfig.allow_duplicates = false for source configuration.
But it requires the source default configuration API...
Anyway, you can use dup field for the time being.
Cool, I already am.
What's the status on this now? I'm getting the same entries from nvim_lsp and buffer using clangd. Setting dup in sources doesn't seem to do anything, and I can't find anything in the docs regarding "dup".

@Seblerr i've had the same difficulties with duplicates in my Vsnip items.
This might help

the vim_item.dup part is the one that interesets you.
I got it from this bug : https://github.com/hrsh7th/nvim-cmp/issues/32
Keep an eye out for this issue...
@Seblerr i've had the same difficulties with duplicates in my Vsnip items. This might help
the vim_item.dup part is the one that interesets you.
I got it from this bug : #32
Hello there, any update on this situation? I had to use this config to deduplicate entries between LSP and Luasnip sources.
--- Edit: I say nothing. it was a null-ls issue with a source.
btw, @hrsh7th and is it possible to somehow set up, for example, unloading "old" copies of duplicated sources?
For example, when I doing PackerSync, it reloads plugins, including sources, and after every sync (keeping same nvim session), I'm getting additional copy of each source, so it goes to look like like this:

@msva this! Just wanted to open an issue for this. I have the exact same isssue. I do PackerSync during my "Reload" function where I reload my config without quitting neovim. When I'm editing my config I do this very frequently obviously and then I get like 10+ duplicates of every entry which makes cmp quite unusable at that point. (If I'm not editing my vimconfig nvim-cmp is awesome of course :-))
I think nvim-cmp can remove duplicated sources....
also having this same issue .
I also have this issue with sorting between lsp and buffer. #1044
How dedup from two different source
{
name = "nvim_lsp",
max_item_count = 7,
},
{
name = "buffer",
option = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end,
},
},
vim_item.dup = ({
buffer = 0,
path = 0,
nvim_lsp = 0,
luasnip = 0,
})[entry.source.name] or 0