feat(lsp): render markdown in docs hover #22766

Problem:
LSP docs hover (textDocument/hover) doesn't handle HTML escape seqs in markdown.

Solution:
Convert common HTML escape seqs to a nicer form, to display in the float.
closees #22757

Signed-off-by: Kasama <robertoaall@gmail.com>
This commit is contained in:
Roberto Pommella Alegro
2023-03-25 13:46:07 -03:00
committed by GitHub
parent 74f05a152d
commit 257d894d75
2 changed files with 89 additions and 0 deletions

View File

@@ -1378,6 +1378,20 @@ function M.stylize_markdown(bufnr, contents, opts)
end
end
-- Handle some common html escape sequences
stripped = vim.tbl_map(function(line)
local escapes = {
['&gt;'] = '>',
['&lt;'] = '<',
['&quot;'] = '"',
['&apos;'] = "'",
['&ensp;'] = ' ',
['&emsp;'] = ' ',
['&amp;'] = '&',
}
return (string.gsub(line, '&[^ ;]+;', escapes))
end, stripped)
-- Compute size of float needed to show (wrapped) lines
opts.wrap_at = opts.wrap_at or (vim.wo['wrap'] and api.nvim_win_get_width(0))
local width = M._make_floating_popup_size(stripped, opts)