mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 12:28:18 +00:00
feat(lsp): support signature help noActiveParameterSupport #34838
This commit is contained in:
@@ -87,6 +87,11 @@ LSP
|
|||||||
• `vim.lsp.semantic_tokens.start/stop` now renamed to
|
• `vim.lsp.semantic_tokens.start/stop` now renamed to
|
||||||
`vim.lsp.semantic_tokens.enable`
|
`vim.lsp.semantic_tokens.enable`
|
||||||
• Missing fields in LSP messages are now represented using |vim.NIL| instead of nil.
|
• Missing fields in LSP messages are now represented using |vim.NIL| instead of nil.
|
||||||
|
• |vim.lsp.util.convert_signature_help_to_markdown_lines()| activeParameter
|
||||||
|
handling updated:
|
||||||
|
• Values < 0 are now treated as `nil` instead of 0.
|
||||||
|
• Values outside the range of `signatures[activeSignature].parameters`
|
||||||
|
are now treated as `nil` instead of `#signatures[activeSignature].parameters`
|
||||||
|
|
||||||
LUA
|
LUA
|
||||||
|
|
||||||
@@ -222,6 +227,7 @@ LSP
|
|||||||
https://microsoft.github.io/language-server-protocol/specification/#textDocument_linkedEditingRange
|
https://microsoft.github.io/language-server-protocol/specification/#textDocument_linkedEditingRange
|
||||||
• Support for related documents in pull diagnostics:
|
• Support for related documents in pull diagnostics:
|
||||||
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#relatedFullDocumentDiagnosticReport
|
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#relatedFullDocumentDiagnosticReport
|
||||||
|
• |vim.lsp.buf.signature_help()| supports "noActiveParameterSupport".
|
||||||
|
|
||||||
LUA
|
LUA
|
||||||
|
|
||||||
|
@@ -330,8 +330,8 @@ local function process_signature_help_results(results)
|
|||||||
)
|
)
|
||||||
api.nvim_command('redraw')
|
api.nvim_command('redraw')
|
||||||
else
|
else
|
||||||
local result = r.result --- @type lsp.SignatureHelp
|
local result = r.result
|
||||||
if result and result.signatures and result.signatures[1] then
|
if result and result.signatures then
|
||||||
for i, sig in ipairs(result.signatures) do
|
for i, sig in ipairs(result.signatures) do
|
||||||
sig.activeParameter = sig.activeParameter or result.activeParameter
|
sig.activeParameter = sig.activeParameter or result.activeParameter
|
||||||
local idx = #signatures + 1
|
local idx = #signatures + 1
|
||||||
|
@@ -514,6 +514,7 @@ function protocol.make_client_capabilities()
|
|||||||
dynamicRegistration = false,
|
dynamicRegistration = false,
|
||||||
signatureInformation = {
|
signatureInformation = {
|
||||||
activeParameterSupport = true,
|
activeParameterSupport = true,
|
||||||
|
noActiveParameterSupport = true,
|
||||||
documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText },
|
documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText },
|
||||||
parameterInformation = {
|
parameterInformation = {
|
||||||
labelOffsetSupport = true,
|
labelOffsetSupport = true,
|
||||||
|
@@ -829,18 +829,21 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft, triggers
|
|||||||
M.convert_input_to_markdown_lines(signature.documentation, contents)
|
M.convert_input_to_markdown_lines(signature.documentation, contents)
|
||||||
end
|
end
|
||||||
if signature.parameters and #signature.parameters > 0 then
|
if signature.parameters and #signature.parameters > 0 then
|
||||||
-- First check if the signature has an activeParameter. If it doesn't check if the response
|
local active_parameter = signature.activeParameter or signature_help.activeParameter
|
||||||
-- had that property instead. Else just default to 0.
|
|
||||||
--
|
|
||||||
-- NOTE: Using tonumber() as a temporary workaround to handle `vim.NIL` until #34838 is merged
|
|
||||||
local active_parameter = math.max(
|
|
||||||
tonumber(signature.activeParameter) or tonumber(signature_help.activeParameter) or 0,
|
|
||||||
0
|
|
||||||
)
|
|
||||||
|
|
||||||
-- If the activeParameter is > #parameters, then set it to the last
|
-- NOTE: We intentionally violate the LSP spec, which states that if `activeParameter`
|
||||||
-- NOTE: this is not fully according to the spec, but a client-side interpretation
|
-- is not provided or is out-of-bounds, it should default to 0.
|
||||||
active_parameter = math.min(active_parameter, #signature.parameters - 1)
|
-- Instead, we default to `nil`, as most clients do. In practice, 'no active parameter'
|
||||||
|
-- is better default than 'first parameter' and aligns better with user expectations.
|
||||||
|
-- Related discussion: https://github.com/microsoft/language-server-protocol/issues/1271
|
||||||
|
if
|
||||||
|
not active_parameter
|
||||||
|
or active_parameter == vim.NIL
|
||||||
|
or active_parameter < 0
|
||||||
|
or active_parameter >= #signature.parameters
|
||||||
|
then
|
||||||
|
return contents, nil
|
||||||
|
end
|
||||||
|
|
||||||
local parameter = signature.parameters[active_parameter + 1]
|
local parameter = signature.parameters[active_parameter + 1]
|
||||||
local parameter_label = parameter.label
|
local parameter_label = parameter.label
|
||||||
|
Reference in New Issue
Block a user