mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
fix(lsp): SignatureHelp docstring is not escaped #16702
Problem: Nvim LSP client always treats signature.documentation as markdown, even if the server returns a plain string. Per https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#signatureInformation in a SignatureInformation response, the documentation field can be either "string" or "MarkupContent". Solution: If signature.documentation is a string, treat it as "plaintext". Closes #16563
This commit is contained in:
parent
898384ac69
commit
20c331915f
@ -1002,6 +1002,12 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft, triggers
|
||||
end
|
||||
list_extend(contents, split(label, '\n', { plain = true }))
|
||||
if signature.documentation then
|
||||
-- if LSP returns plain string, we treat it as plaintext. This avoids
|
||||
-- special characters like underscore or similar from being interpreted
|
||||
-- as markdown font modifiers
|
||||
if type(signature.documentation) == 'string' then
|
||||
signature.documentation = { kind = 'plaintext', value = signature.documentation }
|
||||
end
|
||||
M.convert_input_to_markdown_lines(signature.documentation, contents)
|
||||
end
|
||||
if signature.parameters and #signature.parameters > 0 then
|
||||
|
@ -3006,7 +3006,7 @@ describe('LSP', function()
|
||||
activeSignature = -1,
|
||||
signatures = {
|
||||
{
|
||||
documentation = "",
|
||||
documentation = "some doc",
|
||||
label = "TestEntity.TestEntity()",
|
||||
parameters = {}
|
||||
},
|
||||
@ -3014,7 +3014,7 @@ describe('LSP', function()
|
||||
}
|
||||
return vim.lsp.util.convert_signature_help_to_markdown_lines(signature_help, 'cs', {','})
|
||||
]]
|
||||
local expected = {'```cs', 'TestEntity.TestEntity()', '```', ''}
|
||||
local expected = {'```cs', 'TestEntity.TestEntity()', '```', '<text>', 'some doc', '</text>'}
|
||||
eq(expected, result)
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user