mirror of
https://github.com/neovim/neovim.git
synced 2025-11-14 06:18:50 +00:00
feat(lsp): improve LSP doc hover rendering #30695
Problem: - Some servers like LuaLS add unwanted blank lines after multiline `@param` description. - List items do not wrap nicely. Solution: - When rendering the LSP doc hover, remove blank lines in each `@param` or `@return`. - But ensure exactly one empty line before each. - Set 'breakindent'.
This commit is contained in:
@@ -83,7 +83,62 @@ describe('vim.lsp.util', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('normalize_markdown', function()
|
||||
it('convert_input_to_markdown_lines', function()
|
||||
local r = exec_lua(function()
|
||||
local hover_data = {
|
||||
kind = 'markdown',
|
||||
value = '```lua\nfunction vim.api.nvim_buf_attach(buffer: integer, send_buffer: boolean, opts: vim.api.keyset.buf_attach)\n -> boolean\n```\n\n---\n\n Activates buffer-update events. Example:\n\n\n\n ```lua\n events = {}\n vim.api.nvim_buf_attach(0, false, {\n on_lines = function(...)\n table.insert(events, {...})\n end,\n })\n ```\n\n\n @see `nvim_buf_detach()`\n @see `api-buffer-updates-lua`\n@*param* `buffer` — Buffer handle, or 0 for current buffer\n\n\n\n@*param* `send_buffer` — True if whole buffer.\n Else the first notification will be `nvim_buf_changedtick_event`.\n\n\n@*param* `opts` — Optional parameters.\n\n - on_lines: Lua callback. Args:\n - the string "lines"\n - buffer handle\n - b:changedtick\n@*return* — False if foo;\n\n otherwise True.\n\n@see foo\n@see bar\n\n',
|
||||
}
|
||||
return vim.lsp.util.convert_input_to_markdown_lines(hover_data)
|
||||
end)
|
||||
local expected = {
|
||||
'```lua',
|
||||
'function vim.api.nvim_buf_attach(buffer: integer, send_buffer: boolean, opts: vim.api.keyset.buf_attach)',
|
||||
' -> boolean',
|
||||
'```',
|
||||
'',
|
||||
'---',
|
||||
'',
|
||||
' Activates buffer-update events. Example:',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
' ```lua',
|
||||
' events = {}',
|
||||
' vim.api.nvim_buf_attach(0, false, {',
|
||||
' on_lines = function(...)',
|
||||
' table.insert(events, {...})',
|
||||
' end,',
|
||||
' })',
|
||||
' ```',
|
||||
'',
|
||||
'',
|
||||
' @see `nvim_buf_detach()`',
|
||||
' @see `api-buffer-updates-lua`',
|
||||
'',
|
||||
-- For each @param/@return: #30695
|
||||
-- - Separate each by one empty line.
|
||||
-- - Remove all other blank lines.
|
||||
'@*param* `buffer` — Buffer handle, or 0 for current buffer',
|
||||
'',
|
||||
'@*param* `send_buffer` — True if whole buffer.',
|
||||
' Else the first notification will be `nvim_buf_changedtick_event`.',
|
||||
'',
|
||||
'@*param* `opts` — Optional parameters.',
|
||||
' - on_lines: Lua callback. Args:',
|
||||
' - the string "lines"',
|
||||
' - buffer handle',
|
||||
' - b:changedtick',
|
||||
'',
|
||||
'@*return* — False if foo;',
|
||||
' otherwise True.',
|
||||
'@see foo',
|
||||
'@see bar',
|
||||
}
|
||||
eq(expected, r)
|
||||
end)
|
||||
|
||||
describe('_normalize_markdown', function()
|
||||
it('collapses consecutive blank lines', function()
|
||||
local result = exec_lua(function()
|
||||
local lines = {
|
||||
|
||||
Reference in New Issue
Block a user