From 8654a9700690a715e35baa600bb982f4ea608ead Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:59:49 +0000 Subject: [PATCH] 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. --- runtime/lua/vim/lsp/buf.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index e51727ef13..a43ad8a690 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -447,11 +447,9 @@ function M.document_symbol(opts) request_with_opts(ms.textDocument_documentSymbol, params, opts) 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) - if not call_hierarchy_items then - return - end if #call_hierarchy_items == 1 then return call_hierarchy_items[1] end @@ -476,7 +474,7 @@ local function call_hierarchy(method) vim.notify(err.message, vim.log.levels.WARN) return end - if not result then + if not result or vim.tbl_isempty(result) then vim.notify('No item resolved', vim.log.levels.WARN) return end