mirror of
https://github.com/neovim/neovim.git
synced 2024-12-25 05:35:10 -07:00
fix(lsp): prevent duplicate lines seperated by newlines (#15284)
This commit is contained in:
parent
f22326ef09
commit
e7bde44d6d
@ -1160,6 +1160,8 @@ function M.stylize_markdown(bufnr, contents, opts)
|
|||||||
-- Clean up
|
-- Clean up
|
||||||
contents = M._trim(contents, opts)
|
contents = M._trim(contents, opts)
|
||||||
|
|
||||||
|
-- Insert blank line separator after code block?
|
||||||
|
local add_sep = opts.separator == nil and true or opts.separator
|
||||||
local stripped = {}
|
local stripped = {}
|
||||||
local highlights = {}
|
local highlights = {}
|
||||||
-- keep track of lnums that contain markdown
|
-- keep track of lnums that contain markdown
|
||||||
@ -1186,9 +1188,24 @@ function M.stylize_markdown(bufnr, contents, opts)
|
|||||||
start = start + 1;
|
start = start + 1;
|
||||||
finish = #stripped;
|
finish = #stripped;
|
||||||
})
|
})
|
||||||
|
-- add a separator, but not on the last line
|
||||||
|
if add_sep and i < #contents then
|
||||||
|
table.insert(stripped, "---")
|
||||||
|
markdown_lines[#stripped] = true
|
||||||
|
end
|
||||||
else
|
else
|
||||||
table.insert(stripped, line)
|
-- strip any emty lines or separators prior to this separator in actual markdown
|
||||||
markdown_lines[#stripped] = true
|
if line:match("^---+$") then
|
||||||
|
while markdown_lines[#stripped] and (stripped[#stripped]:match("^%s*$") or stripped[#stripped]:match("^---+$")) do
|
||||||
|
markdown_lines[#stripped] = false
|
||||||
|
table.remove(stripped, #stripped)
|
||||||
|
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("^---+$")) then
|
||||||
|
table.insert(stripped, line)
|
||||||
|
markdown_lines[#stripped] = true
|
||||||
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1196,7 +1213,7 @@ function M.stylize_markdown(bufnr, contents, opts)
|
|||||||
|
|
||||||
-- Compute size of float needed to show (wrapped) lines
|
-- 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))
|
opts.wrap_at = opts.wrap_at or (vim.wo["wrap"] and api.nvim_win_get_width(0))
|
||||||
local width, height = M._make_floating_popup_size(stripped, opts)
|
local width = M._make_floating_popup_size(stripped, opts)
|
||||||
|
|
||||||
local sep_line = string.rep("─", math.min(width, opts.wrap_at or width))
|
local sep_line = string.rep("─", math.min(width, opts.wrap_at or width))
|
||||||
|
|
||||||
@ -1206,26 +1223,6 @@ function M.stylize_markdown(bufnr, contents, opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Insert blank line separator after code block
|
|
||||||
local insert_separator = opts.separator
|
|
||||||
if insert_separator == nil then insert_separator = true end
|
|
||||||
if insert_separator then
|
|
||||||
local offset = 0
|
|
||||||
for _, h in ipairs(highlights) do
|
|
||||||
h.start = h.start + offset
|
|
||||||
h.finish = h.finish + offset
|
|
||||||
-- check if a seperator already exists and use that one instead of creating a new one
|
|
||||||
if h.finish + 1 <= #stripped then
|
|
||||||
if stripped[h.finish + 1] ~= sep_line then
|
|
||||||
table.insert(stripped, h.finish + 1, sep_line)
|
|
||||||
offset = offset + 1
|
|
||||||
height = height + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, stripped)
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, stripped)
|
||||||
|
|
||||||
local idx = 1
|
local idx = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user