Skip to content

Commit

Permalink
fix(lsp): renderDiagnostic and explainError hash collisions
Browse files Browse the repository at this point in the history
The list of positions we've visited so far was hashed as line number +
column number which meant that if a diagnostic was at line 9, column 16
it would conflict with one at line 21, column 4, for example. This would
result in diagnostics later in the file being skipped even if they were
closer to where the cursor was.

We now hash the list with 1000 * line number + column number so that a
conflict is only possible if a diagnostic is at column 1000 or more.
Conflicts are still technically possible, but this was faster to
implement than a full solution which would store the exact cursor
position for each diagnostic visited so far.
  • Loading branch information
LukeFranceschini authored and mrcjkb committed Apr 26, 2024
1 parent db303a4 commit c81f036
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/rustaceanvim/commands/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function M.explain_error()
break
end
end
pos_id = pos[1] + pos[2]
pos_id = pos[1] * 1000 + pos[2]
-- 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
Expand Down Expand Up @@ -203,7 +203,7 @@ function M.render_diagnostic()
break
end
end
pos_id = pos[1] + pos[2]
pos_id = pos[1] * 1000 + pos[2]
-- 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
Expand Down

0 comments on commit c81f036

Please sign in to comment.