diff --git a/crates/editor2/src/display_map.rs b/crates/editor2/src/display_map.rs index 74890d9edb4bced394ce9363856dfbf3096f8cff..1aee04dd0ae02b8d4ea98025be177a82e3801ef7 100644 --- a/crates/editor2/src/display_map.rs +++ b/crates/editor2/src/display_map.rs @@ -1467,12 +1467,10 @@ pub mod tests { cx.update(|cx| init_test(cx, |s| s.defaults.tab_size = Some(2.try_into().unwrap()))); - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); - let condition = cx.condition(&buffer, |buf, _| !buf.is_parsing()); - cx.update_model(&buffer, |this, cx| { - this.set_language(Some(language), cx); + let buffer = cx.build_model(|cx| { + Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) }); - condition.await; + cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); let font_size = px(14.0); @@ -1556,12 +1554,10 @@ pub mod tests { cx.update(|cx| init_test(cx, |_| {})); - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); - let condition = cx.condition(&buffer, |buf, _| !buf.is_parsing()); - buffer.update(cx, |this, cx| { - this.set_language(Some(language), cx); + let buffer = cx.build_model(|cx| { + Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) }); - condition.await; + cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); let font_size = px(16.0); @@ -1625,10 +1621,10 @@ pub mod tests { let (text, highlighted_ranges) = marked_text_ranges(r#"constˇ «a»: B = "c «d»""#, false); - let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), text)); - let condition = cx.condition(&buffer, |buf, _| !buf.is_parsing()); - buffer.update(cx, |this, cx| this.set_language(Some(language), cx)); - condition.await; + let buffer = cx.build_model(|cx| { + Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx) + }); + cx.condition(&buffer, |buf, _| !buf.is_parsing()).await; let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); let buffer_snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx)); diff --git a/crates/gpui2/src/app/test_context.rs b/crates/gpui2/src/app/test_context.rs index 5c2bf65c02ea1e513cca62b5f69c29c7273a157a..c915753749f4f85bb75cf1440df0775b232d7fa4 100644 --- a/crates/gpui2/src/app/test_context.rs +++ b/crates/gpui2/src/app/test_context.rs @@ -8,7 +8,6 @@ use crate::{ use anyhow::{anyhow, bail}; use futures::{Stream, StreamExt}; use std::{future::Future, ops::Deref, rc::Rc, sync::Arc, time::Duration}; -use util::ResultExt; #[derive(Clone)] pub struct TestAppContext { @@ -298,7 +297,7 @@ impl TestAppContext { .unwrap() } - pub fn notifications(&self, entity: &impl Entity) -> impl Stream { + pub fn notifications(&mut self, entity: &impl Entity) -> impl Stream { let (tx, rx) = futures::channel::mpsc::unbounded(); self.update(|cx| { cx.observe(entity, { @@ -308,7 +307,7 @@ impl TestAppContext { } }) .detach(); - cx.observe_release(entity, move |_, _| dbg!(tx.close_channel())) + cx.observe_release(entity, move |_, _| tx.close_channel()) .detach() }); rx @@ -332,30 +331,28 @@ impl TestAppContext { rx } - pub fn condition( - &self, + pub async fn condition( + &mut self, model: &Model, - mut predicate: impl FnMut(&mut T, &mut ModelContext) -> bool + Send + 'static, - ) -> Task<()> { + mut predicate: impl FnMut(&mut T, &mut ModelContext) -> bool, + ) { let timer = self.executor().timer(Duration::from_secs(3)); let mut notifications = self.notifications(model); use futures::FutureExt as _; use smol::future::FutureExt as _; - let model = model.clone(); - self.spawn(move |mut cx| async move { - async move { - while notifications.next().await.is_some() { - if model.update(&mut cx, &mut predicate).log_err().unwrap() { - return Ok(()); - } + + async { + while notifications.next().await.is_some() { + if model.update(self, &mut predicate) { + return Ok(()); } - bail!("model dropped") } - .race(timer.map(|_| Err(anyhow!("condition timed out")))) - .await - .unwrap() - }) + bail!("model dropped") + } + .race(timer.map(|_| Err(anyhow!("condition timed out")))) + .await + .unwrap(); } } diff --git a/crates/project2/src/worktree.rs b/crates/project2/src/worktree.rs index 86cfc6737411aba10d8de8826e855c2bd8342a9d..e424375220c1c7aa2292d9a4762d7581ea67222e 100644 --- a/crates/project2/src/worktree.rs +++ b/crates/project2/src/worktree.rs @@ -4187,7 +4187,7 @@ impl WorktreeModelHandle for Model { &self, cx: &'a mut gpui::TestAppContext, ) -> futures::future::LocalBoxFuture<'a, ()> { - let file_name: &'static str = "fs-event-sentinel"; + let file_name = "fs-event-sentinel"; let tree = self.clone(); let (fs, root_path) = self.update(cx, |tree, _| { @@ -4200,18 +4200,14 @@ impl WorktreeModelHandle for Model { .await .unwrap(); - cx.condition(&tree, move |tree, _| { - tree.entry_for_path(file_name).is_some() - }) - .await; + cx.condition(&tree, |tree, _| tree.entry_for_path(file_name).is_some()) + .await; fs.remove_file(&root_path.join(file_name), Default::default()) .await .unwrap(); - cx.condition(&tree, move |tree, _| { - tree.entry_for_path(file_name).is_none() - }) - .await; + cx.condition(&tree, |tree, _| tree.entry_for_path(file_name).is_none()) + .await; cx.update(|cx| tree.read(cx).as_local().unwrap().scan_complete()) .await;