Expose Worktree::{peers,replica_id}

This commit is contained in:
Antonio Scandurra 2021-07-01 09:36:09 +02:00
parent ed9036f3fc
commit e07065265d

View file

@ -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(())
}
}