Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Summary::Context to Item::summarize #18510

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/channel/src/channel_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ pub fn mentions_to_proto(mentions: &[(Range<usize>, UserId)]) -> Vec<proto::Chat
impl sum_tree::Item for ChannelMessage {
type Summary = ChannelMessageSummary;

fn summary(&self) -> Self::Summary {
fn summary(&self, _cx: &()) -> Self::Summary {
ChannelMessageSummary {
max_id: self.id,
count: 1,
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/display_map/block_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/display_map/crease_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/editor/src/display_map/fold_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/display_map/inlay_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/display_map/wrap_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/git/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/git/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/gpui/src/elements/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/language/src/diagnostic_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl DiagnosticSet {
impl sum_tree::Item for DiagnosticEntry<Anchor> {
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,
Expand Down
2 changes: 1 addition & 1 deletion crates/language/src/syntax_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/multi_buffer/src/multi_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/notifications/src/notification_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl EventEmitter<NotificationEvent> 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/rope/src/rope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/sum_tree/src/sum_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: &<Self::Summary as Summary>::Context) -> Self::Summary;
}

/// An [`Item`] whose summary has a specific key that can be used to identify it
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<T: Item> SumTree<T> {
while iter.peek().is_some() {
let items: ArrayVec<T, { 2 * TREE_BASE }> = iter.by_ref().take(2 * TREE_BASE).collect();
let item_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }> =
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..] {
Expand Down Expand Up @@ -281,7 +281,7 @@ impl<T: Item> SumTree<T> {
.map(|items| {
let items: ArrayVec<T, { 2 * TREE_BASE }> = items.into_iter().collect();
let item_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }> =
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..] {
<T::Summary as Summary>::add_summary(&mut summary, item_summary, cx);
Expand Down Expand Up @@ -405,7 +405,7 @@ impl<T: Item> SumTree<T> {
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 {
Expand Down Expand Up @@ -461,7 +461,7 @@ impl<T: Item> SumTree<T> {
}

pub fn push(&mut self, item: T, cx: &<T::Summary as Summary>::Context) {
let summary = item.summary();
let summary = item.summary(cx);
self.append(
SumTree(Arc::new(Node::Leaf {
summary: summary.clone(),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/sum_tree/src/tree_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ where
{
type Summary = MapKey<K>;

fn summary(&self) -> Self::Summary {
fn summary(&self, _cx: &()) -> Self::Summary {
self.key()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/text/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/text/src/operation_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a> Dimension<'a, OperationSummary> for OperationKey {
impl<T: Operation> Item for OperationItem<T> {
type Summary = OperationSummary;

fn summary(&self) -> Self::Summary {
fn summary(&self, _cx: &()) -> Self::Summary {
OperationSummary {
key: OperationKey::new(self.0.lamport_timestamp()),
len: 1,
Expand Down
6 changes: 3 additions & 3 deletions crates/text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<clock::Global>) -> Self::Summary {
let mut max_version = clock::Global::new();
max_version.observe(self.timestamp);
for deletion in &self.deletions {
Expand Down Expand Up @@ -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,
Expand All @@ -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, &())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/text/src/undo_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/worktree/src/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
}
}
Expand Down
Loading