fix(diagnostics): fixed virtual_text cursormoved autocmd error (#34017)

This commit is contained in:
Rijul Kapoor
2025-05-22 01:20:37 +10:00
committed by GitHub
parent dd43eb445a
commit 19efabafc5
3 changed files with 50 additions and 13 deletions

View File

@@ -2204,6 +2204,31 @@ describe('vim.diagnostic', function()
eq(1, #result)
eq(' Another error there!', result[1][4].virt_text[3][1])
end)
it('only renders virtual_line diagnostics within buffer length', function()
local result = exec_lua(function()
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.diagnostic.config({ virtual_text = { current_line = false } })
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
_G.make_error('Hidden Error here!', 0, 0, 0, 0, 'foo_server'),
_G.make_error('First Error here!', 1, 0, 1, 0, 'foo_server'),
_G.make_error('Second Error here!', 2, 0, 2, 0, 'foo_server'),
_G.make_error('First Ignored Error here!', 3, 0, 3, 0, 'foo_server'),
_G.make_error('Second Ignored Error here!', 6, 0, 6, 0, 'foo_server'),
_G.make_error('Third Ignored Error here!', 8, 0, 8, 0, 'foo_server'),
})
vim.api.nvim_buf_set_lines(_G.diagnostic_bufnr, 2, 5, false, {})
vim.api.nvim_exec_autocmds('CursorMoved', { buffer = _G.diagnostic_bufnr })
return _G.get_virt_text_extmarks(_G.diagnostic_ns)
end)
eq(2, #result)
eq(' First Error here!', result[1][4].virt_text[3][1])
eq(' Second Error here!', result[2][4].virt_text[3][1])
end)
end)
describe('handlers.virtual_lines', function()