From 636931373ee371645cbb6c6177119ad19d8c538e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 20 Dec 2021 18:08:06 -0800 Subject: [PATCH] Add missing RPC handlers for local projects --- crates/project/src/project.rs | 43 ++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 91bdb1e31ca75c4162ae4b8ef50dc41714fb9876..76aec72e907022c60312e3ab8cf858f950065ee8 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -241,13 +241,15 @@ impl Project { self.subscriptions.clear(); if let Some(remote_id) = remote_id { + let client = &self.client; self.subscriptions.extend([ - self.client - .subscribe_to_entity(remote_id, cx, Self::handle_update_worktree), - self.client - .subscribe_to_entity(remote_id, cx, Self::handle_update_buffer), - self.client - .subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved), + client.subscribe_to_entity(remote_id, cx, Self::handle_open_buffer), + client.subscribe_to_entity(remote_id, cx, Self::handle_close_buffer), + client.subscribe_to_entity(remote_id, cx, Self::handle_add_collaborator), + client.subscribe_to_entity(remote_id, cx, Self::handle_remove_collaborator), + client.subscribe_to_entity(remote_id, cx, Self::handle_update_worktree), + client.subscribe_to_entity(remote_id, cx, Self::handle_update_buffer), + client.subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved), ]); } } @@ -637,6 +639,35 @@ impl Project { Ok(()) } + pub fn handle_open_buffer( + &mut self, + envelope: TypedEnvelope, + rpc: Arc, + cx: &mut ModelContext, + ) -> anyhow::Result<()> { + if let Some(worktree) = self.worktree_for_id(envelope.payload.worktree_id as usize) { + return worktree.update(cx, |worktree, cx| { + worktree.handle_open_buffer(envelope, rpc, cx) + }); + } else { + Err(anyhow!("no such worktree")) + } + } + + pub fn handle_close_buffer( + &mut self, + envelope: TypedEnvelope, + rpc: Arc, + cx: &mut ModelContext, + ) -> anyhow::Result<()> { + if let Some(worktree) = self.worktree_for_id(envelope.payload.worktree_id as usize) { + worktree.update(cx, |worktree, cx| { + worktree.handle_close_buffer(envelope, rpc, cx) + })?; + } + Ok(()) + } + pub fn handle_buffer_saved( &mut self, envelope: TypedEnvelope,