commit f7b573f80a33e7d6aba2d7a35a1a9f1a14a7ffca
parent e6d955cb2c93c71cd6a2b27b19792e0745fb6049
Author: Sergei Slipchenko <faergeek@gmail.com>
Date: Mon, 26 Jan 2026 17:26:50 +0400
fix(diagnostics): assert adjusted diagnostic position #37210
Problem:
During diagnostic position adjustment we may go out of bounds
when trying to get line's length. But it's not clear what kind of
input triggers that.
Solution:
Assert and print relevant input values.
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
@@ -1390,7 +1390,25 @@ function M.set(namespace, bufnr, diagnostics, opts)
-- avoid ending an extmark before start of the line
if end_col == 0 then
end_row = end_row - 1
- end_col = #lines[end_row + 1]
+
+ local end_line = lines[end_row + 1]
+
+ if not end_line then
+ error(
+ 'Failed to adjust diagnostic position to the end of a previous line. #lines in a buffer: '
+ .. #lines
+ .. ', lnum: '
+ .. diagnostic.lnum
+ .. ', col: '
+ .. diagnostic.col
+ .. ', end_lnum: '
+ .. diagnostic.end_lnum
+ .. ', end_col: '
+ .. diagnostic.end_col
+ )
+ end
+
+ end_col = #end_line
end
end