diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index a0c69ebd0c6bf8018b31a79bbc5d9d7123d4f299..60103d80b834cfbf73f8b8f6b6e4d52495690b7c 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -521,7 +521,7 @@ impl LanguageServer { #[cfg(any(test, feature = "test-support"))] impl FakeLanguageServer { fn new( - executor: Arc, + background: Arc, stdin: async_pipe::PipeReader, stdout: async_pipe::PipeWriter, ) -> Self { @@ -537,11 +537,13 @@ impl FakeLanguageServer { // Receive incoming messages let handlers = this.handlers.clone(); - executor + let executor = background.clone(); + background .spawn(async move { let mut buffer = Vec::new(); let mut stdin = smol::io::BufReader::new(stdin); while Self::receive(&mut stdin, &mut buffer).await.is_ok() { + executor.simulate_random_delay().await; if let Ok(request) = serde_json::from_slice::(&buffer) { assert_eq!(request.jsonrpc, JSON_RPC_VERSION); @@ -571,7 +573,7 @@ impl FakeLanguageServer { .detach(); // Send outgoing messages - executor + background .spawn(async move { let mut stdout = smol::io::BufWriter::new(stdout); while let Some(notification) = outgoing_rx.next().await { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 1c1f3dcdb4555dd4283bab770d934b75c004da63..208604bd09587d72b83a94c093db8402b841f07f 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1578,8 +1578,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(); + cx.spawn_weak(|_, mut cx| async move { let response = rpc .request(proto::GetCodeActions { project_id, @@ -1588,6 +1587,13 @@ impl Project { end: Some(language::proto::serialize_anchor(&range.end)), }) .await?; + + buffer_handle + .update(&mut cx, |buffer, _| { + buffer.wait_for_version(response.version.into()) + }) + .await; + response .actions .into_iter() @@ -2448,6 +2454,7 @@ impl Project { .iter() .map(language::proto::serialize_code_action) .collect(), + version: (&version).into(), }) } diff --git a/crates/rpc/proto/zed.proto b/crates/rpc/proto/zed.proto index 82cdea47cb2ef15ecdac873ee120e5c8666ba4c6..9d7baa8992443ba20b394ba813f9997164f9cf3d 100644 --- a/crates/rpc/proto/zed.proto +++ b/crates/rpc/proto/zed.proto @@ -261,6 +261,7 @@ message GetCodeActions { message GetCodeActionsResponse { repeated CodeAction actions = 1; + repeated VectorClockEntry version = 2; } message ApplyCodeAction {