Closed mikehaertl closed 4 months ago
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?
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:
workspace.fileOperations.willRename
)Without my above change the server response did not include workspace.fileOperations.willRename
even though the server does support this operation.
To clarify: lspconfig.util.default_config.capabilities
configures the client capabilities, not the server capabilities.
I get it now. We add recipes for specific language servers to the wiki https://github.com/antosha417/nvim-lsp-file-operations/wiki
You can also open a pr and add it to readme if you want.
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.
I mostly use metals language server for scala with https://github.com/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.
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(),
)
}
)
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:Shouldn't this be mentioned in the README?