rust-tools.nvim icon indicating copy to clipboard operation
rust-tools.nvim copied to clipboard

Add documentation regarding nvim-cmp

Open diktomat opened this issue 3 years ago • 2 comments

Setting up nvim-cmp with LSP they recommend this:

  -- Setup lspconfig.
  local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
  -- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
  require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
    capabilities = capabilities
  }

Adding the recommendation of nvim-lspconfig, we arrive at something like this:

local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
local lsp_attach = function(client, buf)
    -- setup keymaps etc
end
require("lspconfig")["server"].setup({
    capabilities = capabilities,
    on_attach = lsp_attach,
})

The recommended setup for rust-tools is an empty call to require('rust-tools').setup({}). While on_attach seems to be a straightforward add, documentation's not clear about capabilities. Having looked into the source of both rust-tools and cmp-nvim-lsp, they don't conflict and one should just be able to do as with pure lspconfig/cmp:

local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
local lsp_attach = function(client, buf)
    -- setup keymaps etc
end
require("rust-tools").setup({
    server = {
        capabilities = capabilities,
        on_attach = lsp_attach,
    }
})

This is a potential source of confusion, however (not only for me, see #131). So I suggest clarifying this in the README and maybe even recommend doing this way for cmp, as cmp-nvim-lsp seems to add more stuff to completionItem.

diktomat avatar May 12 '22 09:05 diktomat

This also helped me understand what to do. Thanks!

TrevorS avatar May 16 '22 23:05 TrevorS

That's a good idea, maybe we should add it to the wiki and reference in the readme under a usage with other plugins section

simrat39 avatar May 18 '22 07:05 simrat39