Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lua/navigator/definition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ local function def_preview(timeout_ms, method, client, bufnr)
local data = {}

for _, value in pairs(result) do
if value ~= nil and value.result ~= nil and not vim.tbl_isempty(value.result) then
table.insert(data, value.result[1])
if value ~= nil and not vim.tbl_isempty(value) then
table.insert(data, value[1])
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I did not notice it was broken.

end
end

Expand Down
24 changes: 18 additions & 6 deletions lua/navigator/hierarchy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,34 @@ end

local request = vim.lsp.buf_request

local function pick_hierarchy_lsp_client(bufnr, method)
bufnr = bufnr or 0
method = method or vim.lsp.protocol.Methods.textDocument_prepareCallHierarchy
local file = vim.api.nvim_buf_get_name(bufnr)

for _, client in ipairs(vim.lsp.get_clients({ bufnr = bufnr, method = method })) do
if client.server_capabilities.callHierarchyProvider then
local root = client.config and client.config.root_dir
if not root or file:find(root, 1, true) == 1 then
Copy link
Copy Markdown
Owner

@ray-x ray-x Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be?

if root and file:find(root, 1, true) == 1

Is there an example of lsp returns nil value for root_dir?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thoughts here were to not enforce root to cover edge cases where a bad configuration or architectural decisions of some LSP's could lead to a nil root_dir since the protocol allows it. Personally, I've no encounter these cases since all the LSP's that I use always have a defined root_dir but I'll let you decide here, if you think it's better to enforce root I can change it, let me know.

return client
end
end
end
return nil
end

-- call_hierarchy with floating window
call_hierarchy = function(method, opts)
local client = opts.client
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()

log(method, opts, client, bufnr)
if not client then
local clients = vim.lsp.get_clients({
bufnr = bufnr,
method = method,
})
if not clients or #clients == 0 then
client = pick_hierarchy_lsp_client(bufnr, method)
if not client then
vim.notify('no call hierarchy clients found for bufnr')
return
end
client = clients[1]
end
trace(method, opts)
opts = opts or {}
Expand Down
Loading