Skip to content

Commit

Permalink
fix(lsp): renderDiagnostic and explainError stop searching early
Browse files Browse the repository at this point in the history
Cursor positions are (1,0)-indexed but recursively searching was using
the previous diagnostic's position directly, which is (0,0)-indexed.
This meant that if the first examined diagnostic did not have a
diagnostic code or a rendered error we would search from the previous
line and immediately look at the current diagnostic again. So we would
fallback to the first possible error/diagnostic, even if there was one
further in the file that could be used instead.

We now convert the diagnostic position back into a cursor position (just
increment the line number) before getting the next diagnostic so we
continue the search from the correct place.
  • Loading branch information
LukeFranceschini authored and mrcjkb committed Apr 26, 2024
1 parent ab34cd8 commit 7b78743
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lua/rustaceanvim/commands/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ function M.explain_error()
found = diagnostic.code ~= nil and diagnostic.source == 'rustc'
local pos = { diagnostic.lnum, diagnostic.col }
pos_id = pos[1] + pos[2]
opts.cursor_position = pos
-- diagnostics are (0,0)-indexed but cursors are (1,0)-indexed
opts.cursor_position = { pos[1] + 1, pos[2] }
local searched_all = pos_map[pos_id] ~= nil
until diagnostic == nil or found or searched_all
if not found then
Expand Down Expand Up @@ -181,7 +182,8 @@ function M.render_diagnostic()
rendered_diagnostic = get_rendered_diagnostic(diagnostic)
local pos = { diagnostic.lnum, diagnostic.col }
pos_id = pos[1] + pos[2]
opts.cursor_position = pos
-- diagnostics are (0,0)-indexed but cursors are (1,0)-indexed
opts.cursor_position = { pos[1] + 1, pos[2] }
local searched_all = pos_map[pos_id] ~= nil
until diagnostic == nil or rendered_diagnostic ~= nil or searched_all
if not rendered_diagnostic then
Expand Down

0 comments on commit 7b78743

Please sign in to comment.