Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Adjust diagnostic transformation test to not wait for two buffer notifications

Max Brunsfeld2db57b5139b0
diff --git a/crates/gpui/src/app/test_app_context.rs b/crates/gpui/src/app/test_app_context.rs
index e956c4ca0d2..2fa86998837 100644
--- a/crates/gpui/src/app/test_app_context.rs
+++ b/crates/gpui/src/app/test_app_context.rs
@@ -434,7 +434,9 @@ impl<T: Entity> ModelHandle<T> {
Duration::from_secs(1)
};
+ let executor = cx.background().clone();
async move {
+ executor.start_waiting();
let notification = crate::util::timeout(duration, rx.next())
.await
.expect("next notification timed out");
diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs
index a06e0d5fdbf..365766fb9dd 100644
--- a/crates/gpui/src/executor.rs
+++ b/crates/gpui/src/executor.rs
@@ -876,6 +876,14 @@ impl Background {
}
}
}
+
+ #[cfg(any(test, feature = "test-support"))]
+ pub fn start_waiting(&self) {
+ match self {
+ Self::Deterministic { executor, .. } => executor.start_waiting(),
+ _ => panic!("this method can only be called on a deterministic executor"),
+ }
+ }
}
impl Default for Background {
diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs
index 87e4880b991..8b4041b852b 100644
--- a/crates/language/src/language.rs
+++ b/crates/language/src/language.rs
@@ -796,6 +796,12 @@ impl LanguageRegistry {
http_client: Arc<dyn HttpClient>,
cx: &mut AppContext,
) -> Option<PendingLanguageServer> {
+ let server_id = self.state.write().next_language_server_id();
+ log::info!(
+ "starting language server name:{}, path:{root_path:?}, id:{server_id}",
+ adapter.name.0
+ );
+
#[cfg(any(test, feature = "test-support"))]
if language.fake_adapter.is_some() {
let task = cx.spawn(|cx| async move {
@@ -825,7 +831,6 @@ impl LanguageRegistry {
Ok(server)
});
- let server_id = self.state.write().next_language_server_id();
return Some(PendingLanguageServer { server_id, task });
}
@@ -834,7 +839,6 @@ impl LanguageRegistry {
.clone()
.ok_or_else(|| anyhow!("language server download directory has not been assigned"))
.log_err()?;
-
let this = self.clone();
let language = language.clone();
let http_client = http_client.clone();
@@ -843,7 +847,6 @@ impl LanguageRegistry {
let adapter = adapter.clone();
let lsp_binary_statuses = self.lsp_binary_statuses_tx.clone();
let login_shell_env_loaded = self.login_shell_env_loaded.clone();
- let server_id = self.state.write().next_language_server_id();
let task = cx.spawn(|cx| async move {
login_shell_env_loaded.await;
diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs
index f4f538b061c..2ec1f63b8b2 100644
--- a/crates/lsp/src/lsp.rs
+++ b/crates/lsp/src/lsp.rs
@@ -849,10 +849,12 @@ impl FakeLanguageServer {
T: request::Request,
T::Result: 'static + Send,
{
+ self.server.executor.start_waiting();
self.server.request::<T>(params).await
}
pub async fn receive_notification<T: notification::Notification>(&mut self) -> T::Params {
+ self.server.executor.start_waiting();
self.try_receive_notification::<T>().await.unwrap()
}
diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs
index d20c5e2619b..34b63fd5bd9 100644
--- a/crates/project/src/project_tests.rs
+++ b/crates/project/src/project_tests.rs
@@ -1193,7 +1193,7 @@ async fn test_toggling_enable_language_server(cx: &mut gpui::TestAppContext) {
.await;
}
-#[gpui::test]
+#[gpui::test(iterations = 3)]
async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {
init_test(cx);
@@ -1273,7 +1273,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {
// The diagnostics have moved down since they were created.
buffer.next_notification(cx).await;
- buffer.next_notification(cx).await;
+ cx.foreground().run_until_parked();
buffer.read_with(cx, |buffer, _| {
assert_eq!(
buffer
@@ -1352,6 +1352,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {
});
buffer.next_notification(cx).await;
+ cx.foreground().run_until_parked();
buffer.read_with(cx, |buffer, _| {
assert_eq!(
buffer
@@ -1444,6 +1445,7 @@ async fn test_transforming_diagnostics(cx: &mut gpui::TestAppContext) {
});
buffer.next_notification(cx).await;
+ cx.foreground().run_until_parked();
buffer.read_with(cx, |buffer, _| {
assert_eq!(
buffer