Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Get project2 tests green
Nathan Sobo53066df52200
diff --git a/crates/gpui2/src/app/test_context.rs b/crates/gpui2/src/app/test_context.rsindex d4a63c4e37c..d7bf2b7087a 100644--- a/crates/gpui2/src/app/test_context.rs+++ b/crates/gpui2/src/app/test_context.rs@@ -3,8 +3,8 @@ use crate::{ForegroundExecutor, Model, ModelContext, Result, Task, TestDispatcher, TestPlatform,WindowContext,};-use anyhow::anyhow;-use futures::{SinkExt, StreamExt};+use anyhow::{anyhow, bail};+use futures::{SinkExt, Stream, StreamExt};use std::{cell::RefCell, future::Future, rc::Rc, sync::Arc, time::Duration};#[derive(Clone)]@@ -140,7 +140,25 @@ impl TestAppContext {}}- pub fn subscribe<T: 'static + EventEmitter>(+ pub fn notifications<T: 'static>(&mut self, entity: &Model<T>) -> impl Stream<Item = ()> {+ let (tx, rx) = futures::channel::mpsc::unbounded();++ entity.update(self, move |_, cx: &mut ModelContext<T>| {+ cx.observe(entity, {+ let tx = tx.clone();+ move |_, _, _| {+ let _ = tx.unbounded_send(());+ }+ })+ .detach();++ cx.on_release(move |_, _| tx.close_channel()).detach();+ });++ rx+ }++ pub fn events<T: 'static + EventEmitter>(&mut self,entity: &Model<T>,) -> futures::channel::mpsc::UnboundedReceiver<T::Event>@@ -160,36 +178,24 @@ impl TestAppContext {rx}- pub async fn condition<T: EventEmitter + 'static>(+ pub async fn condition<T: 'static>(&mut self,model: &Model<T>,mut predicate: impl FnMut(&mut T, &mut ModelContext<T>) -> bool,) {- let (mut tx, mut rx) = futures::channel::mpsc::unbounded::<()>();let timer = self.executor().timer(Duration::from_secs(3));-- let subscriptions = model.update(self, move |_, cx| {- (- cx.observe(model, move |_, _, _| {- // let _ = tx.send(());- }),- cx.subscribe(model, move |_, _, _, _| {- let _ = tx.send(());- }),- )- });+ let mut notifications = self.notifications(model);use futures::FutureExt as _;use smol::future::FutureExt as _;async {- while rx.next().await.is_some() {+ while notifications.next().await.is_some() {if model.update(self, &mut predicate) {return Ok(());}}- drop(subscriptions);- unreachable!()+ bail!("model dropped")}.race(timer.map(|_| Err(anyhow!("condition timed out")))).awaitdiff --git a/crates/project2/src/project_tests.rs b/crates/project2/src/project_tests.rsindex ca6cdbccfc7..5a2f82c3758 100644--- a/crates/project2/src/project_tests.rs+++ b/crates/project2/src/project_tests.rs@@ -947,7 +947,7 @@ async fn test_disk_based_diagnostics_progress(cx: &mut gpui2::TestAppContext) {.await.unwrap();- let mut events = cx.subscribe(&project);+ let mut events = cx.events(&project);let fake_server = fake_servers.next().await.unwrap();assert_eq!(@@ -1078,7 +1078,7 @@ async fn test_restarting_server_with_diagnostics_running(cx: &mut gpui2::TestAppproject.update(cx, |project, cx| {project.restart_language_servers_for_buffers([buffer], cx);});- let mut events = cx.subscribe(&project);+ let mut events = cx.events(&project);// Simulate the newly started server sending more diagnostics.let fake_server = fake_servers.next().await.unwrap();@@ -2788,6 +2788,7 @@ async fn test_rescan_and_remote_updates(cx: &mut gpui2::TestAppContext) {});let remote = cx.update(|cx| Worktree::remote(1, 1, metadata, rpc.clone(), cx));+cx.executor().run_until_parked();cx.update(|cx| {diff --git a/crates/project2/src/worktree.rs b/crates/project2/src/worktree.rsindex f146bf79489..060fefe6b3a 100644--- a/crates/project2/src/worktree.rs+++ b/crates/project2/src/worktree.rs@@ -4065,6 +4065,7 @@ impl WorktreeModelHandle for Model<Worktree> {fs.create_file(&root_path.join(file_name), Default::default()).await.unwrap();+cx.condition(&tree, |tree, _| tree.entry_for_path(file_name).is_some()).await;diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rsindex 854786ebaa6..5318e3f3bb0 100644--- a/crates/ui2/src/components/panes.rs+++ b/crates/ui2/src/components/panes.rs@@ -51,7 +51,7 @@ impl<V: 'static> Pane<V> {.id("drag-target").drag_over::<ExternalPaths>(|d| d.bg(red())).on_drop(|_, files: View<ExternalPaths>, cx| {- dbg!("dropped files!", files.read(cx));+ eprintln!("dropped files! {:?}", files.read(cx));}).absolute().inset_0(),diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rsindex d784ec01748..c89ed2d7eb8 100644--- a/crates/ui2/src/components/tab.rs+++ b/crates/ui2/src/components/tab.rs@@ -130,7 +130,7 @@ impl Tab {.on_drag(move |_view, cx| cx.build_view(|cx| drag_state.clone())).drag_over::<TabDragState>(|d| d.bg(black())).on_drop(|_view, state: View<TabDragState>, cx| {- dbg!(state.read(cx));+ eprintln!("{:?}", state.read(cx));}).px_2().py_0p5()