Skip to content

Commit

Permalink
don't automatically dismiss zero width diagnostics
Browse files Browse the repository at this point in the history
Normal diagnostics can be removed when all the text they cover has been removed.
This is not the case for zero width diagnostics as these are not attached to any
particular text. These diagnostics can not be automatically dismissed and must
be mapped as a point instead of as a range to avoid that.
  • Loading branch information
pascalkuthe committed Jan 8, 2024
1 parent 77ab792 commit 194618f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,18 +1222,23 @@ impl Document {
};
(&mut diagnostic.range.start, assoc)
}));
changes.update_positions(self.diagnostics.iter_mut().map(|diagnostic| {
changes.update_positions(self.diagnostics.iter_mut().filter_map(|diagnostic| {
if diagnostic.zero_width {
// for zero width diagnostics treat the diagnostic as a point
// rather than a range
return None;
}
let assoc = if diagnostic.ends_at_word {
Assoc::AfterWord
} else {
Assoc::Before
};
(&mut diagnostic.range.end, assoc)
Some((&mut diagnostic.range.end, assoc))
}));
self.diagnostics.retain_mut(|diagnostic| {
if diagnostic.range.start > diagnostic.range.end
|| (!diagnostic.zero_width && diagnostic.range.start == diagnostic.range.end)
{
if diagnostic.zero_width {
diagnostic.range.end = diagnostic.range.start
} else if diagnostic.range.start >= diagnostic.range.end {
return false;
}
diagnostic.line = self.text.char_to_line(diagnostic.range.start);
Expand Down

0 comments on commit 194618f

Please sign in to comment.