fix(diagnostic): handle stale diagnostic extmark ids #38060

Problem:
If a server is slow with catching up, there can be stale diagnostics
for deleted lines. Then if a user uses `jump` it can error like:

    E5108: Lua: ...runtime/lua/vim/diagnostic.lua:670: attempt to index a nil value
    stack traceback:
            ...runtime/lua/vim/diagnostic.lua:670: in function 'get_logical_pos'
            ...runtime/lua/vim/diagnostic.lua:687: in function 'diagnostic_lines'
            ...runtime/lua/vim/diagnostic.lua:1122: in function 'next_diagnostic'
            ...runtime/lua/vim/diagnostic.lua:1665: in function 'jump'

Solution:
Fallback to diagnostic location. That's better than the failure.
This commit is contained in:
Mathias Fußenegger authored and GitHub committed 2026-02-25 13:26:56 -05:00
1 parent 4ef217e272
commit 583308f599
1 file changed
+3 -1
+3 -1
View File
@@ -666,7 +666,9 @@ local function get_logical_pos(diagnostic)
diagnostic._extmark_id,
{ details = true }
)
if next(extmark) == nil then
return diagnostic.lnum, diagnostic.col, diagnostic.end_lnum, diagnostic.end_col, true
end
return extmark[1], extmark[2], extmark[3].end_row, extmark[3].end_col, not extmark[3].invalid
end