2

I'm using nvim-cmpto 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.

For example, here is the result of :CmpStatus: after a few minutes of work.

# ready source names
- vsnip
- buffer
- nvim_lsp:pylsp
- vsnip
- nvim_lsp:pylsp
- nvim_lsp:pylsp

Here is my nvim-cmpconfig :

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 ?

2 Answers 2

1

In your cmp configuration, you can use the dup keyword for vim_item with the formatting option / format function. See help for complete-item for explanations (: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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer but even after adding the dup config, I keep having the same source added multiple times when I open new buffers.
1

I had the same problem and managed to solve the issue by realizing that cmp is somehow installed twice.

Try removing or better first renaming the cmp-packages in the plugged directory, for example

cmp-nvim-lsp to cmp-nvim-lsp_not

cml-nvim-buffer to cmp-nvim-buffer_not etc.

This did the job for me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.