diff options
author | Roberto Pommella Alegro <robertoaall@gmail.com> | 2023-03-25 13:46:07 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-25 12:46:07 -0400 |
commit | 257d894d75bc583bb16f4dbe441907eb273d20ad (patch) | |
tree | 8d93aaea761308776789cb2e4b3156f751b0b30e /runtime/lua/vim/lsp/util.lua | |
parent | 74f05a152db1a6e5fc1e02fd8fbe61cf79e5aa59 (diff) | |
download | rneovim-257d894d75bc583bb16f4dbe441907eb273d20ad.tar.gz rneovim-257d894d75bc583bb16f4dbe441907eb273d20ad.tar.bz2 rneovim-257d894d75bc583bb16f4dbe441907eb273d20ad.zip |
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>
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 48faddfce1..ebde7af16c 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -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 = { + ['>'] = '>', + ['<'] = '<', + ['"'] = '"', + ['''] = "'", + [' '] = ' ', + [' '] = ' ', + ['&'] = '&', + } + 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) |