From f7b573f80a33e7d6aba2d7a35a1a9f1a14a7ffca Mon Sep 17 00:00:00 2001 From: Sergei Slipchenko Date: Mon, 26 Jan 2026 17:26:50 +0400 Subject: [PATCH] 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. --- runtime/lua/vim/diagnostic.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 763f057df2..c1f5ff3832 100644 --- 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