diff --git a/crates/collab/src/tests/randomized_integration_tests.rs b/crates/collab/src/tests/randomized_integration_tests.rs index c70c76a76a..a592881929 100644 --- a/crates/collab/src/tests/randomized_integration_tests.rs +++ b/crates/collab/src/tests/randomized_integration_tests.rs @@ -1755,7 +1755,6 @@ async fn simulate_client( name: "the-fake-language-server", capabilities: lsp::LanguageServer::full_capabilities(), initializer: Some(Box::new({ - let plan = plan.clone(); let fs = client.fs.clone(); move |fake_server: &mut FakeLanguageServer| { fake_server.handle_request::( @@ -1797,16 +1796,15 @@ async fn simulate_client( fake_server.handle_request::({ let fs = fs.clone(); - let plan = plan.clone(); - move |_, _| { - let fs = fs.clone(); - let plan = plan.clone(); + move |_, cx| { + let background = cx.background(); + let mut rng = background.rng(); + let count = rng.gen_range::(1..3); + let files = fs.files(); + let files = (0..count) + .map(|_| files.choose(&mut *rng).unwrap().clone()) + .collect::>(); async move { - let files = fs.files(); - let count = plan.lock().rng.gen_range::(1..3); - let files = (0..count) - .map(|_| files.choose(&mut plan.lock().rng).unwrap()) - .collect::>(); log::info!("LSP: Returning definitions in files {:?}", &files); Ok(Some(lsp::GotoDefinitionResponse::Array( files @@ -1821,17 +1819,19 @@ async fn simulate_client( } }); - fake_server.handle_request::({ - let plan = plan.clone(); - move |_, _| { + fake_server.handle_request::( + move |_, cx| { let mut highlights = Vec::new(); - let highlight_count = plan.lock().rng.gen_range(1..=5); + let background = cx.background(); + let mut rng = background.rng(); + + let highlight_count = rng.gen_range(1..=5); for _ in 0..highlight_count { - let start_row = plan.lock().rng.gen_range(0..100); - let start_column = plan.lock().rng.gen_range(0..100); + let start_row = rng.gen_range(0..100); + let start_column = rng.gen_range(0..100); + let end_row = rng.gen_range(0..100); + let end_column = rng.gen_range(0..100); let start = PointUtf16::new(start_row, start_column); - let end_row = plan.lock().rng.gen_range(0..100); - let end_column = plan.lock().rng.gen_range(0..100); let end = PointUtf16::new(end_row, end_column); let range = if start > end { end..start } else { start..end }; highlights.push(lsp::DocumentHighlight { @@ -1843,8 +1843,8 @@ async fn simulate_client( (highlight.range.start, highlight.range.end) }); async move { Ok(Some(highlights)) } - } - }); + }, + ); } })), ..Default::default() diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index 16afa987e9..3ed6abc8e0 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -829,6 +829,16 @@ impl Background { } } + #[cfg(any(test, feature = "test-support"))] + pub fn rng<'a>(&'a self) -> impl 'a + std::ops::DerefMut { + match self { + Self::Deterministic { executor, .. } => { + parking_lot::lock_api::MutexGuard::map(executor.state.lock(), |s| &mut s.rng) + } + _ => panic!("this method can only be called on a deterministic executor"), + } + } + #[cfg(any(test, feature = "test-support"))] pub async fn simulate_random_delay(&self) { match self {