fix(lsp): abort callHierarchy on no result (#28102)

The `callHierarchy` function should warn the user when
`textDocument/prepareCallHierarchy` didn't resolve an entity and
return, rather than calling the `callHierarchy/{incoming,outgoing}Calls`
method with an empty object - which is encoded as an empty list (which
doesn't respect language server specification for the
`callHierarchy/incomingCalls` call).
This commit is contained in:
Marcin Szamotulski 2024-03-31 20:43:34 +02:00 committed by GitHub
parent b25753381c
commit 01691c5447
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -461,7 +461,14 @@ local function call_hierarchy(method)
vim.notify(err.message, vim.log.levels.WARN)
return
end
if not result then
vim.notify('No item resolved', vim.log.levels.WARN)
return
end
local call_hierarchy_item = pick_call_hierarchy_item(result)
if not call_hierarchy_item then
return
end
local client = vim.lsp.get_client_by_id(ctx.client_id)
if client then
client.request(method, { item = call_hierarchy_item }, nil, ctx.bufnr)