From faf265328e9adc46423766f9275a7a7a668a99de Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 16 Nov 2022 16:03:01 +0100 Subject: [PATCH] Wait for acknowledgment before sending the next diagnostic summary --- crates/collab/src/rpc.rs | 5 ++- crates/project/src/worktree.rs | 57 ++++++++++++++++++---------------- crates/rpc/src/proto.rs | 1 + 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index 5e3018160c85b24a51bf04587f880d22008df8e4..db8f25fdb28c56a15a7ea5504951e8a796d1b05e 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -154,7 +154,7 @@ impl Server { .add_request_handler(Server::update_worktree) .add_message_handler(Server::start_language_server) .add_message_handler(Server::update_language_server) - .add_message_handler(Server::update_diagnostic_summary) + .add_request_handler(Server::update_diagnostic_summary) .add_request_handler(Server::forward_project_request::) .add_request_handler(Server::forward_project_request::) .add_request_handler(Server::forward_project_request::) @@ -1127,6 +1127,7 @@ impl Server { async fn update_diagnostic_summary( self: Arc, request: Message, + response: Response, ) -> Result<()> { let guest_connection_ids = self .app_state @@ -1145,6 +1146,8 @@ impl Server { ) }, ); + + response.send(proto::Ack {})?; Ok(()) } diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index ddd4a7a6c847998fec8564e147b9f4ff30fa2177..836ac55b661157f8c2f0297567b55143b8b26d2a 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -166,7 +166,9 @@ enum ScanState { struct ShareState { project_id: u64, snapshots_tx: watch::Sender, - _maintain_remote_snapshot: Option>>, + diagnostic_summaries_tx: mpsc::UnboundedSender<(Arc, DiagnosticSummary)>, + _maintain_remote_snapshot: Task>, + _maintain_remote_diagnostic_summaries: Task<()>, } pub enum Event { @@ -524,18 +526,9 @@ impl LocalWorktree { let updated = !old_summary.is_empty() || !new_summary.is_empty(); if updated { if let Some(share) = self.share.as_ref() { - self.client - .send(proto::UpdateDiagnosticSummary { - project_id: share.project_id, - worktree_id: self.id().to_proto(), - summary: Some(proto::DiagnosticSummary { - path: worktree_path.to_string_lossy().to_string(), - language_server_id: language_server_id as u64, - error_count: new_summary.error_count as u32, - warning_count: new_summary.warning_count as u32, - }), - }) - .log_err(); + let _ = share + .diagnostic_summaries_tx + .unbounded_send((worktree_path.clone(), new_summary)); } } @@ -967,22 +960,10 @@ impl LocalWorktree { let _ = share_tx.send(Ok(())); } else { let (snapshots_tx, mut snapshots_rx) = watch::channel_with(self.snapshot()); - let rpc = self.client.clone(); let worktree_id = cx.model_id() as u64; - for (path, summary) in self.diagnostic_summaries.iter() { - if let Err(e) = rpc.send(proto::UpdateDiagnosticSummary { - project_id, - worktree_id, - summary: Some(summary.to_proto(&path.0)), - }) { - return Task::ready(Err(e)); - } - } - let maintain_remote_snapshot = cx.background().spawn({ - let rpc = rpc; - + let rpc = self.client.clone(); async move { let mut prev_snapshot = match snapshots_rx.recv().await { Some(snapshot) => { @@ -1029,10 +1010,32 @@ impl LocalWorktree { } .log_err() }); + + let (diagnostic_summaries_tx, mut diagnostic_summaries_rx) = mpsc::unbounded(); + for (path, summary) in self.diagnostic_summaries.iter() { + let _ = diagnostic_summaries_tx.unbounded_send((path.0.clone(), summary.clone())); + } + let maintain_remote_diagnostic_summaries = cx.background().spawn({ + let rpc = self.client.clone(); + async move { + while let Some((path, summary)) = diagnostic_summaries_rx.next().await { + rpc.request(proto::UpdateDiagnosticSummary { + project_id, + worktree_id, + summary: Some(summary.to_proto(&path)), + }) + .await + .log_err(); + } + } + }); + self.share = Some(ShareState { project_id, snapshots_tx, - _maintain_remote_snapshot: Some(maintain_remote_snapshot), + diagnostic_summaries_tx, + _maintain_remote_snapshot: maintain_remote_snapshot, + _maintain_remote_diagnostic_summaries: maintain_remote_diagnostic_summaries, }); } diff --git a/crates/rpc/src/proto.rs b/crates/rpc/src/proto.rs index 6d9bc9a0aa348af8c1a14f442323fcf06064688e..50f3c57f2a6b3c5bd9bc6798e468df7a541a2f07 100644 --- a/crates/rpc/src/proto.rs +++ b/crates/rpc/src/proto.rs @@ -228,6 +228,7 @@ request_messages!( (ShareProject, ShareProjectResponse), (Test, Test), (UpdateBuffer, Ack), + (UpdateDiagnosticSummary, Ack), (UpdateParticipantLocation, Ack), (UpdateProject, Ack), (UpdateWorktree, Ack),