forked from neovim/neovim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lsp): render markdown in docs hover neovim#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 neovim#22757 Signed-off-by: Kasama <robertoaall@gmail.com>
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
local helpers = require('test.functional.helpers')(after_each) | ||
|
||
local eq = helpers.eq | ||
local exec_lua = helpers.exec_lua | ||
|
||
describe('vim.lsp.util', function() | ||
before_each(helpers.clear) | ||
|
||
describe('stylize_markdown', function() | ||
local stylize_markdown = function(content, opts) | ||
return exec_lua([[ | ||
local bufnr = vim.uri_to_bufnr("file:///fake/uri") | ||
vim.fn.bufload(bufnr) | ||
local args = { ... } | ||
local content = args[1] | ||
local opts = args[2] | ||
local stripped_content = vim.lsp.util.stylize_markdown(bufnr, content, opts) | ||
return stripped_content | ||
]], content, opts) | ||
end | ||
|
||
it('code fences', function() | ||
local lines = { | ||
"```lua", | ||
"local hello = 'world'", | ||
"```", | ||
} | ||
local expected = { | ||
"local hello = 'world'", | ||
} | ||
local opts = {} | ||
eq(expected, stylize_markdown(lines, opts)) | ||
end) | ||
|
||
it('adds separator after code block', function() | ||
local lines = { | ||
"```lua", | ||
"local hello = 'world'", | ||
"```", | ||
"", | ||
"something", | ||
} | ||
local expected = { | ||
"local hello = 'world'", | ||
"─────────────────────", | ||
"something", | ||
} | ||
local opts = { separator = true } | ||
eq(expected, stylize_markdown(lines, opts)) | ||
end) | ||
|
||
it('replaces supported HTML entities', function() | ||
local lines = { | ||
"1 < 2", | ||
"3 > 2", | ||
""quoted"", | ||
"'apos'", | ||
"   ", | ||
"&", | ||
} | ||
local expected = { | ||
"1 < 2", | ||
"3 > 2", | ||
'"quoted"', | ||
"'apos'", | ||
" ", | ||
"&", | ||
} | ||
local opts = {} | ||
eq(expected, stylize_markdown(lines, opts)) | ||
end) | ||
end) | ||
end) |