4

I'm using NeoVim with autocomplete using nvim-lspconfig and nvim-cmp. I would like to know if there's a way of filtering out text feeds from the autocompletion menu, so that they don't appear in the contextual menu:

enter image description here

Massimiliano
  • 615
  • 4
  • 15

2 Answers2

4

In your setup you can exclude any kind if suggestions thanks to this merged PR.

What is happening is the function "entry_filter" is getting called whenever a suggestion for nvim_lsp is being made. in it we return false if the entry is of the kind "text".

local cmp = require "cmp"

cmp.setup {
    ...
    sources = cmp.config.sources({
        -- Dont suggest Text from nvm_lsp
        { name = "nvim_lsp",
            entry_filter = function(entry, ctx)
                return require("cmp").lsp.CompletionItemKind.Text ~= entry:get_kind()
            end },
    })
}
Hampus
  • 276
  • 2
  • 8
1

Check out nvim-cmp sources list and remove whatever source you don't want to use. Text is quite probably coming from buffer:

cmp.setup({
    ...
    sources = cmp.config.sources({
        { name = 'buffer' }, -- <- remove
        { name = 'nvim_lsp' },
        ...
    })

})
  • 1
    Thanks for the suggestion. I tried removing the buffer source, but it seems that the only completion removed refers to the words already in the buffer. I played around with the configuration, and it seems that the source is **nvim_lsp**. The problem is that the source contains the snippets and completions from the other language servers. – Massimiliano Jul 27 '22 at 22:20
  • 3
    There's a [nvim-cmp PR](https://github.com/hrsh7th/nvim-cmp/pull/1067) to allow for filtering based on `kind`. – dominik-filip Jul 27 '22 at 23:17