How to disable LSP snippets

I manage my own snippets using Ultisnips, I don’t want conflicting snippets from the LSP server.

image

After Googling around it sounds like I should be able to disable snippets by doing:

lspconfig.yang_lsp.setup {
  on_attach = lsp_on_attach,
  capabilities = {
    textDocument = {
      completion = {
        completionItem = {
          snippetSupport = false
        }
      }
    }
  }
}

But that doesn’t work, compe is still suggesting LSP snippets.

I can’t just disable the LSP source in nvim-compe altogether, they are the primary reason I bother to use a completion plugin. Auto completion for types and identifiers from the LSP are invaluable.

I’m not sure how LSP capabilities work, is it just a “suggestion” for the LSP server that I don’t want snippets? Can the LSP server ignore it and suggest them anyway? If so, how do I get rid of them?

(I’m using nvim-compe)


I’m using nvim-lspconfig with yang-lsp:

-- Custom config for YANG language server
--
lspconfig_configs.yang_lsp = {
  default_config = {
    cmd = { "yang-language-server" },
    filetypes = { "yang" },
    root_dir = function(fname)
      return lsputil.root_pattern("yang.settings")(fname)
    end,
  },
  docs = {
    description = [[
TODO
    ]],
  },
}

Same issue, have you solved it?

I guess I did, because I’m no longer getting snippets from the LSP.

I don’t remember what I did though. This is the only special configuration I set:

lspconfig.yang_lsp.setup {
  on_attach = _G.lsp_on_attach,
  capabilities = {
    textDocument = {
      completion = {
        completionItem = {
          snippetSupport = false
        }
      }
    }
  }
}

Which, according to my original post, didn’t work. Perhaps it started working after an update or something.

Thank you for the reply. I want to disable the snippets from clangd, but the same configuration can’t work for me.

I found a solution that works for clangd, it should also work for all language servers.

require "cmp".setup {
    sources = {
        {
            name = "nvim_lsp",
            entry_filter = function(entry)
                return require("cmp").lsp.CompletionItemKind.Snippet ~= entry:get_kind()
            end
        },
    }
}
2 Likes

I can confirm this works for me as well.

This also works with lsp-zero

here is how I implemented it with lsp zero

local lsp = require("lsp-zero")
local lua_snip = require("luasnip")
lsp.preset("recommended")

local cmp_sources = {

    { name = 'luasnip' }, -- For luasnip users.
    { name = 'nvim_lsp',
    entry_filter = function(entry)
                return require("cmp").lsp.CompletionItemKind.Snippet ~= entry:get_kind()
            end },
    { name = 'path' },
    { name = 'nvim_lua' },
}

lsp.setup_nvim_cmp({
    mapping = cmp_mappings, 
    snippet = cmp_snippet,
    sources = cmp_sources, 
})

1 Like