Wait for ignored directory to be expanded in descendant entries test

This commit is contained in:
Max Brunsfeld 2023-06-16 09:42:13 -07:00
parent aa6f2f1816
commit 205c758e4e
3 changed files with 21 additions and 13 deletions

View file

@ -5413,10 +5413,7 @@ impl Project {
if self.is_local() {
let worktree = self.worktree_for_id(worktree_id, cx)?;
worktree.update(cx, |worktree, cx| {
worktree
.as_local_mut()
.unwrap()
.mark_entry_expanded(entry_id, cx);
worktree.as_local_mut().unwrap().expand_dir(entry_id, cx);
});
} else if let Some(project_id) = self.remote_id() {
cx.background()
@ -5742,10 +5739,7 @@ impl Project {
.read_with(&cx, |this, cx| this.worktree_for_entry(entry_id, cx))
.ok_or_else(|| anyhow!("invalid request"))?;
worktree.update(&mut cx, |worktree, cx| {
worktree
.as_local_mut()
.unwrap()
.mark_entry_expanded(entry_id, cx)
worktree.as_local_mut().unwrap().expand_dir(entry_id, cx)
});
Ok(proto::Ack {})
}

View file

@ -91,6 +91,7 @@ enum ScanRequest {
},
ExpandDir {
entry_id: ProjectEntryId,
done: barrier::Sender,
},
}
@ -1149,14 +1150,16 @@ impl LocalWorktree {
}))
}
pub fn mark_entry_expanded(
pub fn expand_dir(
&mut self,
entry_id: ProjectEntryId,
_cx: &mut ModelContext<Worktree>,
) {
) -> barrier::Receiver {
let (tx, rx) = barrier::channel();
self.scan_requests_tx
.try_send(ScanRequest::ExpandDir { entry_id })
.try_send(ScanRequest::ExpandDir { entry_id, done: tx })
.ok();
rx
}
fn refresh_entry(
@ -2963,7 +2966,7 @@ impl BackgroundScanner {
self.reload_entries_for_paths(paths, None).await;
self.send_status_update(false, Some(done))
}
ScanRequest::ExpandDir { entry_id } => {
ScanRequest::ExpandDir { entry_id, done } => {
let path = {
let mut state = self.state.lock();
state.expanded_dirs.insert(entry_id);
@ -2978,7 +2981,7 @@ impl BackgroundScanner {
.await;
if let Some(job) = scan_job_rx.next().await {
self.scan_dir(&job).await.log_err();
self.send_status_update(false, None);
self.send_status_update(false, Some(done));
}
}
true

View file

@ -8,6 +8,7 @@ use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions};
use git::GITIGNORE;
use gpui::{executor::Deterministic, ModelContext, Task, TestAppContext};
use parking_lot::Mutex;
use postage::stream::Stream;
use pretty_assertions::assert_eq;
use rand::prelude::*;
use serde_json::json;
@ -154,7 +155,17 @@ async fn test_descendent_entries(cx: &mut TestAppContext) {
.collect::<Vec<_>>(),
vec![Path::new("g"), Path::new("g/h"),]
);
});
// Expand gitignored directory.
tree.update(cx, |tree, cx| {
let tree = tree.as_local_mut().unwrap();
tree.expand_dir(tree.entry_for_path("i/j").unwrap().id, cx)
})
.recv()
.await;
tree.read_with(cx, |tree, _| {
assert_eq!(
tree.descendent_entries(false, false, Path::new("i"))
.map(|entry| entry.path.as_ref())