Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to setup extended clientCapabilities #30

Closed
mikehaertl opened this issue Jun 10, 2024 · 7 comments
Closed

Document how to setup extended clientCapabilities #30

mikehaertl opened this issue Jun 10, 2024 · 7 comments

Comments

@mikehaertl
Copy link
Contributor

I'm not sure if I missed anything, but for me the default setup is not enough, because nvim will not include the corresponding capabilities in the LSP initialize request.

So for nvim-lspconfig I had to add something like this to my config:

local lspconfig = require'lspconfig'
local util = lspconfig.util

-- Set global defaults for all servers
util.default_config = vim.tbl_extend(
  'force',
  util.default_config,
  {
    capabilities = vim.tbl_deep_extend(
      "force",
      vim.lsp.protocol.make_client_capabilities(),

      -- support added by lsp-file-operations
      {
        workspace = {
          fileOperations = {
            willRename = true,
            didRename = true,
            willCreate = true,
            didCreate = true,
            willDelete = true,
            didDelete = true,
          }
        }
      }
    )
  }
)

Shouldn't this be mentioned in the README?

@antosha417
Copy link
Owner

antosha417 commented Jun 10, 2024

It depends on language server that you are using. Most of language servers do not support all kinds of file operations.
What exactly does not work for you? What language server are you using?

@mikehaertl
Copy link
Contributor Author

It's eclipse.jdt.ls via nvim-jdtls.

To clarify: It does work - but only if I let neovim report the above client capabilities. Correct me if I'm wrong, but what I think how it works:

  • Client reports its capabilites to server (e.g. workspace.fileOperations.willRename)
  • Server responds with an intersection of all its supported capabilites and the client capabilities

Without my above change the server response did not include workspace.fileOperations.willRename even though the server does support this operation.

@mikehaertl
Copy link
Contributor Author

To clarify: lspconfig.util.default_config.capabilities configures the client capabilities, not the server capabilities.

@antosha417
Copy link
Owner

I get it now. We add recipes for specific language servers to the wiki
https:/antosha417/nvim-lsp-file-operations/wiki

You can also open a pr and add it to readme if you want.

@mikehaertl
Copy link
Contributor Author

So you did not have this problem? Then maybe LSP servers behave differently and only jdt.ls has this problem.

If you think it makes sense I can still provide a PR for the README later.

@antosha417
Copy link
Owner

I mostly use metals language server for scala with https:/scalameta/nvim-metals
I make client capabilities like this and they don't contain any of the file operations

    local capabilities = vim.lsp.protocol.make_client_capabilities()

But still metals language server returns everything.

I think it is ok to add some specific instructions to the readme, it might save people time.

@mikehaertl
Copy link
Contributor Author

What do you think about providing a utility method that returns the capabilities to add? That's how cmp-nvim-lsp does it.

It can be used to extend nvim's default capabilities as suggested here. It would look like this:

local lspconfig = require'lspconfig'
local cmp_nvim_lsp = require'cmp_nvim_lsp'
local lsp_file_operations = require'lsp-file-operations'
local util = lspconfig.util

-- Set global defaults for all servers
util.default_config = vim.tbl_extend(
  'force',
  util.default_config,
  {
    capabilities = vim.tbl_deep_extend(
      "force",
      vim.lsp.protocol.make_client_capabilities(),
      cmp_nvim_lsp.default_capabilities(),
      lsp_file_operations.default_capabilities(),
    )
  }
)

mikehaertl added a commit to mikehaertl/nvim-lsp-file-operations that referenced this issue Jun 15, 2024
antosha417 added a commit that referenced this issue Jun 15, 2024
Issue #30 Add utility to get client capabilities for LSP server config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants