fix(diagnostic): invalid col number compare in next_diagnostic (#28397)

Problem: when line is blank link then there will got an invalid column number in math.min compare.

Solution: make sure the min column number is 0 not an illegal number.
This commit is contained in:
Raphael
2024-04-28 05:05:41 +08:00
committed by GitHub
parent 158e329725
commit 96f59e1b99
2 changed files with 25 additions and 2 deletions

View File

@@ -867,14 +867,14 @@ local function next_diagnostic(position, search_forward, bufnr, opts, namespace)
return a.col < b.col
end
is_next = function(d)
return math.min(d.col, line_length - 1) > position[2]
return math.min(d.col, math.max(line_length - 1, 0)) > position[2]
end
else
sort_diagnostics = function(a, b)
return a.col > b.col
end
is_next = function(d)
return math.min(d.col, line_length - 1) < position[2]
return math.min(d.col, math.max(line_length - 1, 0)) < position[2]
end
end
table.sort(line_diagnostics[lnum], sort_diagnostics)