feat(lsp): <Plug> mapping for signature help cycling #34039

Replace direct function mappings with `<Plug>` mappings for cycling
through overloaded signatures, providing better customization options
for users. This change keeps the default mapping (`<C-s>`) for cycling
if `<Plug>(nvim.lsp.ctrl-s)` is not mapped.
This commit is contained in:
Tiago Inaba
2025-06-12 14:56:39 -03:00
committed by GitHub
parent f99e3a8a2a
commit 7486c2f6aa
2 changed files with 22 additions and 3 deletions

View File

@ -1845,7 +1845,12 @@ selection_range({direction}) *vim.lsp.buf.selection_range()*
signature_help({config}) *vim.lsp.buf.signature_help()*
Displays signature information about the symbol under the cursor in a
floating window.
floating window. Allows cycling through signature overloads with `<C-s>`,
which can be remapped via `<Plug>(nvim.lsp.ctrl-s)`
Example: >lua
vim.keymap.set('n', '<C-b>', '<Plug>(nvim.lsp.ctrl-s)')
<
Parameters: ~
• {config} (`vim.lsp.buf.signature_help.Opts?`) See

View File

@ -345,7 +345,15 @@ local sig_help_ns = api.nvim_create_namespace('nvim.lsp.signature_help')
--- @field silent? boolean
--- Displays signature information about the symbol under the cursor in a
--- floating window.
--- floating window. Allows cycling through signature overloads with `<C-s>`,
--- which can be remapped via `<Plug>(nvim.lsp.ctrl-s)`
---
--- Example:
---
--- ```lua
--- vim.keymap.set('n', '<C-b>', '<Plug>(nvim.lsp.ctrl-s)')
--- ```
---
--- @param config? vim.lsp.buf.signature_help.Opts
function M.signature_help(config)
local method = ms.textDocument_signatureHelp
@ -420,12 +428,18 @@ function M.signature_help(config)
local fbuf, fwin = show_signature()
if can_cycle then
vim.keymap.set('n', '<C-s>', function()
vim.keymap.set('n', '<Plug>(nvim.lsp.ctrl-s)', function()
show_signature(fwin)
end, {
buffer = fbuf,
desc = 'Cycle next signature',
})
if vim.fn.hasmapto('<Plug>(nvim.lsp.ctrl-s)', 'n') == 0 then
vim.keymap.set('n', '<C-s>', '<Plug>(nvim.lsp.ctrl-s)', {
buffer = fbuf,
desc = 'Cycle next signature',
})
end
end
end)
end