summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAshley Hauck <953151+khyperia@users.noreply.github.com>2026-04-23 14:20:58 +0200
committerGitHub <noreply@github.com>2026-04-23 08:20:58 -0400
commit7e006b06c4db1464be9c4e2826774fe6f0a4f880 (patch)
tree04f97bfd1a86bf5abb9a9c2b967c5377903b8d7b
parentecb8402197f1883feec1c7a9f9d02a39912ae04a (diff)
fix(lsp): callHierarchy/outgoingCalls ranges are relative to caller, not callee #39336
Problem: The fromRanges field of the result of callHierarchy/outgoingCalls is documented as being relative to the caller. Using vim.lsp.buf.outgoing_calls() opened the qflist with an entry with the callee's filename, but the caller's line number. Solution: Open the qflist with the callers file (the bufnr from the request), rather than the callees (the uri from the resulting CallHierarchyItem)
-rw-r--r--runtime/lua/vim/lsp/handlers.lua13
-rw-r--r--test/functional/plugin/lsp/buf_spec.lua5
2 files changed, 14 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index f8c1db9607..f4765183af 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -519,7 +519,8 @@ end
--- @overload fun(direction:'to'): fun(_, result: lsp.CallHierarchyOutgoingCall[]?)
local function make_call_hierarchy_handler(direction)
--- @param result lsp.CallHierarchyIncomingCall[]|lsp.CallHierarchyOutgoingCall[]
- return function(_, result)
+ --- @param ctx lsp.HandlerContext
+ return function(_, result, ctx)
if not result then
return
end
@@ -527,9 +528,17 @@ local function make_call_hierarchy_handler(direction)
for _, call_hierarchy_call in pairs(result) do
--- @type lsp.CallHierarchyItem
local call_hierarchy_item = call_hierarchy_call[direction]
+ local filename = nil
+ local bufnr = nil
+ if direction == 'from' then
+ filename = assert(vim.uri_to_fname(call_hierarchy_item.uri))
+ else
+ bufnr = ctx.bufnr
+ end
for _, range in pairs(call_hierarchy_call.fromRanges) do
table.insert(items, {
- filename = assert(vim.uri_to_fname(call_hierarchy_item.uri)),
+ filename = filename,
+ bufnr = bufnr,
text = call_hierarchy_item.name,
lnum = range.start.line + 1,
col = range.start.character + 1,
diff --git a/test/functional/plugin/lsp/buf_spec.lua b/test/functional/plugin/lsp/buf_spec.lua
index 4f88108419..f5fc498ef6 100644
--- a/test/functional/plugin/lsp/buf_spec.lua
+++ b/test/functional/plugin/lsp/buf_spec.lua
@@ -106,13 +106,14 @@ describe('vim.lsp.buf', function()
},
}
local handler = require 'vim.lsp.handlers'['callHierarchy/outgoingCalls']
- handler(nil, rust_analyzer_response, {})
+ local bufnr = vim.api.nvim_get_current_buf()
+ handler(nil, rust_analyzer_response, { bufnr = bufnr })
return vim.fn.getqflist()
end)
local expected = {
{
- bufnr = 2,
+ bufnr = 1,
col = 5,
end_col = 0,
lnum = 4,