fix(lsp): handle empty call hierarchy items #30349

Ensure that the function `pick_call_hierarchy_item` correctly handles
the case where `call_hierarchy_items` is nil or an empty table. This
prevents potential errors when the function is called with no items.
This commit is contained in:
James Trew 2024-09-13 11:59:49 +00:00 committed by GitHub
parent 057314345a
commit 8654a97006
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -447,11 +447,9 @@ function M.document_symbol(opts)
request_with_opts(ms.textDocument_documentSymbol, params, opts) request_with_opts(ms.textDocument_documentSymbol, params, opts)
end end
--- @param call_hierarchy_items lsp.CallHierarchyItem[]? --- @param call_hierarchy_items lsp.CallHierarchyItem[]
--- @return lsp.CallHierarchyItem?
local function pick_call_hierarchy_item(call_hierarchy_items) local function pick_call_hierarchy_item(call_hierarchy_items)
if not call_hierarchy_items then
return
end
if #call_hierarchy_items == 1 then if #call_hierarchy_items == 1 then
return call_hierarchy_items[1] return call_hierarchy_items[1]
end end
@ -476,7 +474,7 @@ local function call_hierarchy(method)
vim.notify(err.message, vim.log.levels.WARN) vim.notify(err.message, vim.log.levels.WARN)
return return
end end
if not result then if not result or vim.tbl_isempty(result) then
vim.notify('No item resolved', vim.log.levels.WARN) vim.notify('No item resolved', vim.log.levels.WARN)
return return
end end