From b58ae8bdd7760d78ca9418ac4fd8618abbd1d630 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 23 Nov 2022 13:20:47 -0500 Subject: [PATCH] Clip diagnostic range before and during empty range expansion Co-Authored-By: Max Brunsfeld --- crates/language/src/buffer_tests.rs | 2 +- crates/language/src/diagnostic_set.rs | 4 ++-- crates/project/src/project.rs | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/language/src/buffer_tests.rs b/crates/language/src/buffer_tests.rs index 68fe8a2948..82641dbaa4 100644 --- a/crates/language/src/buffer_tests.rs +++ b/crates/language/src/buffer_tests.rs @@ -1337,7 +1337,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) { (0..entry_count).map(|_| { let range = buffer.random_byte_range(0, &mut rng); let range = range.to_point_utf16(buffer); - let range = Unclipped(range.start)..Unclipped(range.end); + let range = range.start..range.end; DiagnosticEntry { range, diagnostic: Diagnostic { diff --git a/crates/language/src/diagnostic_set.rs b/crates/language/src/diagnostic_set.rs index a4d6dc12c7..cde5a6fb2b 100644 --- a/crates/language/src/diagnostic_set.rs +++ b/crates/language/src/diagnostic_set.rs @@ -6,7 +6,7 @@ use std::{ ops::Range, }; use sum_tree::{self, Bias, SumTree}; -use text::{Anchor, FromAnchor, PointUtf16, ToOffset, Unclipped}; +use text::{Anchor, FromAnchor, PointUtf16, ToOffset}; #[derive(Clone, Debug, Default)] pub struct DiagnosticSet { @@ -63,7 +63,7 @@ impl DiagnosticSet { pub fn new(iter: I, buffer: &text::BufferSnapshot) -> Self where - I: IntoIterator>>, + I: IntoIterator>, { let mut entries = iter.into_iter().collect::>(); entries.sort_unstable_by_key(|entry| (entry.range.start, Reverse(entry.range.end))); diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index f4752270de..432d13076f 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2677,14 +2677,17 @@ impl Project { end = entry.range.end; } - let mut range = start..end; + let mut range = snapshot.clip_point_utf16(start, Bias::Left) + ..snapshot.clip_point_utf16(end, Bias::Right); // Expand empty ranges by one codepoint if range.start == range.end { // This will be go to the next boundary when being clipped - range.end.0.column += 1; - if range.start == range.end && range.end.0.column > 0 { - range.start.0.column -= 1; + range.end.column += 1; + range.end = snapshot.clip_point_utf16(Unclipped(range.end), Bias::Right); + if range.start == range.end && range.end.column > 0 { + range.start.column -= 1; + range.end = snapshot.clip_point_utf16(Unclipped(range.end), Bias::Left); } }