Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge remote-tracking branch 'origin/main' into ai-refactoring
Antonio Scandurra44f554f48963
diff --cc crates/editor/src/multi_buffer.rsindex 52fbcd99d9c,3ace5adbc7f..c7c40289959--- a/crates/editor/src/multi_buffer.rs+++ b/crates/editor/src/multi_buffer.rs@@@ -822,67 -788,53 +824,65 @@@ impl MultiBufferNone}+ pub fn undo_and_forget(&mut self, transaction_id: TransactionId, cx: &mut ModelContext<Self>) {+ if let Some(buffer) = self.as_singleton() {+ buffer.update(cx, |buffer, cx| buffer.undo_and_forget(transaction_id, cx));+ } else if let Some(transaction) = self.history.forget(transaction_id) {+ for (buffer_id, transaction_id) in transaction.buffer_transactions {+ if let Some(BufferState { buffer, .. }) = self.buffers.borrow().get(&buffer_id) {+ buffer.update(cx, |buffer, cx| buffer.undo_and_forget(transaction_id, cx));+ }+ }+ }+ }+pub fn stream_excerpts_with_context_lines(&mut self,- excerpts: Vec<(ModelHandle<Buffer>, Vec<Range<text::Anchor>>)>,+ buffer: ModelHandle<Buffer>,+ ranges: Vec<Range<text::Anchor>>,context_line_count: u32,cx: &mut ModelContext<Self>,- ) -> (Task<()>, mpsc::Receiver<Range<Anchor>>) {+ ) -> mpsc::Receiver<Range<Anchor>> {let (mut tx, rx) = mpsc::channel(256);- let task = cx.spawn(|this, mut cx| async move {- for (buffer, ranges) in excerpts {- let (buffer_id, buffer_snapshot) =- buffer.read_with(&cx, |buffer, _| (buffer.remote_id(), buffer.snapshot()));-- let mut excerpt_ranges = Vec::new();- let mut range_counts = Vec::new();- cx.background()- .scoped(|scope| {- scope.spawn(async {- let (ranges, counts) =- build_excerpt_ranges(&buffer_snapshot, &ranges, context_line_count);- excerpt_ranges = ranges;- range_counts = counts;- });- })- .await;-- let mut ranges = ranges.into_iter();- let mut range_counts = range_counts.into_iter();- for excerpt_ranges in excerpt_ranges.chunks(100) {- let excerpt_ids = this.update(&mut cx, |this, cx| {- this.push_excerpts(buffer.clone(), excerpt_ranges.iter().cloned(), cx)+ cx.spawn(|this, mut cx| async move {+ let (buffer_id, buffer_snapshot) =+ buffer.read_with(&cx, |buffer, _| (buffer.remote_id(), buffer.snapshot()));++ let mut excerpt_ranges = Vec::new();+ let mut range_counts = Vec::new();+ cx.background()+ .scoped(|scope| {+ scope.spawn(async {+ let (ranges, counts) =+ build_excerpt_ranges(&buffer_snapshot, &ranges, context_line_count);+ excerpt_ranges = ranges;+ range_counts = counts;});+ })+ .await;- for (excerpt_id, range_count) in- excerpt_ids.into_iter().zip(range_counts.by_ref())- {- for range in ranges.by_ref().take(range_count) {- let start = Anchor {- buffer_id: Some(buffer_id),- excerpt_id: excerpt_id.clone(),- text_anchor: range.start,- };- let end = Anchor {- buffer_id: Some(buffer_id),- excerpt_id: excerpt_id.clone(),- text_anchor: range.end,- };- if tx.send(start..end).await.is_err() {- break;- }+ let mut ranges = ranges.into_iter();+ let mut range_counts = range_counts.into_iter();+ for excerpt_ranges in excerpt_ranges.chunks(100) {+ let excerpt_ids = this.update(&mut cx, |this, cx| {+ this.push_excerpts(buffer.clone(), excerpt_ranges.iter().cloned(), cx)+ });++ for (excerpt_id, range_count) in excerpt_ids.into_iter().zip(range_counts.by_ref())+ {+ for range in ranges.by_ref().take(range_count) {+ let start = Anchor {+ buffer_id: Some(buffer_id),+ excerpt_id: excerpt_id.clone(),+ text_anchor: range.start,+ };+ let end = Anchor {+ buffer_id: Some(buffer_id),+ excerpt_id: excerpt_id.clone(),+ text_anchor: range.end,+ };+ if tx.send(start..end).await.is_err() {+ break;}}}