diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 1b29555a33..af07b9eca5 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -492,6 +492,15 @@ impl TestAppContext { self.cx.borrow().background().clone() } + pub fn spawn(&self, f: F) -> Task + where + F: FnOnce(AsyncAppContext) -> Fut, + Fut: 'static + Future, + T: 'static, + { + self.cx.borrow_mut().spawn(f) + } + pub fn simulate_new_path_selection(&self, result: impl FnOnce(PathBuf) -> Option) { self.foreground_platform.simulate_new_path_selection(result); } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 9533429ba9..be7ba09d32 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1580,6 +1580,7 @@ impl Project { } else if let Some(project_id) = self.remote_id() { let rpc = self.client.clone(); cx.foreground().spawn(async move { + let _buffer = buffer_handle.clone(); let response = rpc .request(proto::GetCodeActions { project_id, diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index 4fb88d0992..73ebdfab7b 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -4169,6 +4169,8 @@ mod tests { self.buffers.insert(buffer.clone()); buffer } else { + operations.set(operations.get() + 1); + self.buffers .iter() .choose(&mut *rng.borrow_mut()) @@ -4190,30 +4192,42 @@ mod tests { }); } 10..=14 => { - project - .update(&mut cx, |project, cx| { - log::info!( - "Guest {}: requesting completions for buffer {:?}", - guest_id, - buffer.read(cx).file().unwrap().full_path(cx) - ); - project.completions(&buffer, 0, cx) - }) - .await - .expect("completion request failed"); + let completions = project.update(&mut cx, |project, cx| { + log::info!( + "Guest {}: requesting completions for buffer {:?}", + guest_id, + buffer.read(cx).file().unwrap().full_path(cx) + ); + project.completions(&buffer, 0, cx) + }); + let completions = cx.background().spawn(async move { + completions.await.expect("code actions request failed"); + }); + if rng.borrow_mut().gen_bool(0.3) { + log::info!("Guest {}: detaching completions request", guest_id); + completions.detach(); + } else { + completions.await; + } } 15..=19 => { - project - .update(&mut cx, |project, cx| { - log::info!( - "Guest {}: requesting code actions for buffer {:?}", - guest_id, - buffer.read(cx).file().unwrap().full_path(cx) - ); - project.code_actions(&buffer, 0..0, cx) - }) - .await - .expect("completion request failed"); + let code_actions = project.update(&mut cx, |project, cx| { + log::info!( + "Guest {}: requesting code actions for buffer {:?}", + guest_id, + buffer.read(cx).file().unwrap().full_path(cx) + ); + project.code_actions(&buffer, 0..0, cx) + }); + let code_actions = cx.background().spawn(async move { + code_actions.await.expect("code actions request failed"); + }); + if rng.borrow_mut().gen_bool(0.3) { + log::info!("Guest {}: detaching code actions request", guest_id); + code_actions.detach(); + } else { + code_actions.await; + } } 20..=29 if buffer.read_with(&cx, |buffer, _| buffer.is_dirty()) => { let (requested_version, save) = buffer.update(&mut cx, |buffer, cx| { @@ -4224,11 +4238,19 @@ mod tests { ); (buffer.version(), buffer.save(cx)) }); - let (saved_version, _) = save.await.expect("completion request failed"); - buffer.read_with(&cx, |buffer, _| { - assert!(buffer.version().observed_all(&saved_version)); - assert!(saved_version.observed_all(&requested_version)); + let save = cx.spawn(|cx| async move { + let (saved_version, _) = save.await.expect("save request failed"); + buffer.read_with(&cx, |buffer, _| { + assert!(buffer.version().observed_all(&saved_version)); + assert!(saved_version.observed_all(&requested_version)); + }); }); + if rng.borrow_mut().gen_bool(0.3) { + log::info!("Guest {}: detaching save request", guest_id); + save.detach(); + } else { + save.await; + } } _ => { buffer.update(&mut cx, |buffer, cx| {