Replace Default trait bound with a zero function on Summary/Dimension (#17975)
This lets us provide a context when constructing the zero value. We need it so we can require anchors to be associated with a buffer id, which we're doing as part of simplifying the multibuffer API. Release Notes: - N/A Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
4d074fc737
commit
2e72fd210a
28 changed files with 706 additions and 349 deletions
|
@ -561,7 +561,7 @@ impl MultiBuffer {
|
|||
}
|
||||
let mut buffer_edits: HashMap<BufferId, Vec<BufferEdit>> = Default::default();
|
||||
let mut edited_excerpt_ids = Vec::new();
|
||||
let mut cursor = snapshot.excerpts.cursor::<usize>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<usize>(&());
|
||||
for (ix, (range, new_text)) in edits.enumerate() {
|
||||
let new_text: Arc<str> = new_text.into();
|
||||
let original_indent_column = original_indent_columns.get(ix).copied().unwrap_or(0);
|
||||
|
@ -841,7 +841,7 @@ impl MultiBuffer {
|
|||
let mut ranges = Vec::new();
|
||||
let snapshot = self.read(cx);
|
||||
let buffers = self.buffers.borrow();
|
||||
let mut cursor = snapshot.excerpts.cursor::<ExcerptSummary>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<ExcerptSummary>(&());
|
||||
|
||||
for (buffer_id, buffer_transaction) in &transaction.buffer_transactions {
|
||||
let Some(buffer_state) = buffers.get(buffer_id) else {
|
||||
|
@ -957,7 +957,7 @@ impl MultiBuffer {
|
|||
let mut selections_by_buffer: HashMap<BufferId, Vec<Selection<text::Anchor>>> =
|
||||
Default::default();
|
||||
let snapshot = self.read(cx);
|
||||
let mut cursor = snapshot.excerpts.cursor::<Option<&Locator>>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<Option<&Locator>>(&());
|
||||
for selection in selections {
|
||||
let start_locator = snapshot.excerpt_locator_for_id(selection.start.excerpt_id);
|
||||
let end_locator = snapshot.excerpt_locator_for_id(selection.end.excerpt_id);
|
||||
|
@ -1281,7 +1281,7 @@ impl MultiBuffer {
|
|||
|
||||
let mut prev_locator = snapshot.excerpt_locator_for_id(prev_excerpt_id).clone();
|
||||
let mut new_excerpt_ids = mem::take(&mut snapshot.excerpt_ids);
|
||||
let mut cursor = snapshot.excerpts.cursor::<Option<&Locator>>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<Option<&Locator>>(&());
|
||||
let mut new_excerpts = cursor.slice(&prev_locator, Bias::Right, &());
|
||||
prev_locator = cursor.start().unwrap_or(Locator::min_ref()).clone();
|
||||
|
||||
|
@ -1388,7 +1388,7 @@ impl MultiBuffer {
|
|||
let mut excerpts = Vec::new();
|
||||
let snapshot = self.read(cx);
|
||||
let buffers = self.buffers.borrow();
|
||||
let mut cursor = snapshot.excerpts.cursor::<Option<&Locator>>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<Option<&Locator>>(&());
|
||||
for locator in buffers
|
||||
.get(&buffer.read(cx).remote_id())
|
||||
.map(|state| &state.excerpts)
|
||||
|
@ -1432,7 +1432,7 @@ impl MultiBuffer {
|
|||
let snapshot = self.read(cx);
|
||||
let position = position.to_offset(&snapshot);
|
||||
|
||||
let mut cursor = snapshot.excerpts.cursor::<usize>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&position, Bias::Right, &());
|
||||
cursor
|
||||
.item()
|
||||
|
@ -1459,7 +1459,7 @@ impl MultiBuffer {
|
|||
) -> Option<(Model<Buffer>, usize, ExcerptId)> {
|
||||
let snapshot = self.read(cx);
|
||||
let offset = point.to_offset(&snapshot);
|
||||
let mut cursor = snapshot.excerpts.cursor::<usize>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
if cursor.item().is_none() {
|
||||
cursor.prev(&());
|
||||
|
@ -1482,7 +1482,7 @@ impl MultiBuffer {
|
|||
) -> Option<(Model<Buffer>, Point, ExcerptId)> {
|
||||
let snapshot = self.read(cx);
|
||||
let point = point.to_point(&snapshot);
|
||||
let mut cursor = snapshot.excerpts.cursor::<Point>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<Point>(&());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
if cursor.item().is_none() {
|
||||
cursor.prev(&());
|
||||
|
@ -1507,7 +1507,7 @@ impl MultiBuffer {
|
|||
let end = range.end.to_offset(&snapshot);
|
||||
|
||||
let mut result = Vec::new();
|
||||
let mut cursor = snapshot.excerpts.cursor::<usize>();
|
||||
let mut cursor = snapshot.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&start, Bias::Right, &());
|
||||
if cursor.item().is_none() {
|
||||
cursor.prev(&());
|
||||
|
@ -1546,8 +1546,8 @@ impl MultiBuffer {
|
|||
|
||||
let mut buffers = self.buffers.borrow_mut();
|
||||
let mut snapshot = self.snapshot.borrow_mut();
|
||||
let mut new_excerpts = SumTree::new();
|
||||
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, usize)>();
|
||||
let mut new_excerpts = SumTree::default();
|
||||
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, usize)>(&());
|
||||
let mut edits = Vec::new();
|
||||
let mut excerpt_ids = ids.iter().copied().peekable();
|
||||
|
||||
|
@ -1801,8 +1801,8 @@ impl MultiBuffer {
|
|||
let ids = ids.into_iter().collect::<Vec<_>>();
|
||||
let snapshot = self.snapshot(cx);
|
||||
let locators = snapshot.excerpt_locators_for_ids(ids.iter().copied());
|
||||
let mut new_excerpts = SumTree::new();
|
||||
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, usize)>();
|
||||
let mut new_excerpts = SumTree::default();
|
||||
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, usize)>(&());
|
||||
let mut edits = Vec::<Edit<usize>>::new();
|
||||
|
||||
for locator in &locators {
|
||||
|
@ -1927,8 +1927,8 @@ impl MultiBuffer {
|
|||
excerpts_to_edit.sort_unstable_by_key(|(locator, _, _)| *locator);
|
||||
|
||||
let mut edits = Vec::new();
|
||||
let mut new_excerpts = SumTree::new();
|
||||
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, usize)>();
|
||||
let mut new_excerpts = SumTree::default();
|
||||
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, usize)>(&());
|
||||
|
||||
for (locator, buffer, buffer_edited) in excerpts_to_edit {
|
||||
new_excerpts.append(cursor.slice(&Some(locator), Bias::Left, &()), &());
|
||||
|
@ -2230,7 +2230,7 @@ impl MultiBufferSnapshot {
|
|||
|
||||
pub fn reversed_chars_at<T: ToOffset>(&self, position: T) -> impl Iterator<Item = char> + '_ {
|
||||
let mut offset = position.to_offset(self);
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
let mut cursor = self.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&offset, Bias::Left, &());
|
||||
let mut excerpt_chunks = cursor.item().map(|excerpt| {
|
||||
let end_before_footer = cursor.start() + excerpt.text_summary.len;
|
||||
|
@ -2357,7 +2357,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.clip_offset(offset, bias);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
let mut cursor = self.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
let overshoot = if let Some(excerpt) = cursor.item() {
|
||||
let excerpt_start = excerpt.range.context.start.to_offset(&excerpt.buffer);
|
||||
|
@ -2376,7 +2376,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.clip_point(point, bias);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<Point>();
|
||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
let overshoot = if let Some(excerpt) = cursor.item() {
|
||||
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer);
|
||||
|
@ -2395,7 +2395,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.clip_offset_utf16(offset, bias);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<OffsetUtf16>();
|
||||
let mut cursor = self.excerpts.cursor::<OffsetUtf16>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
let overshoot = if let Some(excerpt) = cursor.item() {
|
||||
let excerpt_start = excerpt.range.context.start.to_offset_utf16(&excerpt.buffer);
|
||||
|
@ -2414,7 +2414,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.clip_point_utf16(point, bias);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<PointUtf16>();
|
||||
let mut cursor = self.excerpts.cursor::<PointUtf16>(&());
|
||||
cursor.seek(&point.0, Bias::Right, &());
|
||||
let overshoot = if let Some(excerpt) = cursor.item() {
|
||||
let excerpt_start = excerpt
|
||||
|
@ -2432,7 +2432,7 @@ impl MultiBufferSnapshot {
|
|||
|
||||
pub fn bytes_in_range<T: ToOffset>(&self, range: Range<T>) -> MultiBufferBytes {
|
||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let mut excerpts = self.excerpts.cursor::<usize>();
|
||||
let mut excerpts = self.excerpts.cursor::<usize>(&());
|
||||
excerpts.seek(&range.start, Bias::Right, &());
|
||||
|
||||
let mut chunk = &[][..];
|
||||
|
@ -2457,7 +2457,7 @@ impl MultiBufferSnapshot {
|
|||
range: Range<T>,
|
||||
) -> ReversedMultiBufferBytes {
|
||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let mut excerpts = self.excerpts.cursor::<usize>();
|
||||
let mut excerpts = self.excerpts.cursor::<usize>(&());
|
||||
excerpts.seek(&range.end, Bias::Left, &());
|
||||
|
||||
let mut chunk = &[][..];
|
||||
|
@ -2482,7 +2482,7 @@ impl MultiBufferSnapshot {
|
|||
pub fn buffer_rows(&self, start_row: MultiBufferRow) -> MultiBufferRows {
|
||||
let mut result = MultiBufferRows {
|
||||
buffer_row_range: 0..0,
|
||||
excerpts: self.excerpts.cursor(),
|
||||
excerpts: self.excerpts.cursor(&()),
|
||||
};
|
||||
result.seek(start_row);
|
||||
result
|
||||
|
@ -2492,7 +2492,7 @@ impl MultiBufferSnapshot {
|
|||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let mut chunks = MultiBufferChunks {
|
||||
range: range.clone(),
|
||||
excerpts: self.excerpts.cursor(),
|
||||
excerpts: self.excerpts.cursor(&()),
|
||||
excerpt_chunks: None,
|
||||
language_aware,
|
||||
};
|
||||
|
@ -2505,7 +2505,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.offset_to_point(offset);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(usize, Point)>();
|
||||
let mut cursor = self.excerpts.cursor::<(usize, Point)>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let (start_offset, start_point) = cursor.start();
|
||||
|
@ -2526,7 +2526,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.offset_to_point_utf16(offset);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(usize, PointUtf16)>();
|
||||
let mut cursor = self.excerpts.cursor::<(usize, PointUtf16)>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let (start_offset, start_point) = cursor.start();
|
||||
|
@ -2547,7 +2547,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.point_to_point_utf16(point);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(Point, PointUtf16)>();
|
||||
let mut cursor = self.excerpts.cursor::<(Point, PointUtf16)>(&());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let (start_offset, start_point) = cursor.start();
|
||||
|
@ -2569,7 +2569,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.point_to_offset(point);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(Point, usize)>();
|
||||
let mut cursor = self.excerpts.cursor::<(Point, usize)>(&());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let (start_point, start_offset) = cursor.start();
|
||||
|
@ -2590,7 +2590,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.offset_utf16_to_offset(offset_utf16);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(OffsetUtf16, usize)>();
|
||||
let mut cursor = self.excerpts.cursor::<(OffsetUtf16, usize)>(&());
|
||||
cursor.seek(&offset_utf16, Bias::Right, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let (start_offset_utf16, start_offset) = cursor.start();
|
||||
|
@ -2612,7 +2612,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.offset_to_offset_utf16(offset);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(usize, OffsetUtf16)>();
|
||||
let mut cursor = self.excerpts.cursor::<(usize, OffsetUtf16)>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let (start_offset, start_offset_utf16) = cursor.start();
|
||||
|
@ -2636,7 +2636,7 @@ impl MultiBufferSnapshot {
|
|||
return buffer.point_utf16_to_offset(point);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(PointUtf16, usize)>();
|
||||
let mut cursor = self.excerpts.cursor::<(PointUtf16, usize)>(&());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let (start_point, start_offset) = cursor.start();
|
||||
|
@ -2659,7 +2659,7 @@ impl MultiBufferSnapshot {
|
|||
point: T,
|
||||
) -> Option<(&BufferSnapshot, usize)> {
|
||||
let offset = point.to_offset(self);
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
let mut cursor = self.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
if cursor.item().is_none() {
|
||||
cursor.prev(&());
|
||||
|
@ -2680,7 +2680,7 @@ impl MultiBufferSnapshot {
|
|||
let mut result = BTreeMap::new();
|
||||
|
||||
let mut rows_for_excerpt = Vec::new();
|
||||
let mut cursor = self.excerpts.cursor::<Point>();
|
||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
||||
let mut rows = rows.into_iter().peekable();
|
||||
let mut prev_row = u32::MAX;
|
||||
let mut prev_language_indent_size = IndentSize::default();
|
||||
|
@ -2769,7 +2769,7 @@ impl MultiBufferSnapshot {
|
|||
&self,
|
||||
row: MultiBufferRow,
|
||||
) -> Option<(&BufferSnapshot, Range<Point>)> {
|
||||
let mut cursor = self.excerpts.cursor::<Point>();
|
||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
||||
let point = Point::new(row.0, 0);
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
if cursor.item().is_none() && *cursor.start() == point {
|
||||
|
@ -2803,9 +2803,9 @@ impl MultiBufferSnapshot {
|
|||
D: TextDimension,
|
||||
O: ToOffset,
|
||||
{
|
||||
let mut summary = D::default();
|
||||
let mut summary = D::zero(&());
|
||||
let mut range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
let mut cursor = self.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&range.start, Bias::Right, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let mut end_before_newline = cursor.end(&());
|
||||
|
@ -2856,7 +2856,7 @@ impl MultiBufferSnapshot {
|
|||
where
|
||||
D: TextDimension + Ord + Sub<D, Output = D>,
|
||||
{
|
||||
let mut cursor = self.excerpts.cursor::<ExcerptSummary>();
|
||||
let mut cursor = self.excerpts.cursor::<ExcerptSummary>(&());
|
||||
let locator = self.excerpt_locator_for_id(anchor.excerpt_id);
|
||||
|
||||
cursor.seek(locator, Bias::Left, &());
|
||||
|
@ -2894,7 +2894,7 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
let mut anchors = anchors.into_iter().peekable();
|
||||
let mut cursor = self.excerpts.cursor::<ExcerptSummary>();
|
||||
let mut cursor = self.excerpts.cursor::<ExcerptSummary>(&());
|
||||
let mut summaries = Vec::new();
|
||||
while let Some(anchor) = anchors.peek() {
|
||||
let excerpt_id = anchor.excerpt_id;
|
||||
|
@ -2949,7 +2949,7 @@ impl MultiBufferSnapshot {
|
|||
I: 'a + IntoIterator<Item = &'a Anchor>,
|
||||
{
|
||||
let mut anchors = anchors.into_iter().enumerate().peekable();
|
||||
let mut cursor = self.excerpts.cursor::<Option<&Locator>>();
|
||||
let mut cursor = self.excerpts.cursor::<Option<&Locator>>(&());
|
||||
cursor.next(&());
|
||||
|
||||
let mut result = Vec::new();
|
||||
|
@ -3064,7 +3064,7 @@ impl MultiBufferSnapshot {
|
|||
};
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(usize, Option<ExcerptId>)>();
|
||||
let mut cursor = self.excerpts.cursor::<(usize, Option<ExcerptId>)>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
if cursor.item().is_none() && offset == cursor.start().0 && bias == Bias::Left {
|
||||
cursor.prev(&());
|
||||
|
@ -3099,7 +3099,7 @@ impl MultiBufferSnapshot {
|
|||
text_anchor: text::Anchor,
|
||||
) -> Option<Anchor> {
|
||||
let locator = self.excerpt_locator_for_id(excerpt_id);
|
||||
let mut cursor = self.excerpts.cursor::<Option<&Locator>>();
|
||||
let mut cursor = self.excerpts.cursor::<Option<&Locator>>(&());
|
||||
cursor.seek(locator, Bias::Left, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
if excerpt.id == excerpt_id {
|
||||
|
@ -3139,7 +3139,7 @@ impl MultiBufferSnapshot {
|
|||
) -> impl Iterator<Item = (&Excerpt, usize)> + '_ {
|
||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
let mut cursor = self.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&range.start, Bias::Right, &());
|
||||
cursor.prev(&());
|
||||
|
||||
|
@ -3183,7 +3183,7 @@ impl MultiBufferSnapshot {
|
|||
};
|
||||
let bounds = (start, end);
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(usize, Point)>();
|
||||
let mut cursor = self.excerpts.cursor::<(usize, Point)>(&());
|
||||
cursor.seek(&start_offset, Bias::Right, &());
|
||||
if cursor.item().is_none() {
|
||||
cursor.prev(&());
|
||||
|
@ -3550,7 +3550,7 @@ impl MultiBufferSnapshot {
|
|||
&self,
|
||||
row_range: Range<MultiBufferRow>,
|
||||
) -> impl Iterator<Item = DiffHunk<MultiBufferRow>> + '_ {
|
||||
let mut cursor = self.excerpts.cursor::<Point>();
|
||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
||||
|
||||
cursor.seek(&Point::new(row_range.end.0, 0), Bias::Left, &());
|
||||
if cursor.item().is_none() {
|
||||
|
@ -3617,7 +3617,7 @@ impl MultiBufferSnapshot {
|
|||
&self,
|
||||
row_range: Range<MultiBufferRow>,
|
||||
) -> impl Iterator<Item = DiffHunk<MultiBufferRow>> + '_ {
|
||||
let mut cursor = self.excerpts.cursor::<Point>();
|
||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
||||
|
||||
cursor.seek(&Point::new(row_range.start.0, 0), Bias::Left, &());
|
||||
|
||||
|
@ -3779,7 +3779,7 @@ impl MultiBufferSnapshot {
|
|||
} else if id == ExcerptId::max() {
|
||||
Locator::max_ref()
|
||||
} else {
|
||||
let mut cursor = self.excerpt_ids.cursor::<ExcerptId>();
|
||||
let mut cursor = self.excerpt_ids.cursor::<ExcerptId>(&());
|
||||
cursor.seek(&id, Bias::Left, &());
|
||||
if let Some(entry) = cursor.item() {
|
||||
if entry.id == id {
|
||||
|
@ -3814,7 +3814,7 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpt_ids.cursor::<ExcerptId>();
|
||||
let mut cursor = self.excerpt_ids.cursor::<ExcerptId>(&());
|
||||
for id in sorted_ids {
|
||||
if cursor.seek_forward(&id, Bias::Left, &()) {
|
||||
locators.push(cursor.item().unwrap().locator.clone());
|
||||
|
@ -3839,7 +3839,7 @@ impl MultiBufferSnapshot {
|
|||
&'a self,
|
||||
excerpt_id: ExcerptId,
|
||||
) -> Option<Range<T>> {
|
||||
let mut cursor = self.excerpts.cursor::<(Option<&Locator>, T)>();
|
||||
let mut cursor = self.excerpts.cursor::<(Option<&Locator>, T)>(&());
|
||||
let locator = self.excerpt_locator_for_id(excerpt_id);
|
||||
if cursor.seek(&Some(locator), Bias::Left, &()) {
|
||||
let start = cursor.start().1.clone();
|
||||
|
@ -3851,7 +3851,7 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
fn excerpt(&self, excerpt_id: ExcerptId) -> Option<&Excerpt> {
|
||||
let mut cursor = self.excerpts.cursor::<Option<&Locator>>();
|
||||
let mut cursor = self.excerpts.cursor::<Option<&Locator>>(&());
|
||||
let locator = self.excerpt_locator_for_id(excerpt_id);
|
||||
cursor.seek(&Some(locator), Bias::Left, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
|
@ -3866,7 +3866,7 @@ impl MultiBufferSnapshot {
|
|||
pub fn excerpt_containing<T: ToOffset>(&self, range: Range<T>) -> Option<MultiBufferExcerpt> {
|
||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
let mut cursor = self.excerpts.cursor::<usize>(&());
|
||||
cursor.seek(&range.start, Bias::Right, &());
|
||||
let start_excerpt = cursor.item()?;
|
||||
|
||||
|
@ -3891,7 +3891,7 @@ impl MultiBufferSnapshot {
|
|||
I: IntoIterator<Item = Range<Anchor>> + 'a,
|
||||
{
|
||||
let mut ranges = ranges.into_iter().map(|range| range.to_offset(self));
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
let mut cursor = self.excerpts.cursor::<usize>(&());
|
||||
cursor.next(&());
|
||||
let mut current_range = ranges.next();
|
||||
iter::from_fn(move || {
|
||||
|
@ -3943,7 +3943,7 @@ impl MultiBufferSnapshot {
|
|||
ranges: impl IntoIterator<Item = Range<Anchor>>,
|
||||
) -> impl Iterator<Item = (ExcerptId, &BufferSnapshot, Range<usize>)> {
|
||||
let mut ranges = ranges.into_iter().map(|range| range.to_offset(self));
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
let mut cursor = self.excerpts.cursor::<usize>(&());
|
||||
cursor.next(&());
|
||||
let mut current_range = ranges.next();
|
||||
iter::from_fn(move || {
|
||||
|
@ -3980,7 +3980,7 @@ impl MultiBufferSnapshot {
|
|||
range: &'a Range<Anchor>,
|
||||
include_local: bool,
|
||||
) -> impl 'a + Iterator<Item = (ReplicaId, bool, CursorShape, Selection<Anchor>)> {
|
||||
let mut cursor = self.excerpts.cursor::<ExcerptSummary>();
|
||||
let mut cursor = self.excerpts.cursor::<ExcerptSummary>(&());
|
||||
let start_locator = self.excerpt_locator_for_id(range.start.excerpt_id);
|
||||
let end_locator = self.excerpt_locator_for_id(range.end.excerpt_id);
|
||||
cursor.seek(start_locator, Bias::Left, &());
|
||||
|
@ -4519,6 +4519,10 @@ impl sum_tree::KeyedItem for ExcerptIdMapping {
|
|||
impl sum_tree::Summary for ExcerptId {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, other: &Self, _: &()) {
|
||||
*self = *other;
|
||||
}
|
||||
|
@ -4527,6 +4531,10 @@ impl sum_tree::Summary for ExcerptId {
|
|||
impl sum_tree::Summary for ExcerptSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &Self, _: &()) {
|
||||
debug_assert!(summary.excerpt_locator > self.excerpt_locator);
|
||||
self.excerpt_locator = summary.excerpt_locator.clone();
|
||||
|
@ -4536,12 +4544,20 @@ impl sum_tree::Summary for ExcerptSummary {
|
|||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for TextSummary {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ExcerptSummary, _: &()) {
|
||||
*self += &summary.text;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for usize {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ExcerptSummary, _: &()) {
|
||||
*self += summary.text.len;
|
||||
}
|
||||
|
@ -4566,30 +4582,50 @@ impl<'a> sum_tree::SeekTarget<'a, ExcerptSummary, ExcerptSummary> for Locator {
|
|||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for OffsetUtf16 {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ExcerptSummary, _: &()) {
|
||||
*self += summary.text.len_utf16;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for Point {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ExcerptSummary, _: &()) {
|
||||
*self += summary.text.lines;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for PointUtf16 {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ExcerptSummary, _: &()) {
|
||||
*self += summary.text.lines_utf16()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for Option<&'a Locator> {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ExcerptSummary, _: &()) {
|
||||
*self = Some(&summary.excerpt_locator);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for Option<ExcerptId> {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ExcerptSummary, _: &()) {
|
||||
*self = Some(summary.excerpt_id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue