Massimiliano
Massimiliano

Reputation: 665

Neovim - How to filter out text snippets from nvim-lspconfig + nvim-cmp

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

Upvotes: 8

Views: 3306

Answers (2)

Hampus
Hampus

Reputation: 346

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 },
    })
}

Upvotes: 7

dominik-filip
dominik-filip

Reputation: 46

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' },
        ...
    })

})

Upvotes: 2

Related Questions