commit 9e93bfdb5fcedbb2a829e4528c3536de1a06eeed
parent 8090dcf49493cc8f2352d0e92a0c7a2cae65da54
Author: Yi Ming <ofseed@foxmail.com>
Date: Sat, 26 Apr 2025 15:44:30 +0800
fix(lsp): prioritize showing active signature
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
@@ -309,6 +309,7 @@ end
--- @param results table<integer,{err: lsp.ResponseError?, result: lsp.SignatureHelp?}>
local function process_signature_help_results(results)
local signatures = {} --- @type [vim.lsp.Client,lsp.SignatureInformation][]
+ local active_signature = 1
-- Pre-process results
for client_id, r in pairs(results) do
@@ -323,15 +324,19 @@ local function process_signature_help_results(results)
else
local result = r.result --- @type lsp.SignatureHelp
if result and result.signatures and result.signatures[1] then
- for _, sig in ipairs(result.signatures) do
+ for i, sig in ipairs(result.signatures) do
sig.activeParameter = sig.activeParameter or result.activeParameter
- signatures[#signatures + 1] = { client, sig }
+ local idx = #signatures + 1
+ if (result.activeSignature or 0) + 1 == i then
+ active_signature = idx
+ end
+ signatures[idx] = { client, sig }
end
end
end
end
- return signatures
+ return signatures, active_signature
end
local sig_help_ns = api.nvim_create_namespace('nvim.lsp.signature_help')
@@ -354,7 +359,7 @@ function M.signature_help(config)
return
end
- local signatures = process_signature_help_results(results)
+ local signatures, active_signature = process_signature_help_results(results)
if not next(signatures) then
if config.silent ~= true then
@@ -366,7 +371,7 @@ function M.signature_help(config)
local ft = vim.bo[ctx.bufnr].filetype
local total = #signatures
local can_cycle = total > 1 and config.focusable
- local idx = 0
+ local idx = active_signature - 1
--- @param update_win? integer
local function show_signature(update_win)