Expose `Worktree::{peers,replica_id}`

Antonio Scandurra created

Change summary

zed/src/worktree.rs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

Detailed changes

zed/src/worktree.rs 🔗

@@ -172,6 +172,13 @@ impl Worktree {
         }
     }
 
+    pub fn replica_id(&self) -> ReplicaId {
+        match self {
+            Worktree::Local(_) => 0,
+            Worktree::Remote(worktree) => worktree.replica_id,
+        }
+    }
+
     pub fn add_guest(
         &mut self,
         envelope: TypedEnvelope<proto::AddGuest>,
@@ -194,6 +201,13 @@ impl Worktree {
         }
     }
 
+    pub fn peers(&self) -> &HashMap<PeerId, ReplicaId> {
+        match self {
+            Worktree::Local(worktree) => &worktree.peers,
+            Worktree::Remote(worktree) => &worktree.peers,
+        }
+    }
+
     pub fn open_buffer(
         &mut self,
         path: impl AsRef<Path>,
@@ -464,6 +478,7 @@ impl LocalWorktree {
             .ok_or_else(|| anyhow!("empty peer"))?;
         self.peers
             .insert(PeerId(guest.peer_id), guest.replica_id as ReplicaId);
+        cx.notify();
         Ok(())
     }
 
@@ -483,6 +498,7 @@ impl LocalWorktree {
                 buffer.update(cx, |buffer, cx| buffer.remove_guest(replica_id, cx));
             }
         }
+        cx.notify();
         Ok(())
     }
 
@@ -910,6 +926,7 @@ impl RemoteWorktree {
             .ok_or_else(|| anyhow!("empty peer"))?;
         self.peers
             .insert(PeerId(guest.peer_id), guest.replica_id as ReplicaId);
+        cx.notify();
         Ok(())
     }
 
@@ -928,6 +945,7 @@ impl RemoteWorktree {
                 buffer.update(cx, |buffer, cx| buffer.remove_guest(replica_id, cx));
             }
         }
+        cx.notify();
         Ok(())
     }
 }