From 2147db9b41b26b9d7d274e6aead46a2cec24b952 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 25 Feb 2022 12:29:50 +0100 Subject: [PATCH] Open searched buffers in parallel --- crates/project/src/project.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 827c816fea..fdee1d2db7 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2148,23 +2148,36 @@ impl Project { .values() .filter_map(|b| b.upgrade(cx)) .collect::>(); - cx.spawn(|this, mut cx| async move { + cx.spawn(|this, cx| async move { for buffer in &open_buffers { let snapshot = buffer.read_with(&cx, |buffer, _| buffer.snapshot()); buffers_tx.send((buffer.clone(), snapshot)).await?; } + let open_buffers = Rc::new(RefCell::new(open_buffers)); while let Some(project_path) = matching_paths_rx.next().await { - if let Some(buffer) = this - .update(&mut cx, |this, cx| this.open_buffer(project_path, cx)) - .await - .log_err() - { - if !open_buffers.contains(&buffer) { - let snapshot = buffer.read_with(&cx, |buffer, _| buffer.snapshot()); - buffers_tx.send((buffer, snapshot)).await?; - } + if buffers_tx.is_closed() { + break; } + + let this = this.clone(); + let open_buffers = open_buffers.clone(); + let buffers_tx = buffers_tx.clone(); + cx.spawn(|mut cx| async move { + if let Some(buffer) = this + .update(&mut cx, |this, cx| this.open_buffer(project_path, cx)) + .await + .log_err() + { + if open_buffers.borrow_mut().insert(buffer.clone()) { + let snapshot = buffer.read_with(&cx, |buffer, _| buffer.snapshot()); + buffers_tx.send((buffer, snapshot)).await?; + } + } + + Ok::<_, anyhow::Error>(()) + }) + .detach(); } Ok::<_, anyhow::Error>(())