mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
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<Anchor>`. Release Notes: - N/A Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
8aeab4800c
commit
84ce81caf1
@ -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,
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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(),
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -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..] {
|
||||
@ -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);
|
||||
@ -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 {
|
||||
@ -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(),
|
||||
@ -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,
|
||||
|
@ -224,7 +224,7 @@ where
|
||||
{
|
||||
type Summary = MapKey<K>;
|
||||
|
||||
fn summary(&self) -> Self::Summary {
|
||||
fn summary(&self, _cx: &()) -> Self::Summary {
|
||||
self.key()
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
@ -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, &())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user