clangd_extensions.nvim icon indicating copy to clipboard operation
clangd_extensions.nvim copied to clipboard

"Corresponding file cannot be determined" printout when another LSP server exists

Open YanzhaoW opened this issue 7 months ago • 6 comments

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

YanzhaoW avatar Aug 13 '25 12:08 YanzhaoW

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?

p00f avatar Aug 13 '25 23:08 p00f

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

YanzhaoW avatar Aug 14 '25 13:08 YanzhaoW

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

p00f avatar Aug 14 '25 15:08 p00f

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?

YanzhaoW avatar Aug 15 '25 13:08 YanzhaoW

Which version of neovim do you have?

p00f avatar Aug 15 '25 14:08 p00f

Hi, @p00f

I'm using v0.11.2

YanzhaoW avatar Aug 16 '25 12:08 YanzhaoW