From 19f51bc48045a0fe1931b1eaf55cf7b021c5ac9b Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 13 May 2021 11:25:29 +0200 Subject: [PATCH] Rely more on conditions for state derived after worktree changes --- zed/src/editor/buffer/mod.rs | 10 ++++++---- zed/src/workspace.rs | 20 +++++++++----------- zed/src/worktree.rs | 14 -------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/zed/src/editor/buffer/mod.rs b/zed/src/editor/buffer/mod.rs index 1e960b9dd3..0bb5fc8ea3 100644 --- a/zed/src/editor/buffer/mod.rs +++ b/zed/src/editor/buffer/mod.rs @@ -3148,12 +3148,13 @@ mod tests { }); fs::remove_file(dir.path().join("file2")).unwrap(); - tree.flush_fs_events(&app).await; + buffer2 + .condition(&app, |buffer2, _| buffer2.is_dirty()) + .await; assert_eq!( *events.borrow(), &[Event::Dirtied, Event::FileHandleChanged] ); - app.read(|ctx| assert!(buffer2.read(ctx).is_dirty())); // When a file is already dirty when deleted, we don't emit a Dirtied event. let events = Rc::new(RefCell::new(Vec::new())); @@ -3173,7 +3174,9 @@ mod tests { }); events.borrow_mut().clear(); fs::remove_file(dir.path().join("file3")).unwrap(); - tree.flush_fs_events(&app).await; + buffer3 + .condition(&app, |_, _| !events.borrow().is_empty()) + .await; assert_eq!(*events.borrow(), &[Event::FileHandleChanged]); app.read(|ctx| assert!(buffer3.read(ctx).is_dirty())); }); @@ -3222,7 +3225,6 @@ mod tests { }); let new_contents = "AAAA\naaa\nBB\nbbbbb\n"; fs::write(&abs_path, new_contents).unwrap(); - tree.flush_fs_events(&app).await; // Because the buffer was not modified, it is reloaded from disk. Its // contents are edited according to the diff between the old and new diff --git a/zed/src/workspace.rs b/zed/src/workspace.rs index 5c9dc16c92..328ebf30e8 100644 --- a/zed/src/workspace.rs +++ b/zed/src/workspace.rs @@ -1030,20 +1030,17 @@ mod tests { app.update(|ctx| editor.update(ctx, |editor, ctx| editor.insert(&"x".to_string(), ctx))); fs::write(dir.path().join("a.txt"), "changed").unwrap(); - tree.flush_fs_events(&app).await; - app.read(|ctx| { - assert!(editor.is_dirty(ctx)); - assert!(editor.has_conflict(ctx)); - }); + editor + .condition(&app, |editor, ctx| editor.has_conflict(ctx)) + .await; + app.read(|ctx| assert!(editor.is_dirty(ctx))); app.update(|ctx| workspace.update(ctx, |w, ctx| w.save_active_item(&(), ctx))); app.simulate_prompt_answer(window_id, 0); - tree.update(&mut app, |tree, ctx| tree.next_scan_complete(ctx)) + editor + .condition(&app, |editor, ctx| !editor.is_dirty(ctx)) .await; - app.read(|ctx| { - assert!(!editor.is_dirty(ctx)); - assert!(!editor.has_conflict(ctx)); - }); + app.read(|ctx| assert!(!editor.has_conflict(ctx))); } #[gpui::test] @@ -1097,7 +1094,8 @@ mod tests { }); // When the save completes, the buffer's title is updated. - tree.update(&mut app, |tree, ctx| tree.next_scan_complete(ctx)) + editor + .condition(&app, |editor, ctx| !editor.is_dirty(ctx)) .await; app.read(|ctx| { assert!(!editor.is_dirty(ctx)); diff --git a/zed/src/worktree.rs b/zed/src/worktree.rs index e213257d3a..0f69ea8331 100644 --- a/zed/src/worktree.rs +++ b/zed/src/worktree.rs @@ -134,20 +134,6 @@ impl Worktree { } } - pub fn next_scan_complete(&self, ctx: &mut ModelContext) -> impl Future { - let scan_id = self.snapshot.scan_id; - let mut scan_state = self.scan_state.1.clone(); - ctx.spawn(|this, ctx| async move { - while let Some(scan_state) = scan_state.recv().await { - if this.read_with(&ctx, |this, _| { - matches!(scan_state, ScanState::Idle) && this.snapshot.scan_id > scan_id - }) { - break; - } - } - }) - } - fn observe_scan_state(&mut self, scan_state: ScanState, ctx: &mut ModelContext) { let _ = self.scan_state.0.blocking_send(scan_state); self.poll_entries(ctx);