diff options
| author | Ashley Hauck <953151+khyperia@users.noreply.github.com> | 2026-04-23 14:20:58 +0200 |
|---|---|---|
| committer | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2026-04-23 23:07:07 +0000 |
| commit | 93dc301781ada92324d1e6419e1ccde870147364 (patch) | |
| tree | abf5c2ddcaac7b4f81a0023aa216f5744e80ef57 | |
| parent | 39e8c584d5b51681e0bcc98dce6d205a6acf285d (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)
(cherry picked from commit 7e006b06c4db1464be9c4e2826774fe6f0a4f880)
| -rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 13 | ||||
| -rw-r--r-- | test/functional/plugin/lsp/buf_spec.lua | 5 |
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 aff1e57be1..a49110bee0 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, |
