Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
multi_buffer: Remap excerpt ids to latest excerpt in excerpt fetching (#44229)
Lukas Wirth37b0cdf94ba9
diff --git a/crates/editor/src/selections_collection.rs b/crates/editor/src/selections_collection.rsindex f8ff9da7634..6c6c88faf5e 100644--- a/crates/editor/src/selections_collection.rs+++ b/crates/editor/src/selections_collection.rs@@ -419,22 +419,30 @@ impl SelectionsCollection {mutable_collection.disjoint.iter().for_each(|selection| {assert!(snapshot.can_resolve(&selection.start),- "disjoint selection start is not resolvable for the given snapshot:\n{selection:?}",+ "disjoint selection start is not resolvable for the given snapshot:\n{selection:?}, {excerpt:?}",+ excerpt = snapshot.buffer_for_excerpt(selection.start.excerpt_id).map(|snapshot| snapshot.remote_id()),);assert!(snapshot.can_resolve(&selection.end),- "disjoint selection end is not resolvable for the given snapshot: {selection:?}",+ "disjoint selection end is not resolvable for the given snapshot: {selection:?}, {excerpt:?}",+ excerpt = snapshot.buffer_for_excerpt(selection.end.excerpt_id).map(|snapshot| snapshot.remote_id()),);});if let Some(pending) = &mutable_collection.pending {let selection = &pending.selection;assert!(snapshot.can_resolve(&selection.start),- "pending selection start is not resolvable for the given snapshot: {pending:?}",+ "pending selection start is not resolvable for the given snapshot: {pending:?}, {excerpt:?}",+ excerpt = snapshot+ .buffer_for_excerpt(selection.start.excerpt_id)+ .map(|snapshot| snapshot.remote_id()),);assert!(snapshot.can_resolve(&selection.end),- "pending selection end is not resolvable for the given snapshot: {pending:?}",+ "pending selection end is not resolvable for the given snapshot: {pending:?}, {excerpt:?}",+ excerpt = snapshot+ .buffer_for_excerpt(selection.end.excerpt_id)+ .map(|snapshot| snapshot.remote_id()),);}}diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rsindex 24cb55d2f5e..bd163557c4f 100644--- a/crates/multi_buffer/src/multi_buffer.rs+++ b/crates/multi_buffer/src/multi_buffer.rs@@ -6457,12 +6457,13 @@ impl MultiBufferSnapshot {}/// Returns the excerpt for the given id. The returned excerpt is guaranteed- /// to have the same excerpt id as the one passed in, with the exception of- /// `ExcerptId::max()`.+ /// to have the latest excerpt id for the one passed in and will also remap+ /// `ExcerptId::max()` to the corresponding excertp ID.////// Callers of this function should generally use the resulting excerpt's `id` field/// afterwards.fn excerpt(&self, excerpt_id: ExcerptId) -> Option<&Excerpt> {+ let excerpt_id = self.latest_excerpt_id(excerpt_id);let mut cursor = self.excerpts.cursor::<Option<&Locator>>(());let locator = self.excerpt_locator_for_id(excerpt_id);cursor.seek(&Some(locator), Bias::Left);diff --git a/crates/multi_buffer/src/path_key.rs b/crates/multi_buffer/src/path_key.rsindex 82bb902c230..119194d088c 100644--- a/crates/multi_buffer/src/path_key.rs+++ b/crates/multi_buffer/src/path_key.rs@@ -305,7 +305,7 @@ impl MultiBuffer {let snapshot = self.snapshot(cx);let mut next_excerpt_id =- // is this right? What if we remove the last excerpt, then we might reallocate with a wrong mapping?+ // todo(lw): is this right? What if we remove the last excerpt, then we might reallocate with a wrong mapping?if let Some(last_entry) = self.snapshot.borrow().excerpt_ids.last() {last_entry.id.0 + 1} else {