"Corresponding file cannot be determined" printout when another LSP server exists
Problem
When using other LSPs, such as csspell_ls, using switch_source_header always results in a printout of
Corresponding file cannot be determined.
This is due to that csspell_ls, as a LSP for spell checking, can't find the source or header file.
Possible solutions
Change
https://github.com/p00f/clangd_extensions.nvim/blob/b67cc417d9020fb4b83d46662351b4d16894905e/lua/clangd_extensions/utils.lua#L3-L8
to
function M.buf_request_method(method, params, handler, bufnr)
local clients = vim.lsp.get_clients({ bufnr = bufnr, method = method })
for _, client in pairs(clients) do
if client.name == "clangd" then
client:request(method, params, handler, bufnr)
return
end
end
end
The client name doesn't have to be clangd for clangd, see :h vim.lsp.ClientConfig - it is user defined. Why does csspell_ls advertise support for textDocument/switchSourceHeader?
Hi, thanks for reply.
I guess csspell_ls doesn't support textDocument/switchSourceHeader and that's the reason when it's called with client:request, the handler gets uri of nil. And it triggers the printout of "Corresponding file cannot be determined." from
https://github.com/p00f/clangd_extensions.nvim/blob/b67cc417d9020fb4b83d46662351b4d16894905e/lua/clangd_extensions/switch_source_header.lua#L4-L18
this line https://github.com/p00f/clangd_extensions.nvim/blob/b67cc417d9020fb4b83d46662351b4d16894905e/lua/clangd_extensions/utils.lua#L4
filters clients which are attached to the same buffer and support the requested method (the method = method part, see :h vim.lsp.get_clients()), so if csspell_ls is advertising this method it's a bug in csspell_ls
I see. Maybe it's a bug from csspell_ls, or maybe it accepts everything but not implemented at the end. Sorry that I'm not familiar with how neovim LSP works under the hood.
Would it be possible to have a toggle option to disable the printout of "Corresponding file cannot be determined" such that this plugin can still work well even if some LSPs have some bugs?
Which version of neovim do you have?
Hi, @p00f
I'm using v0.11.2