Change language::min() to a constant

Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Keith Simmons 2022-03-24 10:35:30 -07:00
parent f6805eb802
commit ab631cf6c3
10 changed files with 33 additions and 62 deletions

View file

@ -278,8 +278,7 @@ impl ProjectDiagnosticsEditor {
prev_excerpt_id = excerpt_id.clone(); prev_excerpt_id = excerpt_id.clone();
first_excerpt_id.get_or_insert_with(|| prev_excerpt_id.clone()); first_excerpt_id.get_or_insert_with(|| prev_excerpt_id.clone());
group_state.excerpts.push(excerpt_id.clone()); group_state.excerpts.push(excerpt_id.clone());
let header_position = let header_position = (excerpt_id.clone(), language::Anchor::MIN);
(excerpt_id.clone(), language::Anchor::build_min());
if is_first_excerpt_for_group { if is_first_excerpt_for_group {
is_first_excerpt_for_group = false; is_first_excerpt_for_group = false;

View file

@ -491,7 +491,7 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
movement, movement,
test::{marked_text, marked_text_ranges}, test::{marked_text_ranges},
}; };
use gpui::{color::Color, elements::*, test::observe, MutableAppContext}; use gpui::{color::Color, elements::*, test::observe, MutableAppContext};
use language::{Buffer, Language, LanguageConfig, RandomCharIter, SelectionGoal}; use language::{Buffer, Language, LanguageConfig, RandomCharIter, SelectionGoal};
@ -499,7 +499,6 @@ mod tests {
use smol::stream::StreamExt; use smol::stream::StreamExt;
use std::{env, sync::Arc}; use std::{env, sync::Arc};
use theme::SyntaxTheme; use theme::SyntaxTheme;
use unindent::Unindent;
use util::test::sample_text; use util::test::sample_text;
use Bias::*; use Bias::*;

View file

@ -4,8 +4,6 @@ pub mod items;
pub mod movement; pub mod movement;
mod multi_buffer; mod multi_buffer;
pub mod repro;
#[cfg(test)] #[cfg(test)]
mod test; mod test;
@ -4422,13 +4420,7 @@ impl Editor {
.into_iter() .into_iter()
.flat_map(|(_, ranges)| ranges), .flat_map(|(_, ranges)| ranges),
) )
.collect::<Vec<_>>(); .collect();
let snapshot = this.buffer.read(cx).snapshot(cx);
let point_ranges = ranges
.iter()
.map(|range| range.to_point(&snapshot))
.collect::<Vec<_>>();
this.highlight_text::<Rename>( this.highlight_text::<Rename>(
ranges, ranges,

View file

@ -211,11 +211,7 @@ impl MultiBuffer {
pub fn singleton(buffer: ModelHandle<Buffer>, cx: &mut ModelContext<Self>) -> Self { pub fn singleton(buffer: ModelHandle<Buffer>, cx: &mut ModelContext<Self>) -> Self {
let mut this = Self::new(buffer.read(cx).replica_id()); let mut this = Self::new(buffer.read(cx).replica_id());
this.singleton = true; this.singleton = true;
this.push_excerpts( this.push_excerpts(buffer, [text::Anchor::MIN..text::Anchor::MAX], cx);
buffer,
[text::Anchor::build_min()..text::Anchor::build_max()],
cx,
);
this.snapshot.borrow_mut().singleton = true; this.snapshot.borrow_mut().singleton = true;
this this
} }

View file

@ -19,7 +19,7 @@ impl Anchor {
Self { Self {
buffer_id: None, buffer_id: None,
excerpt_id: ExcerptId::min(), excerpt_id: ExcerptId::min(),
text_anchor: text::Anchor::build_min(), text_anchor: text::Anchor::MIN,
} }
} }
@ -27,7 +27,7 @@ impl Anchor {
Self { Self {
buffer_id: None, buffer_id: None,
excerpt_id: ExcerptId::max(), excerpt_id: ExcerptId::max(),
text_anchor: text::Anchor::build_max(), text_anchor: text::Anchor::MAX,
} }
} }

View file

@ -1,9 +0,0 @@
fn test(complicated: i32, test: i32) {
complicated;
test;
// 1
// 2
// 3
complicated;
test;
}

View file

@ -187,10 +187,10 @@ impl DiagnosticEntry<Anchor> {
impl Default for Summary { impl Default for Summary {
fn default() -> Self { fn default() -> Self {
Self { Self {
start: Anchor::build_min(), start: Anchor::MIN,
end: Anchor::build_max(), end: Anchor::MAX,
min_start: Anchor::build_max(), min_start: Anchor::MAX,
max_end: Anchor::build_min(), max_end: Anchor::MIN,
count: 0, count: 0,
} }
} }

View file

@ -789,7 +789,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) {
for buffer in &buffers { for buffer in &buffers {
let buffer = buffer.read(cx).snapshot(); let buffer = buffer.read(cx).snapshot();
let actual_remote_selections = buffer 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::<Vec<_>>())) .map(|(replica_id, selections)| (replica_id, selections.collect::<Vec<_>>()))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let expected_remote_selections = active_selections let expected_remote_selections = active_selections

View file

@ -12,21 +12,17 @@ pub struct Anchor {
} }
impl Anchor { impl Anchor {
pub fn build_min() -> Self { pub const MIN: Self = Self {
Self { timestamp: clock::Local::MIN,
timestamp: clock::Local::MIN, offset: usize::MIN,
offset: usize::MIN, bias: Bias::Left,
bias: Bias::Left, };
}
}
pub fn build_max() -> Self { pub const MAX: Self = Self {
Self { timestamp: clock::Local::MAX,
timestamp: clock::Local::MAX, offset: usize::MAX,
offset: usize::MAX, bias: Bias::Right,
bias: Bias::Right, };
}
}
pub fn cmp(&self, other: &Anchor, buffer: &BufferSnapshot) -> Result<Ordering> { pub fn cmp(&self, other: &Anchor, buffer: &BufferSnapshot) -> Result<Ordering> {
let fragment_id_comparison = if self.timestamp == other.timestamp { let fragment_id_comparison = if self.timestamp == other.timestamp {

View file

@ -1318,8 +1318,8 @@ impl Buffer {
let mut futures = Vec::new(); let mut futures = Vec::new();
for anchor in anchors { for anchor in anchors {
if !self.version.observed(anchor.timestamp) if !self.version.observed(anchor.timestamp)
&& *anchor != Anchor::build_max() && *anchor != Anchor::MAX
&& *anchor != Anchor::build_min() && *anchor != Anchor::MIN
{ {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
self.edit_id_resolvers self.edit_id_resolvers
@ -1638,9 +1638,9 @@ impl BufferSnapshot {
let mut position = D::default(); let mut position = D::default();
anchors.map(move |anchor| { anchors.map(move |anchor| {
if *anchor == Anchor::build_min() { if *anchor == Anchor::MIN {
return D::default(); return D::default();
} else if *anchor == Anchor::build_max() { } else if *anchor == Anchor::MAX {
return D::from_text_summary(&self.visible_text.summary()); return D::from_text_summary(&self.visible_text.summary());
} }
@ -1680,9 +1680,9 @@ impl BufferSnapshot {
where where
D: TextDimension, D: TextDimension,
{ {
if *anchor == Anchor::build_min() { if *anchor == Anchor::MIN {
D::default() D::default()
} else if *anchor == Anchor::build_max() { } else if *anchor == Anchor::MAX {
D::from_text_summary(&self.visible_text.summary()) D::from_text_summary(&self.visible_text.summary())
} else { } else {
let anchor_key = InsertionFragmentKey { let anchor_key = InsertionFragmentKey {
@ -1718,9 +1718,9 @@ impl BufferSnapshot {
} }
fn fragment_id_for_anchor(&self, anchor: &Anchor) -> &Locator { fn fragment_id_for_anchor(&self, anchor: &Anchor) -> &Locator {
if *anchor == Anchor::build_min() { if *anchor == Anchor::MIN {
&locator::MIN &locator::MIN
} else if *anchor == Anchor::build_max() { } else if *anchor == Anchor::MAX {
&locator::MAX &locator::MAX
} else { } else {
let anchor_key = InsertionFragmentKey { let anchor_key = InsertionFragmentKey {
@ -1758,9 +1758,9 @@ impl BufferSnapshot {
pub fn anchor_at<T: ToOffset>(&self, position: T, bias: Bias) -> Anchor { pub fn anchor_at<T: ToOffset>(&self, position: T, bias: Bias) -> Anchor {
let offset = position.to_offset(self); let offset = position.to_offset(self);
if bias == Bias::Left && offset == 0 { if bias == Bias::Left && offset == 0 {
Anchor::build_min() Anchor::MIN
} else if bias == Bias::Right && offset == self.len() { } else if bias == Bias::Right && offset == self.len() {
Anchor::build_max() Anchor::MAX
} else { } else {
let mut fragment_cursor = self.fragments.cursor::<usize>(); let mut fragment_cursor = self.fragments.cursor::<usize>();
fragment_cursor.seek(&offset, bias, &None); fragment_cursor.seek(&offset, bias, &None);
@ -1775,9 +1775,7 @@ impl BufferSnapshot {
} }
pub fn can_resolve(&self, anchor: &Anchor) -> bool { pub fn can_resolve(&self, anchor: &Anchor) -> bool {
*anchor == Anchor::build_min() *anchor == Anchor::MIN || *anchor == Anchor::MAX || self.version.observed(anchor.timestamp)
|| *anchor == Anchor::build_max()
|| self.version.observed(anchor.timestamp)
} }
pub fn clip_offset(&self, offset: usize, bias: Bias) -> usize { pub fn clip_offset(&self, offset: usize, bias: Bias) -> usize {
@ -1799,7 +1797,7 @@ impl BufferSnapshot {
where where
D: TextDimension + Ord, 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>( pub fn edited_ranges_for_transaction<'a, D>(