mirror of
https://github.com/neovim/neovim.git
synced 2025-12-17 11:55:34 +00:00
feat(lsp): use fancy_floating_markdown for signature_help
This commit is contained in:
@@ -271,9 +271,7 @@ function M.hover(_, method, result, _, _, config)
|
|||||||
-- return { 'No information available' }
|
-- return { 'No information available' }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local bufnr, winnr = util.fancy_floating_markdown(markdown_lines, {
|
local bufnr, winnr = util.fancy_floating_markdown(markdown_lines, config)
|
||||||
border = config.border
|
|
||||||
})
|
|
||||||
util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, winnr)
|
util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, winnr)
|
||||||
return bufnr, winnr
|
return bufnr, winnr
|
||||||
end)
|
end)
|
||||||
@@ -341,17 +339,20 @@ function M.signature_help(_, method, result, _, bufnr, config)
|
|||||||
print('No signature help available')
|
print('No signature help available')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local lines = util.convert_signature_help_to_markdown_lines(result)
|
local p_bufnr, winnr = util.focusable_float(method, function()
|
||||||
lines = util.trim_empty_lines(lines)
|
local ft = api.nvim_buf_get_option(bufnr, 'filetype')
|
||||||
if vim.tbl_isempty(lines) then
|
local lines = util.convert_signature_help_to_markdown_lines(result, ft)
|
||||||
print('No signature help available')
|
lines = util.trim_empty_lines(lines)
|
||||||
return
|
if vim.tbl_isempty(lines) then
|
||||||
end
|
print('No signature help available')
|
||||||
local syntax = api.nvim_buf_get_option(bufnr, 'syntax')
|
return
|
||||||
local p_bufnr, _ = util.focusable_preview(method, function()
|
end
|
||||||
return lines, util.try_trim_markdown_code_blocks(lines), config
|
local p_bufnr, p_winnr = util.fancy_floating_markdown(lines, config)
|
||||||
|
util.close_preview_autocmd({"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre"}, p_winnr)
|
||||||
|
|
||||||
|
return p_bufnr, p_winnr
|
||||||
end)
|
end)
|
||||||
api.nvim_buf_set_option(p_bufnr, 'syntax', syntax)
|
return p_bufnr, winnr
|
||||||
end
|
end
|
||||||
|
|
||||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
|
||||||
|
|||||||
@@ -804,9 +804,10 @@ end
|
|||||||
--- Converts `textDocument/SignatureHelp` response to markdown lines.
|
--- Converts `textDocument/SignatureHelp` response to markdown lines.
|
||||||
---
|
---
|
||||||
--@param signature_help Response of `textDocument/SignatureHelp`
|
--@param signature_help Response of `textDocument/SignatureHelp`
|
||||||
|
--@param ft optional filetype that will be use as the `lang` for the label markdown code block
|
||||||
--@returns list of lines of converted markdown.
|
--@returns list of lines of converted markdown.
|
||||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
|
||||||
function M.convert_signature_help_to_markdown_lines(signature_help)
|
function M.convert_signature_help_to_markdown_lines(signature_help, ft)
|
||||||
if not signature_help.signatures then
|
if not signature_help.signatures then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -824,7 +825,12 @@ function M.convert_signature_help_to_markdown_lines(signature_help)
|
|||||||
if not signature then
|
if not signature then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.list_extend(contents, vim.split(signature.label, '\n', true))
|
local label = signature.label
|
||||||
|
if ft then
|
||||||
|
-- wrap inside a code block so fancy_markdown can render it properly
|
||||||
|
label = ("```%s\n%s\n```"):format(ft, label)
|
||||||
|
end
|
||||||
|
vim.list_extend(contents, vim.split(label, '\n', true))
|
||||||
if signature.documentation then
|
if signature.documentation then
|
||||||
M.convert_input_to_markdown_lines(signature.documentation, contents)
|
M.convert_input_to_markdown_lines(signature.documentation, contents)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user