mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
fix(diagnostic): check for negative column value (#18868)
This commit is contained in:
parent
4d9e2247c9
commit
94181ad7dc
@ -398,10 +398,19 @@ local function get_diagnostics(bufnr, opts, clamp)
|
||||
if not opts.lnum or d.lnum == opts.lnum then
|
||||
if clamp and vim.api.nvim_buf_is_loaded(b) then
|
||||
local line_count = buf_line_count[b] - 1
|
||||
if d.lnum > line_count or d.end_lnum > line_count or d.lnum < 0 or d.end_lnum < 0 then
|
||||
if
|
||||
d.lnum > line_count
|
||||
or d.end_lnum > line_count
|
||||
or d.lnum < 0
|
||||
or d.end_lnum < 0
|
||||
or d.col < 0
|
||||
or d.end_col < 0
|
||||
then
|
||||
d = vim.deepcopy(d)
|
||||
d.lnum = math.max(math.min(d.lnum, line_count), 0)
|
||||
d.end_lnum = math.max(math.min(d.end_lnum, line_count), 0)
|
||||
d.col = math.max(d.col, 0)
|
||||
d.end_col = math.max(d.end_col, 0)
|
||||
end
|
||||
end
|
||||
table.insert(diagnostics, d)
|
||||
|
@ -729,6 +729,19 @@ describe('vim.diagnostic', function()
|
||||
return vim.diagnostic.get_next_pos { namespace = diagnostic_ns }
|
||||
]])
|
||||
end)
|
||||
|
||||
it('works with diagnostics before the start of the line', function()
|
||||
eq({4, 0}, exec_lua [[
|
||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
|
||||
make_error('Diagnostic #1', 3, 9001, 3, 9001),
|
||||
make_error('Diagnostic #2', 4, -1, 4, -1),
|
||||
})
|
||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||
vim.api.nvim_win_set_cursor(0, {1, 1})
|
||||
vim.diagnostic.goto_next { float = false }
|
||||
return vim.diagnostic.get_next_pos { namespace = diagnostic_ns }
|
||||
]])
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('get_prev_pos()', function()
|
||||
|
Loading…
Reference in New Issue
Block a user