hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
8.16k stars 407 forks source link

How to get rid of the results from a certain LSP in the completion menu? #822

Closed nyngwang closed 2 years ago

nyngwang commented 2 years ago

As title. I'm using both pyright and pylsp (both are documented in the nvim-lspconfig). The reason why I'm using two LSPs for python are:

OK, so here I just want to show the results of pyright and get rid of those from pylsp. So basically pylsp is just a formattor. Could you please help?

Here is some of my settings I thought it should work:

pylsp:

M = {
  -- here I already removed the `require('cmp_nvim_lsp')...`, but the results still contain those from `pylsp` :(
  autostart = true,
  on_attach = function (client, bufnr)
    require('lsp_config.common_setup')(client, bufnr)
    if (client.resolved_capabilities.document_formatting) then
      vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()")
    end
  end
}

return M

pyright:

M = {
  capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
  autostart = true,
  on_attach = function (client, bufnr)
    client.resolved_capabilities.document_formatting = false
    client.resolved_capabilities.document_range_formatting = false
    require('lsp_config.common_setup')(client, bufnr)
  end
}

return M

Screenshots:

Shougo commented 2 years ago

It seems nvim-lsp configuration problem. I think LSP can disable the completion by config.

Shougo commented 2 years ago

https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md

pylsp.plugins.jedi_completion.enabled boolean Enable or disable the plugin. true

I think you need to disable it.

nyngwang commented 2 years ago

To @Shougo: Many thanks for the link!

nyngwang commented 2 years ago

@Shougo: May I also ask you where should I put these config settings? Somewhere like the pylsp setup { } of nvim-lspconfig?

Shougo commented 2 years ago

You can set LSP specific config like this. https://github.com/nvim-lua/kickstart.nvim/blob/master/init.lua#L242

nyngwang commented 2 years ago

Thank you! During the waiting I found this too: https://neovim.discourse.group/t/pylsp-config-is-not-taken-into-account/1846/2?u=nyngwang hope this will help the others who find this.

hrsh7th commented 2 years ago

You can add the client.server_capabilities.completionProvider = false

nyngwang commented 2 years ago

@hrsh7th: Thank you a lot!