fix(lsp): prioritize showing active signature

(cherry picked from commit 9e93bfdb5f)
This commit is contained in:
Yi Ming
2025-04-26 15:44:30 +08:00
committed by github-actions[bot]
parent 9909580df2
commit 95f96a3d1b

View File

@ -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)