diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 69a4d1235f..61a2e6c9c1 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -278,8 +278,7 @@ impl ProjectDiagnosticsEditor { prev_excerpt_id = excerpt_id.clone(); first_excerpt_id.get_or_insert_with(|| prev_excerpt_id.clone()); group_state.excerpts.push(excerpt_id.clone()); - let header_position = - (excerpt_id.clone(), language::Anchor::build_min()); + let header_position = (excerpt_id.clone(), language::Anchor::MIN); if is_first_excerpt_for_group { is_first_excerpt_for_group = false; diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 1f825e175c..aee964ec56 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -491,7 +491,7 @@ mod tests { use super::*; use crate::{ movement, - test::{marked_text, marked_text_ranges}, + test::{marked_text_ranges}, }; use gpui::{color::Color, elements::*, test::observe, MutableAppContext}; use language::{Buffer, Language, LanguageConfig, RandomCharIter, SelectionGoal}; @@ -499,7 +499,6 @@ mod tests { use smol::stream::StreamExt; use std::{env, sync::Arc}; use theme::SyntaxTheme; - use unindent::Unindent; use util::test::sample_text; use Bias::*; diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 634851bd82..3fbdf7def1 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4,8 +4,6 @@ pub mod items; pub mod movement; mod multi_buffer; -pub mod repro; - #[cfg(test)] mod test; @@ -4422,13 +4420,7 @@ impl Editor { .into_iter() .flat_map(|(_, ranges)| ranges), ) - .collect::>(); - - let snapshot = this.buffer.read(cx).snapshot(cx); - let point_ranges = ranges - .iter() - .map(|range| range.to_point(&snapshot)) - .collect::>(); + .collect(); this.highlight_text::( ranges, diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 398f7da99e..de735dafa7 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -211,11 +211,7 @@ impl MultiBuffer { pub fn singleton(buffer: ModelHandle, cx: &mut ModelContext) -> Self { let mut this = Self::new(buffer.read(cx).replica_id()); this.singleton = true; - this.push_excerpts( - buffer, - [text::Anchor::build_min()..text::Anchor::build_max()], - cx, - ); + this.push_excerpts(buffer, [text::Anchor::MIN..text::Anchor::MAX], cx); this.snapshot.borrow_mut().singleton = true; this } diff --git a/crates/editor/src/multi_buffer/anchor.rs b/crates/editor/src/multi_buffer/anchor.rs index 847a38f500..aeaf184c60 100644 --- a/crates/editor/src/multi_buffer/anchor.rs +++ b/crates/editor/src/multi_buffer/anchor.rs @@ -19,7 +19,7 @@ impl Anchor { Self { buffer_id: None, excerpt_id: ExcerptId::min(), - text_anchor: text::Anchor::build_min(), + text_anchor: text::Anchor::MIN, } } @@ -27,7 +27,7 @@ impl Anchor { Self { buffer_id: None, excerpt_id: ExcerptId::max(), - text_anchor: text::Anchor::build_max(), + text_anchor: text::Anchor::MAX, } } diff --git a/crates/editor/src/repro.rs b/crates/editor/src/repro.rs deleted file mode 100644 index 0dfa9ecbfc..0000000000 --- a/crates/editor/src/repro.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn test(complicated: i32, test: i32) { - complicated; - test; - // 1 - // 2 - // 3 - complicated; - test; -} diff --git a/crates/language/src/diagnostic_set.rs b/crates/language/src/diagnostic_set.rs index 017f117bbe..28b03b5aa0 100644 --- a/crates/language/src/diagnostic_set.rs +++ b/crates/language/src/diagnostic_set.rs @@ -187,10 +187,10 @@ impl DiagnosticEntry { impl Default for Summary { fn default() -> Self { Self { - start: Anchor::build_min(), - end: Anchor::build_max(), - min_start: Anchor::build_max(), - max_end: Anchor::build_min(), + start: Anchor::MIN, + end: Anchor::MAX, + min_start: Anchor::MAX, + max_end: Anchor::MIN, count: 0, } } diff --git a/crates/language/src/tests.rs b/crates/language/src/tests.rs index 3dbe8508a5..7eff3b0d97 100644 --- a/crates/language/src/tests.rs +++ b/crates/language/src/tests.rs @@ -789,7 +789,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) { for buffer in &buffers { let buffer = buffer.read(cx).snapshot(); let actual_remote_selections = buffer - .remote_selections_in_range(Anchor::build_min()..Anchor::build_max()) + .remote_selections_in_range(Anchor::MIN..Anchor::MAX) .map(|(replica_id, selections)| (replica_id, selections.collect::>())) .collect::>(); let expected_remote_selections = active_selections diff --git a/crates/text/src/anchor.rs b/crates/text/src/anchor.rs index c7de6bc882..5438ecd51f 100644 --- a/crates/text/src/anchor.rs +++ b/crates/text/src/anchor.rs @@ -12,21 +12,17 @@ pub struct Anchor { } impl Anchor { - pub fn build_min() -> Self { - Self { - timestamp: clock::Local::MIN, - offset: usize::MIN, - bias: Bias::Left, - } - } + pub const MIN: Self = Self { + timestamp: clock::Local::MIN, + offset: usize::MIN, + bias: Bias::Left, + }; - pub fn build_max() -> Self { - Self { - timestamp: clock::Local::MAX, - offset: usize::MAX, - bias: Bias::Right, - } - } + pub const MAX: Self = Self { + timestamp: clock::Local::MAX, + offset: usize::MAX, + bias: Bias::Right, + }; pub fn cmp(&self, other: &Anchor, buffer: &BufferSnapshot) -> Result { let fragment_id_comparison = if self.timestamp == other.timestamp { diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs index 8cb9629d07..b811d08c04 100644 --- a/crates/text/src/text.rs +++ b/crates/text/src/text.rs @@ -1318,8 +1318,8 @@ impl Buffer { let mut futures = Vec::new(); for anchor in anchors { if !self.version.observed(anchor.timestamp) - && *anchor != Anchor::build_max() - && *anchor != Anchor::build_min() + && *anchor != Anchor::MAX + && *anchor != Anchor::MIN { let (tx, rx) = oneshot::channel(); self.edit_id_resolvers @@ -1638,9 +1638,9 @@ impl BufferSnapshot { let mut position = D::default(); anchors.map(move |anchor| { - if *anchor == Anchor::build_min() { + if *anchor == Anchor::MIN { return D::default(); - } else if *anchor == Anchor::build_max() { + } else if *anchor == Anchor::MAX { return D::from_text_summary(&self.visible_text.summary()); } @@ -1680,9 +1680,9 @@ impl BufferSnapshot { where D: TextDimension, { - if *anchor == Anchor::build_min() { + if *anchor == Anchor::MIN { D::default() - } else if *anchor == Anchor::build_max() { + } else if *anchor == Anchor::MAX { D::from_text_summary(&self.visible_text.summary()) } else { let anchor_key = InsertionFragmentKey { @@ -1718,9 +1718,9 @@ impl BufferSnapshot { } fn fragment_id_for_anchor(&self, anchor: &Anchor) -> &Locator { - if *anchor == Anchor::build_min() { + if *anchor == Anchor::MIN { &locator::MIN - } else if *anchor == Anchor::build_max() { + } else if *anchor == Anchor::MAX { &locator::MAX } else { let anchor_key = InsertionFragmentKey { @@ -1758,9 +1758,9 @@ impl BufferSnapshot { pub fn anchor_at(&self, position: T, bias: Bias) -> Anchor { let offset = position.to_offset(self); if bias == Bias::Left && offset == 0 { - Anchor::build_min() + Anchor::MIN } else if bias == Bias::Right && offset == self.len() { - Anchor::build_max() + Anchor::MAX } else { let mut fragment_cursor = self.fragments.cursor::(); fragment_cursor.seek(&offset, bias, &None); @@ -1775,9 +1775,7 @@ impl BufferSnapshot { } pub fn can_resolve(&self, anchor: &Anchor) -> bool { - *anchor == Anchor::build_min() - || *anchor == Anchor::build_max() - || self.version.observed(anchor.timestamp) + *anchor == Anchor::MIN || *anchor == Anchor::MAX || self.version.observed(anchor.timestamp) } pub fn clip_offset(&self, offset: usize, bias: Bias) -> usize { @@ -1799,7 +1797,7 @@ impl BufferSnapshot { where D: TextDimension + Ord, { - self.edits_since_in_range(since, Anchor::build_min()..Anchor::build_max()) + self.edits_since_in_range(since, Anchor::MIN..Anchor::MAX) } pub fn edited_ranges_for_transaction<'a, D>(