diff --git a/zed/src/editor/buffer/mod.rs b/zed/src/editor/buffer/mod.rs index dbc87b3ae0..6d35e9bd42 100644 --- a/zed/src/editor/buffer/mod.rs +++ b/zed/src/editor/buffer/mod.rs @@ -3060,7 +3060,8 @@ mod tests { tree.flush_fs_events(&app).await; fs::remove_file(dir.path().join("file1")).unwrap(); - app.read(|ctx| tree.read(ctx).next_scan_complete()).await; + tree.update(&mut app, |tree, ctx| tree.next_scan_complete(ctx)) + .await; model.update(&mut app, |buffer, _| { assert_eq!(*events.borrow(), &[Event::FileHandleChanged]); diff --git a/zed/src/workspace.rs b/zed/src/workspace.rs index 756ec3c09a..7253e0a5af 100644 --- a/zed/src/workspace.rs +++ b/zed/src/workspace.rs @@ -732,7 +732,6 @@ mod tests { use gpui::App; use serde_json::json; use std::collections::HashSet; - use std::time; use tempdir::TempDir; #[test] @@ -986,7 +985,7 @@ mod tests { workspace.add_worktree(dir.path(), ctx); workspace }); - let worktree = app.read(|ctx| { + let tree = app.read(|ctx| { workspace .read(ctx) .worktrees() @@ -995,6 +994,7 @@ mod tests { .unwrap() .clone() }); + tree.flush_fs_events(&app).await; // Create a new untitled buffer let editor = workspace.update(&mut app, |workspace, ctx| { @@ -1027,15 +1027,12 @@ mod tests { }); // When the save completes, the buffer's title is updated. - editor - .condition(&app, |editor, ctx| !editor.is_dirty(ctx)) + tree.update(&mut app, |tree, ctx| tree.next_scan_complete(ctx)) .await; - worktree - .condition_with_duration(time::Duration::from_millis(500), &app, |worktree, _| { - worktree.inode_for_path("the-new-name").is_some() - }) - .await; - app.read(|ctx| assert_eq!(editor.title(ctx), "the-new-name")); + app.read(|ctx| { + assert!(!editor.is_dirty(ctx)); + assert_eq!(editor.title(ctx), "the-new-name"); + }); // Edit the file and save it again. This time, there is no filename prompt. editor.update(&mut app, |editor, ctx| { @@ -1057,7 +1054,7 @@ mod tests { workspace.open_new_file(&(), ctx); workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, ctx); assert!(workspace - .open_entry((worktree.id(), Path::new("the-new-name").into()), ctx) + .open_entry((tree.id(), Path::new("the-new-name").into()), ctx) .is_none()); }); let editor2 = workspace.update(&mut app, |workspace, ctx| { diff --git a/zed/src/worktree.rs b/zed/src/worktree.rs index a2993d99bb..06d74f9310 100644 --- a/zed/src/worktree.rs +++ b/zed/src/worktree.rs @@ -114,19 +114,17 @@ impl Worktree { } } - pub fn next_scan_complete(&self) -> impl Future { - let mut scan_state_rx = self.scan_state.1.clone(); - let mut did_scan = matches!(*scan_state_rx.borrow(), ScanState::Scanning); - async move { - loop { - if let ScanState::Scanning = *scan_state_rx.borrow() { - did_scan = true; - } else if did_scan { - break; + pub fn next_scan_complete(&self, ctx: &mut ModelContext) -> impl Future { + let scan_id = self.snapshot.scan_id; + ctx.spawn_stream( + self.scan_state.1.clone(), + move |this, _, ctx| { + if this.snapshot.scan_id > scan_id { + ctx.halt_stream(); } - scan_state_rx.recv().await; - } - } + }, + |_, _| {}, + ) } fn observe_scan_state(&mut self, scan_state: ScanState, ctx: &mut ModelContext) { @@ -1495,7 +1493,8 @@ mod tests { std::fs::remove_file(dir.path().join("b/c/file5")).unwrap(); std::fs::rename(dir.path().join("b/c"), dir.path().join("d")).unwrap(); std::fs::rename(dir.path().join("a/file2"), dir.path().join("a/file2.new")).unwrap(); - app.read(|ctx| tree.read(ctx).next_scan_complete()).await; + tree.update(&mut app, |tree, ctx| tree.next_scan_complete(ctx)) + .await; app.read(|ctx| { assert_eq!( @@ -1557,7 +1556,8 @@ mod tests { fs::write(dir.path().join("tracked-dir/tracked-file2"), "").unwrap(); fs::write(dir.path().join("ignored-dir/ignored-file2"), "").unwrap(); - app.read(|ctx| tree.read(ctx).next_scan_complete()).await; + tree.update(&mut app, |tree, ctx| tree.next_scan_complete(ctx)) + .await; app.read(|ctx| { let tree = tree.read(ctx); let dot_git = tree.entry_for_path(".git").unwrap();