WIP - start restructuring collaboration around entire projects
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
88d663a253
commit
c41b958829
8 changed files with 771 additions and 561 deletions
|
@ -3,18 +3,20 @@ mod ignore;
|
|||
mod worktree;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use client::{Client, UserStore};
|
||||
use client::{proto, Client, PeerId, TypedEnvelope, User, UserStore};
|
||||
use clock::ReplicaId;
|
||||
use collections::HashMap;
|
||||
use futures::Future;
|
||||
use fuzzy::{PathMatch, PathMatchCandidate, PathMatchCandidateSet};
|
||||
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
||||
use gpui::{AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, Task};
|
||||
use language::{Buffer, DiagnosticEntry, LanguageRegistry};
|
||||
use lsp::DiagnosticSeverity;
|
||||
use postage::{prelude::Stream, sink::Sink, watch};
|
||||
use std::{
|
||||
path::Path,
|
||||
sync::{atomic::AtomicBool, Arc},
|
||||
};
|
||||
use util::TryFutureExt as _;
|
||||
use util::{ResultExt, TryFutureExt as _};
|
||||
|
||||
pub use fs::*;
|
||||
pub use worktree::*;
|
||||
|
@ -27,6 +29,29 @@ pub struct Project {
|
|||
client: Arc<client::Client>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
fs: Arc<dyn Fs>,
|
||||
client_state: ProjectClientState,
|
||||
collaborators: HashMap<PeerId, Collaborator>,
|
||||
subscriptions: Vec<client::Subscription>,
|
||||
}
|
||||
|
||||
enum ProjectClientState {
|
||||
Local {
|
||||
is_shared: bool,
|
||||
remote_id_tx: watch::Sender<Option<u64>>,
|
||||
remote_id_rx: watch::Receiver<Option<u64>>,
|
||||
_maintain_remote_id_task: Task<Option<()>>,
|
||||
},
|
||||
Remote {
|
||||
remote_id: u64,
|
||||
replica_id: ReplicaId,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Collaborator {
|
||||
pub user: Arc<User>,
|
||||
pub peer_id: PeerId,
|
||||
pub replica_id: ReplicaId,
|
||||
}
|
||||
|
||||
pub enum Event {
|
||||
|
@ -80,14 +105,46 @@ pub struct ProjectEntry {
|
|||
}
|
||||
|
||||
impl Project {
|
||||
pub fn new(
|
||||
pub fn local(
|
||||
languages: Arc<LanguageRegistry>,
|
||||
client: Arc<Client>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
fs: Arc<dyn Fs>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Self {
|
||||
let (remote_id_tx, remote_id_rx) = watch::channel();
|
||||
let _maintain_remote_id_task = cx.spawn_weak({
|
||||
let rpc = client.clone();
|
||||
move |this, cx| {
|
||||
async move {
|
||||
let mut status = rpc.status();
|
||||
while let Some(status) = status.recv().await {
|
||||
if let Some(this) = this.upgrade(&cx) {
|
||||
let remote_id = if let client::Status::Connected { .. } = status {
|
||||
let response = rpc.request(proto::RegisterProject {}).await?;
|
||||
Some(response.project_id)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
this.update(&mut cx, |this, cx| this.set_remote_id(remote_id, cx));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
.log_err()
|
||||
}
|
||||
});
|
||||
|
||||
Self {
|
||||
worktrees: Default::default(),
|
||||
collaborators: Default::default(),
|
||||
client_state: ProjectClientState::Local {
|
||||
is_shared: false,
|
||||
remote_id_tx,
|
||||
remote_id_rx,
|
||||
_maintain_remote_id_task,
|
||||
},
|
||||
subscriptions: Vec::new(),
|
||||
active_worktree: None,
|
||||
active_entry: None,
|
||||
languages,
|
||||
|
@ -97,9 +154,120 @@ impl Project {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn open_remote(
|
||||
remote_id: u64,
|
||||
languages: Arc<LanguageRegistry>,
|
||||
client: Arc<Client>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
fs: Arc<dyn Fs>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Result<ModelHandle<Self>> {
|
||||
client.authenticate_and_connect(&cx).await?;
|
||||
|
||||
let response = client
|
||||
.request(proto::JoinProject {
|
||||
project_id: remote_id,
|
||||
})
|
||||
.await?;
|
||||
|
||||
let replica_id = response.replica_id as ReplicaId;
|
||||
|
||||
let mut worktrees = Vec::new();
|
||||
for worktree in response.worktrees {
|
||||
worktrees.push(
|
||||
Worktree::remote(
|
||||
remote_id,
|
||||
replica_id,
|
||||
worktree,
|
||||
client.clone(),
|
||||
user_store.clone(),
|
||||
languages.clone(),
|
||||
cx,
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
}
|
||||
|
||||
let user_ids = response
|
||||
.collaborators
|
||||
.iter()
|
||||
.map(|peer| peer.user_id)
|
||||
.collect();
|
||||
user_store
|
||||
.update(cx, |user_store, cx| user_store.load_users(user_ids, cx))
|
||||
.await?;
|
||||
let mut collaborators = HashMap::default();
|
||||
for message in response.collaborators {
|
||||
let collaborator = Collaborator::from_proto(message, &user_store, cx).await?;
|
||||
collaborators.insert(collaborator.peer_id, collaborator);
|
||||
}
|
||||
|
||||
Ok(cx.add_model(|cx| Self {
|
||||
worktrees,
|
||||
active_worktree: None,
|
||||
active_entry: None,
|
||||
collaborators,
|
||||
languages,
|
||||
user_store,
|
||||
fs,
|
||||
subscriptions: vec![
|
||||
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_register_worktree),
|
||||
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),
|
||||
],
|
||||
client,
|
||||
client_state: ProjectClientState::Remote {
|
||||
remote_id,
|
||||
replica_id,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
fn set_remote_id(&mut self, remote_id: Option<u64>, cx: &mut ModelContext<Self>) {
|
||||
if let ProjectClientState::Local { remote_id_tx, .. } = &mut self.client_state {
|
||||
cx.foreground().spawn(remote_id_tx.send(remote_id)).detach();
|
||||
}
|
||||
|
||||
for worktree in &self.worktrees {
|
||||
worktree.update(cx, |worktree, cx| {
|
||||
if let Some(worktree) = worktree.as_local_mut() {
|
||||
worktree.set_project_remote_id(remote_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
self.subscriptions.clear();
|
||||
if let Some(remote_id) = remote_id {
|
||||
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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remote_id(&self) -> Option<u64> {
|
||||
match &self.client_state {
|
||||
ProjectClientState::Local { remote_id_rx, .. } => *remote_id_rx.borrow(),
|
||||
ProjectClientState::Remote { remote_id, .. } => Some(*remote_id),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replica_id(&self, cx: &AppContext) -> ReplicaId {
|
||||
// TODO
|
||||
self.worktrees.first().unwrap().read(cx).replica_id()
|
||||
match &self.client_state {
|
||||
ProjectClientState::Local { .. } => 0,
|
||||
ProjectClientState::Remote { replica_id, .. } => *replica_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collaborators(&self) -> &HashMap<PeerId, Collaborator> {
|
||||
&self.collaborators
|
||||
}
|
||||
|
||||
pub fn worktrees(&self) -> &[ModelHandle<Worktree>] {
|
||||
|
@ -113,6 +281,40 @@ impl Project {
|
|||
.cloned()
|
||||
}
|
||||
|
||||
pub fn share(&self, cx: &mut ModelContext<Self>) -> Task<anyhow::Result<()>> {
|
||||
let rpc = self.client.clone();
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let remote_id = this.update(&mut cx, |this, cx| {
|
||||
if let ProjectClientState::Local {
|
||||
is_shared,
|
||||
remote_id_rx,
|
||||
..
|
||||
} = &mut this.client_state
|
||||
{
|
||||
*is_shared = true;
|
||||
Ok(*remote_id_rx.borrow())
|
||||
} else {
|
||||
Err(anyhow!("can't share a remote project"))
|
||||
}
|
||||
})?;
|
||||
|
||||
let remote_id = remote_id.ok_or_else(|| anyhow!("no project id"))?;
|
||||
rpc.send(proto::ShareProject {
|
||||
project_id: remote_id,
|
||||
})
|
||||
.await?;
|
||||
|
||||
this.update(&mut cx, |this, cx| {
|
||||
for worktree in &this.worktrees {
|
||||
worktree.update(cx, |worktree, cx| {
|
||||
worktree.as_local_mut().unwrap().share(cx).detach();
|
||||
});
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn open_buffer(
|
||||
&self,
|
||||
path: ProjectPath,
|
||||
|
@ -139,6 +341,24 @@ impl Project {
|
|||
let worktree =
|
||||
Worktree::open_local(client, user_store, path, fs, languages, &mut cx).await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
if let Some(project_id) = this.remote_id() {
|
||||
worktree.update(cx, |worktree, cx| {
|
||||
worktree
|
||||
.as_local_mut()
|
||||
.unwrap()
|
||||
.set_project_remote_id(Some(project_id));
|
||||
cx.foreground().spawn(
|
||||
client
|
||||
.request(proto::RegisterWorktree {
|
||||
project_id,
|
||||
root_name: worktree.root_name().to_string(),
|
||||
authorized_logins: worktree.authorized_logins(),
|
||||
worktree_id: worktree.id() as u64,
|
||||
})
|
||||
.log_err(),
|
||||
);
|
||||
});
|
||||
}
|
||||
this.add_worktree(worktree.clone(), cx);
|
||||
});
|
||||
Ok(worktree)
|
||||
|
@ -154,10 +374,8 @@ impl Project {
|
|||
let languages = self.languages.clone();
|
||||
let user_store = self.user_store.clone();
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
rpc.authenticate_and_connect(&cx).await?;
|
||||
let worktree =
|
||||
Worktree::open_remote(rpc.clone(), remote_id, languages, user_store, &mut cx)
|
||||
.await?;
|
||||
Worktree::remote(rpc.clone(), remote_id, languages, user_store, &mut cx).await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
cx.subscribe(&worktree, move |this, _, event, cx| match event {
|
||||
worktree::Event::Closed => {
|
||||
|
@ -304,6 +522,116 @@ impl Project {
|
|||
}
|
||||
}
|
||||
|
||||
// RPC message handlers
|
||||
|
||||
fn handle_add_collaborator(
|
||||
&mut self,
|
||||
mut envelope: TypedEnvelope<proto::AddProjectCollaborator>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
let user_store = self.user_store.clone();
|
||||
let collaborator = envelope
|
||||
.payload
|
||||
.collaborator
|
||||
.take()
|
||||
.ok_or_else(|| anyhow!("empty collaborator"))?;
|
||||
|
||||
cx.spawn(|this, mut cx| {
|
||||
async move {
|
||||
let collaborator =
|
||||
Collaborator::from_proto(collaborator, &user_store, &mut cx).await?;
|
||||
this.collaborators
|
||||
.insert(collaborator.peer_id, collaborator);
|
||||
cx.notify();
|
||||
Ok(())
|
||||
}
|
||||
.log_err()
|
||||
})
|
||||
.detach();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_remove_collaborator(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::RemoveProjectCollaborator>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
let peer_id = PeerId(envelope.payload.peer_id);
|
||||
let replica_id = self
|
||||
.collaborators
|
||||
.remove(&peer_id)
|
||||
.ok_or_else(|| anyhow!("unknown peer {:?}", peer_id))?
|
||||
.replica_id;
|
||||
for worktree in &self.worktrees {
|
||||
worktree.update(cx, |worktree, cx| {
|
||||
worktree.remove_collaborator(peer_id, replica_id, cx);
|
||||
})
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_register_worktree(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::RegisterWorktree>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
let peer_id = PeerId(envelope.payload.peer_id);
|
||||
let replica_id = self
|
||||
.collaborators
|
||||
.remove(&peer_id)
|
||||
.ok_or_else(|| anyhow!("unknown peer {:?}", peer_id))?
|
||||
.replica_id;
|
||||
for worktree in &self.worktrees {
|
||||
worktree.update(cx, |worktree, cx| {
|
||||
worktree.remove_collaborator(peer_id, replica_id, cx);
|
||||
})
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_update_worktree(
|
||||
&mut self,
|
||||
mut envelope: TypedEnvelope<proto::UpdateWorktree>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
if let Some(worktree) = self.worktree_for_id(envelope.payload.worktree_id as usize) {
|
||||
worktree
|
||||
.as_remote_mut()
|
||||
.unwrap()
|
||||
.update_from_remote(envelope, cx);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_update_buffer(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::UpdateBuffer>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
if let Some(worktree) = self.worktree_for_id(envelope.payload.worktree_id as usize) {
|
||||
worktree.handle_update_buffer(envelope, cx)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_buffer_saved(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::BufferSaved>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
if let Some(worktree) = self.worktree_for_id(envelope.payload.worktree_id as usize) {
|
||||
worktree.handle_buffer_saved(envelope, cx);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn match_paths<'a>(
|
||||
&self,
|
||||
query: &'a str,
|
||||
|
@ -400,6 +728,38 @@ impl<'a> Iterator for CandidateSetIter<'a> {
|
|||
|
||||
impl Entity for Project {
|
||||
type Event = Event;
|
||||
|
||||
fn release(&mut self, cx: &mut gpui::MutableAppContext) {
|
||||
if let Some(project_id) = *self.remote_id.borrow() {
|
||||
let rpc = self.client.clone();
|
||||
cx.spawn(|_| async move {
|
||||
if let Err(err) = rpc.send(proto::UnregisterProject { project_id }).await {
|
||||
log::error!("error unregistering project: {}", err);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Collaborator {
|
||||
fn from_proto(
|
||||
message: proto::Collaborator,
|
||||
user_store: &ModelHandle<UserStore>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> impl Future<Output = Result<Self>> {
|
||||
let user = user_store.update(cx, |user_store, cx| {
|
||||
user_store.fetch_user(message.user_id, cx)
|
||||
});
|
||||
|
||||
async move {
|
||||
Ok(Self {
|
||||
peer_id: PeerId(message.peer_id),
|
||||
user: user.await?,
|
||||
replica_id: message.replica_id as ReplicaId,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -514,6 +874,6 @@ mod tests {
|
|||
let client = client::Client::new();
|
||||
let http_client = FakeHttpClient::new(|_| async move { Ok(ServerResponse::new(404)) });
|
||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
||||
cx.add_model(|_| Project::new(languages, client, user_store, fs))
|
||||
cx.add_model(|cx| Project::new(languages, client, user_store, fs, cx))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use super::{
|
|||
};
|
||||
use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use client::{proto, Client, PeerId, TypedEnvelope, User, UserStore};
|
||||
use client::{proto, Client, PeerId, TypedEnvelope, UserStore};
|
||||
use clock::ReplicaId;
|
||||
use collections::{hash_map, HashMap};
|
||||
use futures::{Stream, StreamExt};
|
||||
|
@ -66,62 +66,9 @@ pub enum Event {
|
|||
Closed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Collaborator {
|
||||
pub user: Arc<User>,
|
||||
pub peer_id: PeerId,
|
||||
pub replica_id: ReplicaId,
|
||||
}
|
||||
|
||||
impl Collaborator {
|
||||
fn from_proto(
|
||||
message: proto::Collaborator,
|
||||
user_store: &ModelHandle<UserStore>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> impl Future<Output = Result<Self>> {
|
||||
let user = user_store.update(cx, |user_store, cx| {
|
||||
user_store.fetch_user(message.user_id, cx)
|
||||
});
|
||||
|
||||
async move {
|
||||
Ok(Self {
|
||||
peer_id: PeerId(message.peer_id),
|
||||
user: user.await?,
|
||||
replica_id: message.replica_id as ReplicaId,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for Worktree {
|
||||
type Event = Event;
|
||||
|
||||
fn release(&mut self, cx: &mut MutableAppContext) {
|
||||
match self {
|
||||
Self::Local(tree) => {
|
||||
if let Some(worktree_id) = *tree.remote_id.borrow() {
|
||||
let rpc = tree.client.clone();
|
||||
cx.spawn(|_| async move {
|
||||
if let Err(err) = rpc.send(proto::CloseWorktree { worktree_id }).await {
|
||||
log::error!("error closing worktree: {}", err);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
Self::Remote(tree) => {
|
||||
let rpc = tree.client.clone();
|
||||
let worktree_id = tree.remote_id;
|
||||
cx.spawn(|_| async move {
|
||||
if let Err(err) = rpc.send(proto::LeaveWorktree { worktree_id }).await {
|
||||
log::error!("error closing worktree: {}", err);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn app_will_quit(
|
||||
&mut self,
|
||||
_: &mut MutableAppContext,
|
||||
|
@ -172,32 +119,16 @@ impl Worktree {
|
|||
Ok(tree)
|
||||
}
|
||||
|
||||
pub async fn open_remote(
|
||||
client: Arc<Client>,
|
||||
id: u64,
|
||||
languages: Arc<LanguageRegistry>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Result<ModelHandle<Self>> {
|
||||
let response = client
|
||||
.request(proto::JoinWorktree { worktree_id: id })
|
||||
.await?;
|
||||
Worktree::remote(response, client, user_store, languages, cx).await
|
||||
}
|
||||
|
||||
async fn remote(
|
||||
join_response: proto::JoinWorktreeResponse,
|
||||
pub async fn remote(
|
||||
project_remote_id: u64,
|
||||
replica_id: ReplicaId,
|
||||
worktree: proto::Worktree,
|
||||
client: Arc<Client>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
languages: Arc<LanguageRegistry>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Result<ModelHandle<Self>> {
|
||||
let worktree = join_response
|
||||
.worktree
|
||||
.ok_or_else(|| anyhow!("empty worktree"))?;
|
||||
|
||||
let remote_id = worktree.id;
|
||||
let replica_id = join_response.replica_id as ReplicaId;
|
||||
let root_char_bag: CharBag = worktree
|
||||
.root_name
|
||||
.chars()
|
||||
|
@ -232,20 +163,6 @@ impl Worktree {
|
|||
})
|
||||
.await;
|
||||
|
||||
let user_ids = join_response
|
||||
.collaborators
|
||||
.iter()
|
||||
.map(|peer| peer.user_id)
|
||||
.collect();
|
||||
user_store
|
||||
.update(cx, |user_store, cx| user_store.load_users(user_ids, cx))
|
||||
.await?;
|
||||
let mut collaborators = HashMap::default();
|
||||
for message in join_response.collaborators {
|
||||
let collaborator = Collaborator::from_proto(message, &user_store, cx).await?;
|
||||
collaborators.insert(collaborator.peer_id, collaborator);
|
||||
}
|
||||
|
||||
let worktree = cx.update(|cx| {
|
||||
cx.add_model(|cx: &mut ModelContext<Worktree>| {
|
||||
let snapshot = Snapshot {
|
||||
|
@ -290,16 +207,8 @@ impl Worktree {
|
|||
.detach();
|
||||
}
|
||||
|
||||
let _subscriptions = vec![
|
||||
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),
|
||||
client.subscribe_to_entity(remote_id, cx, Self::handle_update_buffer),
|
||||
client.subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved),
|
||||
client.subscribe_to_entity(remote_id, cx, Self::handle_unshare),
|
||||
];
|
||||
|
||||
Worktree::Remote(RemoteWorktree {
|
||||
project_remote_id,
|
||||
remote_id,
|
||||
replica_id,
|
||||
snapshot,
|
||||
|
@ -309,11 +218,9 @@ impl Worktree {
|
|||
loading_buffers: Default::default(),
|
||||
open_buffers: Default::default(),
|
||||
diagnostic_summaries: HashMap::default(),
|
||||
collaborators,
|
||||
queued_operations: Default::default(),
|
||||
languages,
|
||||
user_store,
|
||||
_subscriptions,
|
||||
})
|
||||
})
|
||||
});
|
||||
|
@ -359,6 +266,25 @@ impl Worktree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn authorized_logins(&self) -> Vec<String> {
|
||||
match self {
|
||||
Worktree::Local(worktree) => worktree.config.collaborators.clone(),
|
||||
Worktree::Remote(worktree) => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_collaborator(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
replica_id: ReplicaId,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
match self {
|
||||
Worktree::Local(worktree) => worktree.remove_collaborator(peer_id, replica_id, cx),
|
||||
Worktree::Remote(worktree) => worktree.remove_collaborator(peer_id, replica_id, cx),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn languages(&self) -> &Arc<LanguageRegistry> {
|
||||
match self {
|
||||
Worktree::Local(worktree) => &worktree.languages,
|
||||
|
@ -373,59 +299,6 @@ impl Worktree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn handle_add_collaborator(
|
||||
&mut self,
|
||||
mut envelope: TypedEnvelope<proto::AddCollaborator>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
let user_store = self.user_store().clone();
|
||||
let collaborator = envelope
|
||||
.payload
|
||||
.collaborator
|
||||
.take()
|
||||
.ok_or_else(|| anyhow!("empty collaborator"))?;
|
||||
|
||||
cx.spawn(|this, mut cx| {
|
||||
async move {
|
||||
let collaborator =
|
||||
Collaborator::from_proto(collaborator, &user_store, &mut cx).await?;
|
||||
this.update(&mut cx, |this, cx| match this {
|
||||
Worktree::Local(worktree) => worktree.add_collaborator(collaborator, cx),
|
||||
Worktree::Remote(worktree) => worktree.add_collaborator(collaborator, cx),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
.log_err()
|
||||
})
|
||||
.detach();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_remove_collaborator(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::RemoveCollaborator>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
match self {
|
||||
Worktree::Local(worktree) => worktree.remove_collaborator(envelope, cx),
|
||||
Worktree::Remote(worktree) => worktree.remove_collaborator(envelope, cx),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_update(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::UpdateWorktree>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> anyhow::Result<()> {
|
||||
self.as_remote_mut()
|
||||
.unwrap()
|
||||
.update_from_remote(envelope, cx)
|
||||
}
|
||||
|
||||
pub fn handle_open_buffer(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::OpenBuffer>,
|
||||
|
@ -463,13 +336,6 @@ impl Worktree {
|
|||
.close_remote_buffer(envelope, cx)
|
||||
}
|
||||
|
||||
pub fn collaborators(&self) -> &HashMap<PeerId, Collaborator> {
|
||||
match self {
|
||||
Worktree::Local(worktree) => &worktree.collaborators,
|
||||
Worktree::Remote(worktree) => &worktree.collaborators,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn diagnostic_summaries<'a>(
|
||||
&'a self,
|
||||
) -> impl Iterator<Item = (Arc<Path>, DiagnosticSummary)> + 'a {
|
||||
|
@ -623,9 +489,12 @@ impl Worktree {
|
|||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
let sender_id = envelope.original_sender_id()?;
|
||||
let buffer = self
|
||||
.as_local()
|
||||
.unwrap()
|
||||
let this = self.as_local().unwrap();
|
||||
let project_id = this
|
||||
.project_remote_id
|
||||
.ok_or_else(|| anyhow!("can't save buffer while disconnected"))?;
|
||||
|
||||
let buffer = this
|
||||
.shared_buffers
|
||||
.get(&sender_id)
|
||||
.and_then(|shared_buffers| shared_buffers.get(&envelope.payload.buffer_id).cloned())
|
||||
|
@ -646,6 +515,7 @@ impl Worktree {
|
|||
rpc.respond(
|
||||
receipt,
|
||||
proto::BufferSaved {
|
||||
project_id,
|
||||
worktree_id,
|
||||
buffer_id,
|
||||
version: (&version).into(),
|
||||
|
@ -689,16 +559,6 @@ impl Worktree {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_unshare(
|
||||
&mut self,
|
||||
_: TypedEnvelope<proto::UnshareWorktree>,
|
||||
_: Arc<Client>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
cx.emit(Event::Closed);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn poll_snapshot(&mut self, cx: &mut ModelContext<Self>) {
|
||||
match self {
|
||||
Self::Local(worktree) => {
|
||||
|
@ -905,17 +765,19 @@ impl Worktree {
|
|||
operation: Operation,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
if let Some((rpc, remote_id)) = match self {
|
||||
if let Some((rpc, project_id)) = match self {
|
||||
Worktree::Local(worktree) => worktree
|
||||
.remote_id
|
||||
.borrow()
|
||||
.project_remote_id
|
||||
.map(|id| (worktree.client.clone(), id)),
|
||||
Worktree::Remote(worktree) => Some((worktree.client.clone(), worktree.remote_id)),
|
||||
Worktree::Remote(worktree) => {
|
||||
Some((worktree.client.clone(), worktree.project_remote_id))
|
||||
}
|
||||
} {
|
||||
cx.spawn(|worktree, mut cx| async move {
|
||||
if let Err(error) = rpc
|
||||
.request(proto::UpdateBuffer {
|
||||
worktree_id: remote_id,
|
||||
project_id,
|
||||
worktree_id: worktree.id() as u64,
|
||||
buffer_id,
|
||||
operations: vec![language::proto::serialize_operation(&operation)],
|
||||
})
|
||||
|
@ -956,16 +818,14 @@ pub struct LocalWorktree {
|
|||
background_snapshot: Arc<Mutex<Snapshot>>,
|
||||
last_scan_state_rx: watch::Receiver<ScanState>,
|
||||
_background_scanner_task: Option<Task<()>>,
|
||||
_maintain_remote_id_task: Task<Option<()>>,
|
||||
project_remote_id: Option<u64>,
|
||||
poll_task: Option<Task<()>>,
|
||||
remote_id: watch::Receiver<Option<u64>>,
|
||||
share: Option<ShareState>,
|
||||
loading_buffers: LoadingBuffers,
|
||||
open_buffers: HashMap<usize, WeakModelHandle<Buffer>>,
|
||||
shared_buffers: HashMap<PeerId, HashMap<u64, ModelHandle<Buffer>>>,
|
||||
diagnostics: HashMap<Arc<Path>, Vec<DiagnosticEntry<PointUtf16>>>,
|
||||
diagnostic_summaries: HashMap<Arc<Path>, DiagnosticSummary>,
|
||||
collaborators: HashMap<PeerId, Collaborator>,
|
||||
queued_operations: Vec<(u64, Operation)>,
|
||||
languages: Arc<LanguageRegistry>,
|
||||
client: Arc<Client>,
|
||||
|
@ -976,10 +836,10 @@ pub struct LocalWorktree {
|
|||
|
||||
struct ShareState {
|
||||
snapshots_tx: Sender<Snapshot>,
|
||||
_subscriptions: Vec<client::Subscription>,
|
||||
}
|
||||
|
||||
pub struct RemoteWorktree {
|
||||
project_remote_id: u64,
|
||||
remote_id: u64,
|
||||
snapshot: Snapshot,
|
||||
snapshot_rx: watch::Receiver<Snapshot>,
|
||||
|
@ -988,12 +848,10 @@ pub struct RemoteWorktree {
|
|||
replica_id: ReplicaId,
|
||||
loading_buffers: LoadingBuffers,
|
||||
open_buffers: HashMap<usize, RemoteBuffer>,
|
||||
collaborators: HashMap<PeerId, Collaborator>,
|
||||
diagnostic_summaries: HashMap<Arc<Path>, DiagnosticSummary>,
|
||||
languages: Arc<LanguageRegistry>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
queued_operations: Vec<(u64, Operation)>,
|
||||
_subscriptions: Vec<client::Subscription>,
|
||||
}
|
||||
|
||||
type LoadingBuffers = HashMap<
|
||||
|
@ -1061,48 +919,13 @@ impl LocalWorktree {
|
|||
);
|
||||
}
|
||||
|
||||
let (mut remote_id_tx, remote_id_rx) = watch::channel();
|
||||
let _maintain_remote_id_task = cx.spawn_weak({
|
||||
let rpc = client.clone();
|
||||
move |this, cx| {
|
||||
async move {
|
||||
let mut status = rpc.status();
|
||||
while let Some(status) = status.recv().await {
|
||||
if let Some(this) = this.upgrade(&cx) {
|
||||
let remote_id = if let client::Status::Connected { .. } = status {
|
||||
let authorized_logins = this.read_with(&cx, |this, _| {
|
||||
this.as_local().unwrap().config.collaborators.clone()
|
||||
});
|
||||
let response = rpc
|
||||
.request(proto::OpenWorktree {
|
||||
root_name: root_name.clone(),
|
||||
authorized_logins,
|
||||
})
|
||||
.await?;
|
||||
|
||||
Some(response.worktree_id)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if remote_id_tx.send(remote_id).await.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
.log_err()
|
||||
}
|
||||
});
|
||||
|
||||
let tree = Self {
|
||||
snapshot: snapshot.clone(),
|
||||
config,
|
||||
remote_id: remote_id_rx,
|
||||
project_remote_id: None,
|
||||
background_snapshot: Arc::new(Mutex::new(snapshot)),
|
||||
last_scan_state_rx,
|
||||
_background_scanner_task: None,
|
||||
_maintain_remote_id_task,
|
||||
share: None,
|
||||
poll_task: None,
|
||||
loading_buffers: Default::default(),
|
||||
|
@ -1111,7 +934,6 @@ impl LocalWorktree {
|
|||
diagnostics: Default::default(),
|
||||
diagnostic_summaries: Default::default(),
|
||||
queued_operations: Default::default(),
|
||||
collaborators: Default::default(),
|
||||
languages,
|
||||
client,
|
||||
user_store,
|
||||
|
@ -1152,6 +974,10 @@ impl LocalWorktree {
|
|||
Ok((tree, scan_states_tx))
|
||||
}
|
||||
|
||||
pub fn set_project_remote_id(&mut self, id: Option<u64>) {
|
||||
self.project_remote_id = id;
|
||||
}
|
||||
|
||||
pub fn languages(&self) -> &LanguageRegistry {
|
||||
&self.languages
|
||||
}
|
||||
|
@ -1297,27 +1123,12 @@ impl LocalWorktree {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_collaborator(
|
||||
&mut self,
|
||||
collaborator: Collaborator,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) {
|
||||
self.collaborators
|
||||
.insert(collaborator.peer_id, collaborator);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn remove_collaborator(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::RemoveCollaborator>,
|
||||
peer_id: PeerId,
|
||||
replica_id: ReplicaId,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) -> Result<()> {
|
||||
let peer_id = PeerId(envelope.payload.peer_id);
|
||||
let replica_id = self
|
||||
.collaborators
|
||||
.remove(&peer_id)
|
||||
.ok_or_else(|| anyhow!("unknown peer {:?}", peer_id))?
|
||||
.replica_id;
|
||||
) {
|
||||
self.shared_buffers.remove(&peer_id);
|
||||
for (_, buffer) in &self.open_buffers {
|
||||
if let Some(buffer) = buffer.upgrade(cx) {
|
||||
|
@ -1325,8 +1136,6 @@ impl LocalWorktree {
|
|||
}
|
||||
}
|
||||
cx.notify();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn scan_complete(&self) -> impl Future<Output = ()> {
|
||||
|
@ -1339,22 +1148,6 @@ impl LocalWorktree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn remote_id(&self) -> Option<u64> {
|
||||
*self.remote_id.borrow()
|
||||
}
|
||||
|
||||
pub fn next_remote_id(&self) -> impl Future<Output = Option<u64>> {
|
||||
let mut remote_id = self.remote_id.clone();
|
||||
async move {
|
||||
while let Some(remote_id) = remote_id.recv().await {
|
||||
if remote_id.is_some() {
|
||||
return remote_id;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn is_scanning(&self) -> bool {
|
||||
if let ScanState::Scanning = *self.last_scan_state_rx.borrow() {
|
||||
true
|
||||
|
@ -1456,31 +1249,28 @@ impl LocalWorktree {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn share(&mut self, cx: &mut ModelContext<Worktree>) -> Task<anyhow::Result<u64>> {
|
||||
pub fn share(&mut self, cx: &mut ModelContext<Worktree>) -> Task<anyhow::Result<()>> {
|
||||
let snapshot = self.snapshot();
|
||||
let share_request = self.share_request(cx);
|
||||
let rpc = self.client.clone();
|
||||
let project_id = self.project_remote_id;
|
||||
let worktree_id = cx.model_id() as u64;
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let share_request = if let Some(request) = share_request.await {
|
||||
request
|
||||
} else {
|
||||
return Err(anyhow!("failed to open worktree on the server"));
|
||||
};
|
||||
let project_id = project_id.ok_or_else(|| anyhow!("no project id"))?;
|
||||
|
||||
let remote_id = share_request.worktree.as_ref().unwrap().id;
|
||||
let share_response = rpc.request(share_request).await?;
|
||||
|
||||
log::info!("sharing worktree {:?}", share_response);
|
||||
let (snapshots_to_send_tx, snapshots_to_send_rx) =
|
||||
smol::channel::unbounded::<Snapshot>();
|
||||
|
||||
cx.background()
|
||||
.spawn({
|
||||
let rpc = rpc.clone();
|
||||
async move {
|
||||
let mut prev_snapshot = snapshot;
|
||||
while let Ok(snapshot) = snapshots_to_send_rx.recv().await {
|
||||
let message = snapshot.build_update(&prev_snapshot, remote_id, false);
|
||||
let message = snapshot.build_update(
|
||||
&prev_snapshot,
|
||||
project_id,
|
||||
worktree_id,
|
||||
false,
|
||||
);
|
||||
match rpc.send(message).await {
|
||||
Ok(()) => prev_snapshot = snapshot,
|
||||
Err(err) => log::error!("error sending snapshot diff {}", err),
|
||||
|
@ -1491,64 +1281,32 @@ impl LocalWorktree {
|
|||
.detach();
|
||||
|
||||
this.update(&mut cx, |worktree, cx| {
|
||||
let _subscriptions = vec![
|
||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_add_collaborator),
|
||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_remove_collaborator),
|
||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_open_buffer),
|
||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_close_buffer),
|
||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_update_buffer),
|
||||
rpc.subscribe_to_entity(remote_id, cx, Worktree::handle_save_buffer),
|
||||
];
|
||||
|
||||
let worktree = worktree.as_local_mut().unwrap();
|
||||
worktree.share = Some(ShareState {
|
||||
snapshots_tx: snapshots_to_send_tx,
|
||||
_subscriptions,
|
||||
});
|
||||
});
|
||||
|
||||
Ok(remote_id)
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn unshare(&mut self, cx: &mut ModelContext<Worktree>) {
|
||||
self.share.take();
|
||||
let rpc = self.client.clone();
|
||||
let remote_id = self.remote_id();
|
||||
cx.foreground()
|
||||
.spawn(
|
||||
async move {
|
||||
if let Some(worktree_id) = remote_id {
|
||||
rpc.send(proto::UnshareWorktree { worktree_id }).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
.log_err(),
|
||||
)
|
||||
.detach()
|
||||
}
|
||||
|
||||
fn share_request(&self, cx: &mut ModelContext<Worktree>) -> Task<Option<proto::ShareWorktree>> {
|
||||
let remote_id = self.next_remote_id();
|
||||
fn to_proto(&self, cx: &mut ModelContext<Worktree>) -> impl Future<Output = proto::Worktree> {
|
||||
let id = cx.model_id() as u64;
|
||||
let snapshot = self.snapshot();
|
||||
let root_name = self.root_name.clone();
|
||||
cx.background().spawn(async move {
|
||||
remote_id.await.map(|id| {
|
||||
let entries = snapshot
|
||||
async move {
|
||||
proto::Worktree {
|
||||
id,
|
||||
root_name,
|
||||
entries: snapshot
|
||||
.entries_by_path
|
||||
.cursor::<()>()
|
||||
.filter(|e| !e.is_ignored)
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
proto::ShareWorktree {
|
||||
worktree: Some(proto::Worktree {
|
||||
id,
|
||||
root_name,
|
||||
entries,
|
||||
}),
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1617,6 +1375,7 @@ impl RemoteWorktree {
|
|||
) -> Task<Result<ModelHandle<Buffer>>> {
|
||||
let rpc = self.client.clone();
|
||||
let replica_id = self.replica_id;
|
||||
let project_id = self.project_remote_id;
|
||||
let remote_worktree_id = self.remote_id;
|
||||
let root_path = self.snapshot.abs_path.clone();
|
||||
let path: Arc<Path> = Arc::from(path);
|
||||
|
@ -1629,6 +1388,7 @@ impl RemoteWorktree {
|
|||
.ok_or_else(|| anyhow!("file does not exist"))?;
|
||||
let response = rpc
|
||||
.request(proto::OpenBuffer {
|
||||
project_id,
|
||||
worktree_id: remote_worktree_id as u64,
|
||||
path: path_string,
|
||||
})
|
||||
|
@ -1669,10 +1429,6 @@ impl RemoteWorktree {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn remote_id(&self) -> u64 {
|
||||
self.remote_id
|
||||
}
|
||||
|
||||
pub fn close_all_buffers(&mut self, cx: &mut MutableAppContext) {
|
||||
for (_, buffer) in self.open_buffers.drain() {
|
||||
if let RemoteBuffer::Loaded(buffer) = buffer {
|
||||
|
@ -1703,34 +1459,18 @@ impl RemoteWorktree {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_collaborator(
|
||||
&mut self,
|
||||
collaborator: Collaborator,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) {
|
||||
self.collaborators
|
||||
.insert(collaborator.peer_id, collaborator);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn remove_collaborator(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::RemoveCollaborator>,
|
||||
peer_id: PeerId,
|
||||
replica_id: ReplicaId,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) -> Result<()> {
|
||||
let peer_id = PeerId(envelope.payload.peer_id);
|
||||
let replica_id = self
|
||||
.collaborators
|
||||
.remove(&peer_id)
|
||||
.ok_or_else(|| anyhow!("unknown peer {:?}", peer_id))?
|
||||
.replica_id;
|
||||
) {
|
||||
for (_, buffer) in &self.open_buffers {
|
||||
if let Some(buffer) = buffer.upgrade(cx) {
|
||||
buffer.update(cx, |buffer, cx| buffer.remove_peer(replica_id, cx));
|
||||
}
|
||||
}
|
||||
cx.notify();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1756,6 +1496,7 @@ impl Snapshot {
|
|||
pub fn build_update(
|
||||
&self,
|
||||
other: &Self,
|
||||
project_id: u64,
|
||||
worktree_id: u64,
|
||||
include_ignored: bool,
|
||||
) -> proto::UpdateWorktree {
|
||||
|
@ -1809,9 +1550,10 @@ impl Snapshot {
|
|||
}
|
||||
|
||||
proto::UpdateWorktree {
|
||||
project_id,
|
||||
worktree_id,
|
||||
updated_entries,
|
||||
removed_entries,
|
||||
worktree_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2168,15 +1910,17 @@ impl language::File for File {
|
|||
version: clock::Global,
|
||||
cx: &mut MutableAppContext,
|
||||
) -> Task<Result<(clock::Global, SystemTime)>> {
|
||||
let worktree_id = self.worktree.id() as u64;
|
||||
self.worktree.update(cx, |worktree, cx| match worktree {
|
||||
Worktree::Local(worktree) => {
|
||||
let rpc = worktree.client.clone();
|
||||
let worktree_id = *worktree.remote_id.borrow();
|
||||
let project_id = worktree.project_remote_id;
|
||||
let save = worktree.save(self.path.clone(), text, cx);
|
||||
cx.background().spawn(async move {
|
||||
let entry = save.await?;
|
||||
if let Some(worktree_id) = worktree_id {
|
||||
if let Some(project_id) = project_id {
|
||||
rpc.send(proto::BufferSaved {
|
||||
project_id,
|
||||
worktree_id,
|
||||
buffer_id,
|
||||
version: (&version).into(),
|
||||
|
@ -2189,10 +1933,11 @@ impl language::File for File {
|
|||
}
|
||||
Worktree::Remote(worktree) => {
|
||||
let rpc = worktree.client.clone();
|
||||
let worktree_id = worktree.remote_id;
|
||||
let project_id = worktree.project_remote_id;
|
||||
cx.foreground().spawn(async move {
|
||||
let response = rpc
|
||||
.request(proto::SaveBuffer {
|
||||
project_id,
|
||||
worktree_id,
|
||||
buffer_id,
|
||||
})
|
||||
|
@ -2225,14 +1970,16 @@ impl language::File for File {
|
|||
}
|
||||
|
||||
fn buffer_removed(&self, buffer_id: u64, cx: &mut MutableAppContext) {
|
||||
let worktree_id = self.worktree.id() as u64;
|
||||
self.worktree.update(cx, |worktree, cx| {
|
||||
if let Worktree::Remote(worktree) = worktree {
|
||||
let worktree_id = worktree.remote_id;
|
||||
let project_id = worktree.project_remote_id;
|
||||
let rpc = worktree.client.clone();
|
||||
cx.background()
|
||||
.spawn(async move {
|
||||
if let Err(error) = rpc
|
||||
.send(proto::CloseBuffer {
|
||||
project_id,
|
||||
worktree_id,
|
||||
buffer_id,
|
||||
})
|
||||
|
@ -3370,9 +3117,7 @@ mod tests {
|
|||
// Create a remote copy of this worktree.
|
||||
let initial_snapshot = tree.read_with(&cx, |tree, _| tree.snapshot());
|
||||
let worktree_id = 1;
|
||||
let share_request = tree.update(&mut cx, |tree, cx| {
|
||||
tree.as_local().unwrap().share_request(cx)
|
||||
});
|
||||
let proto_message = tree.update(&mut cx, |tree, cx| tree.as_local().unwrap().to_proto(cx));
|
||||
let open_worktree = server.receive::<proto::OpenWorktree>().await.unwrap();
|
||||
server
|
||||
.respond(
|
||||
|
@ -3383,7 +3128,7 @@ mod tests {
|
|||
|
||||
let remote = Worktree::remote(
|
||||
proto::JoinWorktreeResponse {
|
||||
worktree: share_request.await.unwrap().worktree,
|
||||
worktree: Some(proto_message.await),
|
||||
replica_id: 1,
|
||||
collaborators: Vec::new(),
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue