From 84ce81caf155fefb60b1a26e44b14b1a28cfb2cd Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sun, 29 Sep 2024 10:30:48 -0600 Subject: [PATCH] Pass `Summary::Context` to `Item::summarize` (#18510) We are going to use this in the multi-buffer to produce a summary for an `Excerpt` that contains a `Range`. Release Notes: - N/A Co-authored-by: Nathan --- crates/channel/src/channel_chat.rs | 2 +- crates/editor/src/display_map/block_map.rs | 2 +- crates/editor/src/display_map/crease_map.rs | 2 +- crates/editor/src/display_map/fold_map.rs | 4 ++-- crates/editor/src/display_map/inlay_map.rs | 2 +- crates/editor/src/display_map/wrap_map.rs | 2 +- crates/editor/src/git/blame.rs | 2 +- crates/git/src/diff.rs | 2 +- crates/gpui/src/elements/list.rs | 2 +- crates/language/src/diagnostic_set.rs | 2 +- crates/language/src/syntax_map.rs | 2 +- crates/multi_buffer/src/multi_buffer.rs | 4 ++-- crates/notifications/src/notification_store.rs | 2 +- crates/rope/src/rope.rs | 2 +- crates/sum_tree/src/sum_tree.rs | 12 ++++++------ crates/sum_tree/src/tree_map.rs | 2 +- crates/text/src/locator.rs | 2 +- crates/text/src/operation_queue.rs | 2 +- crates/text/src/text.rs | 6 +++--- crates/text/src/undo_map.rs | 2 +- crates/worktree/src/worktree.rs | 4 ++-- 21 files changed, 31 insertions(+), 31 deletions(-) diff --git a/crates/channel/src/channel_chat.rs b/crates/channel/src/channel_chat.rs index 1a9e46db04..e5b5b74c16 100644 --- a/crates/channel/src/channel_chat.rs +++ b/crates/channel/src/channel_chat.rs @@ -808,7 +808,7 @@ pub fn mentions_to_proto(mentions: &[(Range, UserId)]) -> Vec Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { ChannelMessageSummary { max_id: self.id, count: 1, diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index efa026a56c..52e0ca2486 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -1360,7 +1360,7 @@ impl<'a> Iterator for BlockBufferRows<'a> { impl sum_tree::Item for Transform { type Summary = TransformSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { self.summary.clone() } } diff --git a/crates/editor/src/display_map/crease_map.rs b/crates/editor/src/display_map/crease_map.rs index c3f2b0061a..531c650c43 100644 --- a/crates/editor/src/display_map/crease_map.rs +++ b/crates/editor/src/display_map/crease_map.rs @@ -291,7 +291,7 @@ impl sum_tree::Summary for ItemSummary { impl sum_tree::Item for CreaseItem { type Summary = ItemSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &MultiBufferSnapshot) -> Self::Summary { ItemSummary { range: self.crease.range.clone(), } diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 37983030b8..5eb26ff969 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -944,7 +944,7 @@ struct TransformSummary { impl sum_tree::Item for Transform { type Summary = TransformSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { self.summary.clone() } } @@ -1004,7 +1004,7 @@ impl Default for FoldRange { impl sum_tree::Item for Fold { type Summary = FoldSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &MultiBufferSnapshot) -> Self::Summary { FoldSummary { start: self.range.start, end: self.range.end, diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index 712db45e3f..d4e39f2df9 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -74,7 +74,7 @@ impl Inlay { impl sum_tree::Item for Transform { type Summary = TransformSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { match self { Transform::Isomorphic(summary) => TransformSummary { input: summary.clone(), diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index 564bba2158..dc4d93058c 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -917,7 +917,7 @@ impl Transform { impl sum_tree::Item for Transform { type Summary = TransformSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { self.summary.clone() } } diff --git a/crates/editor/src/git/blame.rs b/crates/editor/src/git/blame.rs index 733d42d0c5..303ead16b2 100644 --- a/crates/editor/src/git/blame.rs +++ b/crates/editor/src/git/blame.rs @@ -29,7 +29,7 @@ pub struct GitBlameEntrySummary { impl sum_tree::Item for GitBlameEntry { type Summary = GitBlameEntrySummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { GitBlameEntrySummary { rows: self.rows } } } diff --git a/crates/git/src/diff.rs b/crates/git/src/diff.rs index 1f7930ce14..baad824577 100644 --- a/crates/git/src/diff.rs +++ b/crates/git/src/diff.rs @@ -34,7 +34,7 @@ struct InternalDiffHunk { impl sum_tree::Item for InternalDiffHunk { type Summary = DiffHunkSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &text::BufferSnapshot) -> Self::Summary { DiffHunkSummary { buffer_range: self.buffer_range.clone(), } diff --git a/crates/gpui/src/elements/list.rs b/crates/gpui/src/elements/list.rs index d03392867b..6ac6d2a9bf 100644 --- a/crates/gpui/src/elements/list.rs +++ b/crates/gpui/src/elements/list.rs @@ -858,7 +858,7 @@ impl Styled for List { impl sum_tree::Item for ListItem { type Summary = ListItemSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _: &()) -> Self::Summary { match self { ListItem::Unmeasured { focus_handle } => ListItemSummary { count: 1, diff --git a/crates/language/src/diagnostic_set.rs b/crates/language/src/diagnostic_set.rs index c35659d9bb..38d4216bee 100644 --- a/crates/language/src/diagnostic_set.rs +++ b/crates/language/src/diagnostic_set.rs @@ -224,7 +224,7 @@ impl DiagnosticSet { impl sum_tree::Item for DiagnosticEntry { type Summary = Summary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &text::BufferSnapshot) -> Self::Summary { Summary { start: self.range.start, end: self.range.end, diff --git a/crates/language/src/syntax_map.rs b/crates/language/src/syntax_map.rs index 55177f7962..8617696cc4 100644 --- a/crates/language/src/syntax_map.rs +++ b/crates/language/src/syntax_map.rs @@ -1739,7 +1739,7 @@ impl<'a> SeekTarget<'a, SyntaxLayerSummary, SyntaxLayerSummary> impl sum_tree::Item for SyntaxLayerEntry { type Summary = SyntaxLayerSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &BufferSnapshot) -> Self::Summary { SyntaxLayerSummary { min_depth: self.depth, max_depth: self.depth, diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 828b39967d..7aa733ba8f 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -4596,7 +4596,7 @@ impl fmt::Debug for Excerpt { impl sum_tree::Item for Excerpt { type Summary = ExcerptSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { let mut text = self.text_summary.clone(); if self.has_trailing_newline { text += TextSummary::from("\n"); @@ -4613,7 +4613,7 @@ impl sum_tree::Item for Excerpt { impl sum_tree::Item for ExcerptIdMapping { type Summary = ExcerptId; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { self.id } } diff --git a/crates/notifications/src/notification_store.rs b/crates/notifications/src/notification_store.rs index 48fcb5dfbb..5c3de53ee1 100644 --- a/crates/notifications/src/notification_store.rs +++ b/crates/notifications/src/notification_store.rs @@ -455,7 +455,7 @@ impl EventEmitter for NotificationStore {} impl sum_tree::Item for NotificationEntry { type Summary = NotificationSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { NotificationSummary { max_id: self.id, count: 1, diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rs index 56fe7fc054..68ff7d5c69 100644 --- a/crates/rope/src/rope.rs +++ b/crates/rope/src/rope.rs @@ -1159,7 +1159,7 @@ impl Chunk { impl sum_tree::Item for Chunk { type Summary = ChunkSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { ChunkSummary::from(self.0.as_str()) } } diff --git a/crates/sum_tree/src/sum_tree.rs b/crates/sum_tree/src/sum_tree.rs index 7013dc66fd..fbfe3b06f3 100644 --- a/crates/sum_tree/src/sum_tree.rs +++ b/crates/sum_tree/src/sum_tree.rs @@ -20,7 +20,7 @@ pub const TREE_BASE: usize = 6; pub trait Item: Clone { type Summary: Summary; - fn summary(&self) -> Self::Summary; + fn summary(&self, cx: &::Context) -> Self::Summary; } /// An [`Item`] whose summary has a specific key that can be used to identify it @@ -211,7 +211,7 @@ impl SumTree { while iter.peek().is_some() { let items: ArrayVec = iter.by_ref().take(2 * TREE_BASE).collect(); let item_summaries: ArrayVec = - items.iter().map(|item| item.summary()).collect(); + items.iter().map(|item| item.summary(cx)).collect(); let mut summary = item_summaries[0].clone(); for item_summary in &item_summaries[1..] { @@ -281,7 +281,7 @@ impl SumTree { .map(|items| { let items: ArrayVec = items.into_iter().collect(); let item_summaries: ArrayVec = - items.iter().map(|item| item.summary()).collect(); + items.iter().map(|item| item.summary(cx)).collect(); let mut summary = item_summaries[0].clone(); for item_summary in &item_summaries[1..] { ::add_summary(&mut summary, item_summary, cx); @@ -405,7 +405,7 @@ impl SumTree { if let Some((item, item_summary)) = items.last_mut().zip(item_summaries.last_mut()) { (f)(item); - *item_summary = item.summary(); + *item_summary = item.summary(cx); *summary = sum(item_summaries.iter(), cx); Some(summary.clone()) } else { @@ -461,7 +461,7 @@ impl SumTree { } pub fn push(&mut self, item: T, cx: &::Context) { - let summary = item.summary(); + let summary = item.summary(cx); self.append( SumTree(Arc::new(Node::Leaf { summary: summary.clone(), @@ -1352,7 +1352,7 @@ mod tests { impl Item for u8 { type Summary = IntegersSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { IntegersSummary { count: 1, sum: *self as usize, diff --git a/crates/sum_tree/src/tree_map.rs b/crates/sum_tree/src/tree_map.rs index c57226b681..9a4d952e93 100644 --- a/crates/sum_tree/src/tree_map.rs +++ b/crates/sum_tree/src/tree_map.rs @@ -224,7 +224,7 @@ where { type Summary = MapKey; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { self.key() } } diff --git a/crates/text/src/locator.rs b/crates/text/src/locator.rs index 7afc16f581..e38b9b58af 100644 --- a/crates/text/src/locator.rs +++ b/crates/text/src/locator.rs @@ -69,7 +69,7 @@ impl Default for Locator { impl sum_tree::Item for Locator { type Summary = Locator; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { self.clone() } } diff --git a/crates/text/src/operation_queue.rs b/crates/text/src/operation_queue.rs index c7964f6267..52b534a41b 100644 --- a/crates/text/src/operation_queue.rs +++ b/crates/text/src/operation_queue.rs @@ -107,7 +107,7 @@ impl<'a> Dimension<'a, OperationSummary> for OperationKey { impl Item for OperationItem { type Summary = OperationSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { OperationSummary { key: OperationKey::new(self.0.lamport_timestamp()), len: 1, diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs index 8bdc9fdb03..80eafcf4eb 100644 --- a/crates/text/src/text.rs +++ b/crates/text/src/text.rs @@ -2617,7 +2617,7 @@ impl Fragment { impl sum_tree::Item for Fragment { type Summary = FragmentSummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &Option) -> Self::Summary { let mut max_version = clock::Global::new(); max_version.observe(self.timestamp); for deletion in &self.deletions { @@ -2688,7 +2688,7 @@ impl Default for FragmentSummary { impl sum_tree::Item for InsertionFragment { type Summary = InsertionFragmentKey; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { InsertionFragmentKey { timestamp: self.timestamp, split_offset: self.split_offset, @@ -2700,7 +2700,7 @@ impl sum_tree::KeyedItem for InsertionFragment { type Key = InsertionFragmentKey; fn key(&self) -> Self::Key { - sum_tree::Item::summary(self) + sum_tree::Item::summary(self, &()) } } diff --git a/crates/text/src/undo_map.rs b/crates/text/src/undo_map.rs index 4e670fd456..ed363cfc6b 100644 --- a/crates/text/src/undo_map.rs +++ b/crates/text/src/undo_map.rs @@ -11,7 +11,7 @@ struct UndoMapEntry { impl sum_tree::Item for UndoMapEntry { type Summary = UndoMapKey; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { self.key } } diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index d81c91132b..a3daf8ea2e 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -3339,7 +3339,7 @@ impl EntryKind { impl sum_tree::Item for Entry { type Summary = EntrySummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { let non_ignored_count = if self.is_ignored || self.is_external { 0 } else { @@ -3434,7 +3434,7 @@ struct PathEntry { impl sum_tree::Item for PathEntry { type Summary = PathEntrySummary; - fn summary(&self) -> Self::Summary { + fn summary(&self, _cx: &()) -> Self::Summary { PathEntrySummary { max_id: self.id } } }