diff options
Diffstat (limited to 'helix-view/src/document.rs')
-rw-r--r-- | helix-view/src/document.rs | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 37b8a0bf..b4971c8a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1213,20 +1213,32 @@ impl Document { let changes = transaction.changes(); - changes.update_positions( - self.diagnostics - .iter_mut() - .map(|diagnostic| (&mut diagnostic.range.start, Assoc::After)), - ); - changes.update_positions( - self.diagnostics - .iter_mut() - .map(|diagnostic| (&mut diagnostic.range.end, Assoc::After)), - ); - // map state.diagnostics over changes::map_pos too - for diagnostic in &mut self.diagnostics { + // map diagnostics over changes too + changes.update_positions(self.diagnostics.iter_mut().map(|diagnostic| { + let assoc = if diagnostic.starts_at_word { + Assoc::BeforeWord + } else { + Assoc::After + }; + (&mut diagnostic.range.start, assoc) + })); + changes.update_positions(self.diagnostics.iter_mut().map(|diagnostic| { + let assoc = if diagnostic.ends_at_word { + Assoc::AfterWord + } else { + Assoc::Before + }; + (&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) + { + return false; + } diagnostic.line = self.text.char_to_line(diagnostic.range.start); - } + true + }); self.diagnostics .sort_unstable_by_key(|diagnostic| diagnostic.range); |