aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2025-04-02 11:24:38 +0100
committerLewis Russell <me@lewisr.dev>2025-04-04 14:33:50 +0100
commit379c37fa0b1be09cd46dd299638d94b9727fbaea (patch)
tree7ae1d8d7eecbc60327dafeda3710dd2e8b4c3104 /runtime/lua/vim/lsp/util.lua
parent98f5aa2564c38898d35519a1bb38dd1937c8c82e (diff)
downloadrneovim-379c37fa0b1be09cd46dd299638d94b9727fbaea.tar.gz
rneovim-379c37fa0b1be09cd46dd299638d94b9727fbaea.tar.bz2
rneovim-379c37fa0b1be09cd46dd299638d94b9727fbaea.zip
fix: bug in stylize_markdown
`stripped` and `markdown_lines` are iterated together so must have the same length.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua25
1 files changed, 8 insertions, 17 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index a069225e37..e18ff39b63 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -1138,10 +1138,8 @@ function M.stylize_markdown(bufnr, contents, opts)
-- Clean up
contents = vim.split(table.concat(contents, '\n'), '\n', { trimempty = true })
- local stripped = {}
+ local stripped = {} --- @type string[]
local highlights = {} --- @type {ft:string,start:integer,finish:integer}[]
- -- keep track of lnums that contain markdown
- local markdown_lines = {} --- @type table<integer,boolean>
local i = 1
while i <= #contents do
@@ -1156,7 +1154,7 @@ function M.stylize_markdown(bufnr, contents, opts)
i = i + 1
break
end
- table.insert(stripped, line)
+ stripped[#stripped + 1] = line
i = i + 1
end
table.insert(highlights, {
@@ -1166,30 +1164,23 @@ function M.stylize_markdown(bufnr, contents, opts)
})
-- add a separator, but not on the last line
if opts.separator and i < #contents then
- table.insert(stripped, '---')
- markdown_lines[#stripped] = true
+ stripped[#stripped + 1] = '---'
end
else
-- strip any empty lines or separators prior to this separator in actual markdown
if line:match('^---+$') then
while
- markdown_lines[#stripped]
+ stripped[#stripped]
and (stripped[#stripped]:match('^%s*$') or stripped[#stripped]:match('^---+$'))
do
- markdown_lines[#stripped] = false
- table.remove(stripped, #stripped)
+ stripped[#stripped] = nil
end
end
-- add the line if its not an empty line following a separator
if
- not (
- line:match('^%s*$')
- and markdown_lines[#stripped]
- and stripped[#stripped]:match('^---+$')
- )
+ not (line:match('^%s*$') and stripped[#stripped] and stripped[#stripped]:match('^---+$'))
then
- table.insert(stripped, line)
- markdown_lines[#stripped] = true
+ stripped[#stripped + 1] = line
end
i = i + 1
end
@@ -1220,7 +1211,7 @@ function M.stylize_markdown(bufnr, contents, opts)
local sep_line = string.rep('─', math.min(width, opts.wrap_at or width))
- for l in pairs(markdown_lines) do
+ for l in ipairs(stripped) do
if stripped[l]:match('^---+$') then
stripped[l] = sep_line
end