Skip to content

Commit

Permalink
feat(docs/hover): add support for some html escape sequences
Browse files Browse the repository at this point in the history
Implements neovim#22757

During handling of textDocument/hover, if the language server returns a
payload containing markdown with some html escape sequences, the neovim
handler will convert common ones to characters to display in the
floating window's buffer.

Signed-off-by: Kasama <robertoaall@gmail.com>
  • Loading branch information
Kasama committed Mar 23, 2023
1 parent 3875b1f commit 9cafcec
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions runtime/lua/vim/lsp/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,21 @@ function M.stylize_markdown(bufnr, contents, opts)
end
end

-- Handle some common html escape sequences
stripped = vim.tbl_map(
function(line)
line = string.gsub(line, '&gt;', '>')
line = string.gsub(line, '&lt;', '<')
line = string.gsub(line, '&quot;', '"')
line = string.gsub(line, '&apos;', "'")
line = string.gsub(line, '&ensp;', ' ')
line = string.gsub(line, '&emsp;', ' ')
line = string.gsub(line, '&amp;', '&')
return line
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)
Expand Down

0 comments on commit 9cafcec

Please sign in to comment.