From 95024c616eac1bc859b7055d2e7ee74a0adc8fa5 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 21 Jun 2021 14:44:01 +0200 Subject: [PATCH] Put back `worktree_id` in `CloseFile` and `OpenBuffer` messages --- zed-rpc/proto/zed.proto | 6 ++++-- zed-rpc/src/peer.rs | 22 ++++++++++++++++++++++ zed/src/worktree.rs | 16 ++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/zed-rpc/proto/zed.proto b/zed-rpc/proto/zed.proto index a2e2613419a7ba8ae8f46fe8ab36866777d07912..f7e71fa3ed20943c3845933167dfb7c42c25fd6a 100644 --- a/zed-rpc/proto/zed.proto +++ b/zed-rpc/proto/zed.proto @@ -67,11 +67,13 @@ message OpenFileResponse { } message CloseFile { - uint64 id = 1; + uint64 worktree_id = 1; + uint64 id = 2; } message OpenBuffer { - uint64 id = 1; + uint64 worktree_id = 1; + uint64 id = 2; } message OpenBufferResponse { diff --git a/zed-rpc/src/peer.rs b/zed-rpc/src/peer.rs index dbd72bdec32f0d32e25ebbc30d779539bb9009d8..532269fdef8fc2a7f2bbb1e32907c2bec23a800a 100644 --- a/zed-rpc/src/peer.rs +++ b/zed-rpc/src/peer.rs @@ -310,6 +310,28 @@ impl Peer { } } + pub fn forward_send( + self: &Arc, + sender_id: ConnectionId, + receiver_id: ConnectionId, + message: T, + ) -> impl Future> { + let this = self.clone(); + async move { + let connection = this.connection(receiver_id).await?; + let message_id = connection + .next_message_id + .fetch_add(1, atomic::Ordering::SeqCst); + connection + .writer + .lock() + .await + .write_message(&message.into_envelope(message_id, None, Some(sender_id.0))) + .await?; + Ok(()) + } + } + pub fn respond( self: &Arc, receipt: Receipt, diff --git a/zed/src/worktree.rs b/zed/src/worktree.rs index a1f54520dab25190601529805ed6d20f9e316307..766c85f0650ea5e7afd01e42d2ab4baae093c059 100644 --- a/zed/src/worktree.rs +++ b/zed/src/worktree.rs @@ -142,6 +142,7 @@ struct FileHandleState { path: Arc, is_deleted: bool, mtime: Duration, + worktree_id: usize, id: u64, rpc: Option<(ConnectionId, rpc::Client)>, } @@ -150,8 +151,12 @@ impl Drop for FileHandleState { fn drop(&mut self) { if let Some((connection_id, rpc)) = self.rpc.take() { let id = self.id; + let worktree_id = self.worktree_id as u64; smol::spawn(async move { - if let Err(error) = rpc.send(connection_id, proto::CloseFile { id }).await { + if let Err(error) = rpc + .send(connection_id, proto::CloseFile { worktree_id, id }) + .await + { log::warn!("error closing file {}: {}", id, error); } }) @@ -658,9 +663,12 @@ impl FileHandle { Worktree::Remote(worktree) => { let state = self.state.lock(); let id = state.id; + let worktree_id = worktree.id as u64; let (connection_id, rpc) = state.rpc.clone().unwrap(); cx.background_executor().spawn(async move { - let response = rpc.request(connection_id, proto::OpenBuffer { id }).await?; + let response = rpc + .request(connection_id, proto::OpenBuffer { worktree_id, id }) + .await?; let buffer = response .buffer .ok_or_else(|| anyhow!("buffer must be present"))?; @@ -1458,6 +1466,7 @@ impl WorktreeHandle for ModelHandle { let tree = self.read(cx); match tree { Worktree::Local(tree) => { + let worktree_id = handle.id(); let abs_path = tree.absolutize(&path); cx.spawn(|cx| async move { let mtime = cx @@ -1479,6 +1488,7 @@ impl WorktreeHandle for ModelHandle { path: entry.path().clone(), is_deleted: false, mtime, + worktree_id, id, rpc: None, } @@ -1487,6 +1497,7 @@ impl WorktreeHandle for ModelHandle { path: path.clone(), is_deleted: !tree.path_is_pending(&path), mtime, + worktree_id, id, rpc: None, } @@ -1538,6 +1549,7 @@ impl WorktreeHandle for ModelHandle { path, is_deleted, mtime: Duration::from_secs(response.mtime), + worktree_id, id: response.id, rpc: Some((connection_id, rpc)), }));