mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(lsp): restore diagnostics extmarks that were moved to the last edit line (#15023)
This commit is contained in:
parent
af263711a3
commit
03d15d9e09
@ -1042,16 +1042,17 @@ function M.on_publish_diagnostics(_, _, params, client_id, _, config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- restores the extmarks set by M.display
|
-- restores the extmarks set by M.display
|
||||||
|
--- @param last number last line that was changed
|
||||||
-- @private
|
-- @private
|
||||||
local function restore_extmarks(bufnr)
|
local function restore_extmarks(bufnr, last)
|
||||||
local lcount = api.nvim_buf_line_count(bufnr)
|
|
||||||
for client_id, extmarks in pairs(diagnostic_cache_extmarks[bufnr]) do
|
for client_id, extmarks in pairs(diagnostic_cache_extmarks[bufnr]) do
|
||||||
local ns = M._get_diagnostic_namespace(client_id)
|
local ns = M._get_diagnostic_namespace(client_id)
|
||||||
local extmarks_current = api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, {details = true})
|
local extmarks_current = api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, {details = true})
|
||||||
local found = {}
|
local found = {}
|
||||||
for _, extmark in ipairs(extmarks_current) do
|
for _, extmark in ipairs(extmarks_current) do
|
||||||
-- HACK: the missing extmarks seem to still exist, but at the line after the last
|
-- nvim_buf_set_lines will move any extmark to the line after the last
|
||||||
if extmark[2] < lcount then
|
-- nvim_buf_set_text will move any extmark to the last line
|
||||||
|
if extmark[2] ~= last + 1 then
|
||||||
found[extmark[1]] = true
|
found[extmark[1]] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1076,8 +1077,8 @@ local function save_extmarks(bufnr, client_id)
|
|||||||
bufnr = bufnr == 0 and api.nvim_get_current_buf() or bufnr
|
bufnr = bufnr == 0 and api.nvim_get_current_buf() or bufnr
|
||||||
if not diagnostic_attached_buffers[bufnr] then
|
if not diagnostic_attached_buffers[bufnr] then
|
||||||
api.nvim_buf_attach(bufnr, false, {
|
api.nvim_buf_attach(bufnr, false, {
|
||||||
on_lines = function()
|
on_lines = function(_, _, _, _, _, last)
|
||||||
restore_extmarks(bufnr)
|
restore_extmarks(bufnr, last - 1)
|
||||||
end,
|
end,
|
||||||
on_detach = function()
|
on_detach = function()
|
||||||
diagnostic_cache_extmarks[bufnr] = nil
|
diagnostic_cache_extmarks[bufnr] = nil
|
||||||
|
Loading…
Reference in New Issue
Block a user