Send worktree info only when sharing worktree

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-12-20 11:36:59 -08:00
parent 697e641e8e
commit 614ee4eac7
10 changed files with 200 additions and 208 deletions

View file

@ -11,16 +11,10 @@ use postage::watch;
use theme::Theme; use theme::Theme;
use workspace::{Settings, Workspace}; use workspace::{Settings, Workspace};
action!(JoinWorktree, u64); action!(JoinProject, u64);
action!(LeaveWorktree, u64);
action!(ShareWorktree, u64);
action!(UnshareWorktree, u64);
pub fn init(cx: &mut MutableAppContext) { pub fn init(cx: &mut MutableAppContext) {
cx.add_action(ContactsPanel::share_worktree); cx.add_action(ContactsPanel::join_project);
cx.add_action(ContactsPanel::unshare_worktree);
cx.add_action(ContactsPanel::join_worktree);
cx.add_action(ContactsPanel::leave_worktree);
} }
pub struct ContactsPanel { pub struct ContactsPanel {
@ -63,44 +57,8 @@ impl ContactsPanel {
} }
} }
fn share_worktree( fn join_project(_: &mut Workspace, _: &JoinProject, _: &mut ViewContext<Workspace>) {
workspace: &mut Workspace, todo!();
action: &ShareWorktree,
cx: &mut ViewContext<Workspace>,
) {
workspace
.project()
.update(cx, |p, cx| p.share_worktree(action.0, cx));
}
fn unshare_worktree(
workspace: &mut Workspace,
action: &UnshareWorktree,
cx: &mut ViewContext<Workspace>,
) {
workspace
.project()
.update(cx, |p, cx| p.unshare_worktree(action.0, cx));
}
fn join_worktree(
workspace: &mut Workspace,
action: &JoinWorktree,
cx: &mut ViewContext<Workspace>,
) {
workspace
.project()
.update(cx, |p, cx| p.add_remote_worktree(action.0, cx).detach());
}
fn leave_worktree(
workspace: &mut Workspace,
action: &LeaveWorktree,
cx: &mut ViewContext<Workspace>,
) {
workspace
.project()
.update(cx, |p, cx| p.close_remote_worktree(action.0, cx));
} }
fn update_contacts(&mut self, _: ModelHandle<UserStore>, cx: &mut ViewContext<Self>) { fn update_contacts(&mut self, _: ModelHandle<UserStore>, cx: &mut ViewContext<Self>) {
@ -116,16 +74,12 @@ impl ContactsPanel {
cx: &mut LayoutContext, cx: &mut LayoutContext,
) -> ElementBox { ) -> ElementBox {
let theme = &theme.contacts_panel; let theme = &theme.contacts_panel;
let worktree_count = collaborator.worktrees.len(); let project_count = collaborator.projects.len();
let font_cache = cx.font_cache(); let font_cache = cx.font_cache();
let line_height = theme.unshared_worktree.name.text.line_height(font_cache); let line_height = theme.unshared_project.name.text.line_height(font_cache);
let cap_height = theme.unshared_worktree.name.text.cap_height(font_cache); let cap_height = theme.unshared_project.name.text.cap_height(font_cache);
let baseline_offset = theme let baseline_offset = theme.unshared_project.name.text.baseline_offset(font_cache)
.unshared_worktree + (theme.unshared_project.height - line_height) / 2.;
.name
.text
.baseline_offset(font_cache)
+ (theme.unshared_worktree.height - line_height) / 2.;
let tree_branch_width = theme.tree_branch_width; let tree_branch_width = theme.tree_branch_width;
let tree_branch_color = theme.tree_branch_color; let tree_branch_color = theme.tree_branch_color;
let host_avatar_height = theme let host_avatar_height = theme
@ -161,11 +115,11 @@ impl ContactsPanel {
) )
.with_children( .with_children(
collaborator collaborator
.worktrees .projects
.iter() .iter()
.enumerate() .enumerate()
.map(|(ix, worktree)| { .map(|(ix, project)| {
let worktree_id = worktree.id; let project_id = project.id;
Flex::row() Flex::row()
.with_child( .with_child(
@ -182,7 +136,7 @@ impl ContactsPanel {
vec2f(start_x, start_y), vec2f(start_x, start_y),
vec2f( vec2f(
start_x + tree_branch_width, start_x + tree_branch_width,
if ix + 1 == worktree_count { if ix + 1 == project_count {
end_y end_y
} else { } else {
bounds.max_y() bounds.max_y()
@ -210,28 +164,27 @@ impl ContactsPanel {
.with_child({ .with_child({
let is_host = Some(collaborator.user.id) == current_user_id; let is_host = Some(collaborator.user.id) == current_user_id;
let is_guest = !is_host let is_guest = !is_host
&& worktree && project
.guests .guests
.iter() .iter()
.any(|guest| Some(guest.id) == current_user_id); .any(|guest| Some(guest.id) == current_user_id);
let is_shared = worktree.is_shared; let is_shared = project.is_shared;
MouseEventHandler::new::<ContactsPanel, _, _, _>( MouseEventHandler::new::<ContactsPanel, _, _, _>(
worktree_id as usize, project_id as usize,
cx, cx,
|mouse_state, _| { |mouse_state, _| {
let style = match (worktree.is_shared, mouse_state.hovered) let style = match (project.is_shared, mouse_state.hovered) {
{ (false, false) => &theme.unshared_project,
(false, false) => &theme.unshared_worktree, (false, true) => &theme.hovered_unshared_project,
(false, true) => &theme.hovered_unshared_worktree, (true, false) => &theme.shared_project,
(true, false) => &theme.shared_worktree, (true, true) => &theme.hovered_shared_project,
(true, true) => &theme.hovered_shared_worktree,
}; };
Flex::row() Flex::row()
.with_child( .with_child(
Label::new( Label::new(
worktree.root_name.clone(), project.worktree_root_names.join(", "),
style.name.text.clone(), style.name.text.clone(),
) )
.aligned() .aligned()
@ -240,7 +193,7 @@ impl ContactsPanel {
.with_style(style.name.container) .with_style(style.name.container)
.boxed(), .boxed(),
) )
.with_children(worktree.guests.iter().filter_map( .with_children(project.guests.iter().filter_map(
|participant| { |participant| {
participant.avatar.clone().map(|avatar| { participant.avatar.clone().map(|avatar| {
Image::new(avatar) Image::new(avatar)
@ -268,23 +221,15 @@ impl ContactsPanel {
CursorStyle::Arrow CursorStyle::Arrow
}) })
.on_click(move |cx| { .on_click(move |cx| {
if is_shared { if !is_host && !is_guest {
if is_host { cx.dispatch_action(JoinProject(project_id))
cx.dispatch_action(UnshareWorktree(worktree_id));
} else if is_guest {
cx.dispatch_action(LeaveWorktree(worktree_id));
} else {
cx.dispatch_action(JoinWorktree(worktree_id))
}
} else if is_host {
cx.dispatch_action(ShareWorktree(worktree_id));
} }
}) })
.expanded(1.0) .expanded(1.0)
.boxed() .boxed()
}) })
.constrained() .constrained()
.with_height(theme.unshared_worktree.height) .with_height(theme.unshared_project.height)
.boxed() .boxed()
}), }),
) )

View file

@ -213,7 +213,7 @@ impl workspace::Item for ProjectDiagnostics {
}) })
.detach(); .detach();
ProjectDiagnosticsEditor::new(project.read(cx).replica_id(cx), settings, cx) ProjectDiagnosticsEditor::new(project.read(cx).replica_id(), settings, cx)
} }
fn project_path(&self) -> Option<project::ProjectPath> { fn project_path(&self) -> Option<project::ProjectPath> {

View file

@ -54,6 +54,7 @@ type AnyLocalTask = async_task::Task<Box<dyn Any + 'static>>;
#[must_use] #[must_use]
pub enum Task<T> { pub enum Task<T> {
Ready(Option<T>),
Local { Local {
any_task: AnyLocalTask, any_task: AnyLocalTask,
result_type: PhantomData<T>, result_type: PhantomData<T>,
@ -594,6 +595,10 @@ pub fn deterministic(seed: u64) -> (Rc<Foreground>, Arc<Background>) {
} }
impl<T> Task<T> { impl<T> Task<T> {
pub fn ready(value: T) -> Self {
Self::Ready(Some(value))
}
fn local(any_task: AnyLocalTask) -> Self { fn local(any_task: AnyLocalTask) -> Self {
Self::Local { Self::Local {
any_task, any_task,
@ -603,6 +608,7 @@ impl<T> Task<T> {
pub fn detach(self) { pub fn detach(self) {
match self { match self {
Task::Ready(_) => {}
Task::Local { any_task, .. } => any_task.detach(), Task::Local { any_task, .. } => any_task.detach(),
Task::Send { any_task, .. } => any_task.detach(), Task::Send { any_task, .. } => any_task.detach(),
} }
@ -621,6 +627,7 @@ impl<T: Send> Task<T> {
impl<T: fmt::Debug> fmt::Debug for Task<T> { impl<T: fmt::Debug> fmt::Debug for Task<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Task::Ready(value) => value.fmt(f),
Task::Local { any_task, .. } => any_task.fmt(f), Task::Local { any_task, .. } => any_task.fmt(f),
Task::Send { any_task, .. } => any_task.fmt(f), Task::Send { any_task, .. } => any_task.fmt(f),
} }
@ -632,6 +639,7 @@ impl<T: 'static> Future for Task<T> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match unsafe { self.get_unchecked_mut() } { match unsafe { self.get_unchecked_mut() } {
Task::Ready(value) => Poll::Ready(value.take().unwrap()),
Task::Local { any_task, .. } => { Task::Local { any_task, .. } => {
any_task.poll(cx).map(|value| *value.downcast().unwrap()) any_task.poll(cx).map(|value| *value.downcast().unwrap())
} }

View file

@ -213,7 +213,8 @@ impl Project {
subscriptions: vec![ subscriptions: vec![
client.subscribe_to_entity(remote_id, cx, Self::handle_add_collaborator), 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_remove_collaborator),
client.subscribe_to_entity(remote_id, cx, Self::handle_register_worktree), client.subscribe_to_entity(remote_id, cx, Self::handle_share_worktree),
client.subscribe_to_entity(remote_id, cx, Self::handle_unregister_worktree),
client.subscribe_to_entity(remote_id, cx, Self::handle_update_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_update_buffer),
client.subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved), client.subscribe_to_entity(remote_id, cx, Self::handle_buffer_saved),
@ -231,14 +232,6 @@ impl Project {
*remote_id_tx.borrow_mut() = remote_id; *remote_id_tx.borrow_mut() = remote_id;
} }
for worktree in &self.worktrees {
worktree.update(cx, |worktree, _| {
if let Some(worktree) = worktree.as_local_mut() {
worktree.set_project_remote_id(remote_id);
}
});
}
self.subscriptions.clear(); self.subscriptions.clear();
if let Some(remote_id) = remote_id { if let Some(remote_id) = remote_id {
self.subscriptions.extend([ self.subscriptions.extend([
@ -307,7 +300,11 @@ impl Project {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
for worktree in &this.worktrees { for worktree in &this.worktrees {
worktree.update(cx, |worktree, cx| { worktree.update(cx, |worktree, cx| {
worktree.as_local_mut().unwrap().share(cx).detach(); worktree
.as_local_mut()
.unwrap()
.share(remote_id, cx)
.detach();
}); });
} }
}); });
@ -327,6 +324,13 @@ impl Project {
} }
} }
fn is_shared(&self) -> bool {
match &self.client_state {
ProjectClientState::Local { is_shared, .. } => *is_shared,
ProjectClientState::Remote { .. } => false,
}
}
pub fn add_local_worktree( pub fn add_local_worktree(
&mut self, &mut self,
abs_path: &Path, abs_path: &Path,
@ -337,32 +341,35 @@ impl Project {
let user_store = self.user_store.clone(); let user_store = self.user_store.clone();
let languages = self.languages.clone(); let languages = self.languages.clone();
let path = Arc::from(abs_path); let path = Arc::from(abs_path);
cx.spawn(|this, mut cx| async move { cx.spawn(|project, mut cx| async move {
let worktree = let worktree =
Worktree::open_local(client.clone(), user_store, path, fs, languages, &mut cx) Worktree::open_local(client.clone(), user_store, path, fs, languages, &mut cx)
.await?; .await?;
this.update(&mut cx, |this, cx| {
if let Some(project_id) = this.remote_id() { let (remote_project_id, is_shared) = project.update(&mut cx, |project, cx| {
worktree.update(cx, |worktree, cx| { project.add_worktree(worktree.clone(), cx);
let worktree = worktree.as_local_mut().unwrap(); (project.remote_id(), project.is_shared())
worktree.set_project_remote_id(Some(project_id));
let serialized_worktree = worktree.to_proto(cx);
let authorized_logins = worktree.authorized_logins();
cx.foreground()
.spawn(async move {
client
.request(proto::RegisterWorktree {
project_id,
worktree: Some(serialized_worktree),
authorized_logins,
})
.log_err();
})
.detach();
});
}
this.add_worktree(worktree.clone(), cx);
}); });
if let Some(project_id) = remote_project_id {
let register_message = worktree.update(&mut cx, |worktree, _| {
let worktree = worktree.as_local_mut().unwrap();
proto::RegisterWorktree {
project_id,
root_name: worktree.root_name().to_string(),
authorized_logins: worktree.authorized_logins(),
}
});
client.request(register_message).await?;
if is_shared {
worktree
.update(&mut cx, |worktree, cx| {
worktree.as_local_mut().unwrap().share(project_id, cx)
})
.await?;
}
}
Ok(worktree) Ok(worktree)
}) })
} }
@ -476,9 +483,9 @@ impl Project {
Ok(()) Ok(())
} }
fn handle_register_worktree( fn handle_share_worktree(
&mut self, &mut self,
envelope: TypedEnvelope<proto::RegisterWorktree>, envelope: TypedEnvelope<proto::ShareWorktree>,
client: Arc<Client>, client: Arc<Client>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
@ -505,6 +512,19 @@ impl Project {
Ok(()) Ok(())
} }
fn handle_unregister_worktree(
&mut self,
envelope: TypedEnvelope<proto::UnregisterWorktree>,
_: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
self.worktrees.retain(|worktree| {
worktree.read(cx).as_remote().unwrap().remote_id() != envelope.payload.worktree_id
});
cx.notify();
Ok(())
}
fn handle_update_worktree( fn handle_update_worktree(
&mut self, &mut self,
envelope: TypedEnvelope<proto::UpdateWorktree>, envelope: TypedEnvelope<proto::UpdateWorktree>,

View file

@ -208,7 +208,7 @@ impl Worktree {
} }
Worktree::Remote(RemoteWorktree { Worktree::Remote(RemoteWorktree {
project_remote_id, project_id: project_remote_id,
remote_id, remote_id,
replica_id, replica_id,
snapshot, snapshot,
@ -236,6 +236,14 @@ impl Worktree {
} }
} }
pub fn as_remote(&self) -> Option<&RemoteWorktree> {
if let Worktree::Remote(worktree) = self {
Some(worktree)
} else {
None
}
}
pub fn as_local_mut(&mut self) -> Option<&mut LocalWorktree> { pub fn as_local_mut(&mut self) -> Option<&mut LocalWorktree> {
if let Worktree::Local(worktree) = self { if let Worktree::Local(worktree) = self {
Some(worktree) Some(worktree)
@ -483,8 +491,10 @@ impl Worktree {
let sender_id = envelope.original_sender_id()?; let sender_id = envelope.original_sender_id()?;
let this = self.as_local().unwrap(); let this = self.as_local().unwrap();
let project_id = this let project_id = this
.project_remote_id .share
.ok_or_else(|| anyhow!("can't save buffer while disconnected"))?; .as_ref()
.ok_or_else(|| anyhow!("can't save buffer while disconnected"))?
.project_id;
let buffer = this let buffer = this
.shared_buffers .shared_buffers
@ -756,13 +766,12 @@ impl Worktree {
operation: Operation, operation: Operation,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) { ) {
if let Some((rpc, project_id)) = match self { if let Some((project_id, rpc)) = match self {
Worktree::Local(worktree) => worktree Worktree::Local(worktree) => worktree
.project_remote_id .share
.map(|id| (worktree.client.clone(), id)), .as_ref()
Worktree::Remote(worktree) => { .map(|share| (share.project_id, worktree.client.clone())),
Some((worktree.client.clone(), worktree.project_remote_id)) Worktree::Remote(worktree) => Some((worktree.project_id, worktree.client.clone())),
}
} { } {
cx.spawn(|worktree, mut cx| async move { cx.spawn(|worktree, mut cx| async move {
if let Err(error) = rpc if let Err(error) = rpc
@ -809,7 +818,6 @@ pub struct LocalWorktree {
background_snapshot: Arc<Mutex<Snapshot>>, background_snapshot: Arc<Mutex<Snapshot>>,
last_scan_state_rx: watch::Receiver<ScanState>, last_scan_state_rx: watch::Receiver<ScanState>,
_background_scanner_task: Option<Task<()>>, _background_scanner_task: Option<Task<()>>,
project_remote_id: Option<u64>,
poll_task: Option<Task<()>>, poll_task: Option<Task<()>>,
share: Option<ShareState>, share: Option<ShareState>,
loading_buffers: LoadingBuffers, loading_buffers: LoadingBuffers,
@ -826,11 +834,12 @@ pub struct LocalWorktree {
} }
struct ShareState { struct ShareState {
project_id: u64,
snapshots_tx: Sender<Snapshot>, snapshots_tx: Sender<Snapshot>,
} }
pub struct RemoteWorktree { pub struct RemoteWorktree {
project_remote_id: u64, project_id: u64,
remote_id: u64, remote_id: u64,
snapshot: Snapshot, snapshot: Snapshot,
snapshot_rx: watch::Receiver<Snapshot>, snapshot_rx: watch::Receiver<Snapshot>,
@ -913,7 +922,6 @@ impl LocalWorktree {
let tree = Self { let tree = Self {
snapshot: snapshot.clone(), snapshot: snapshot.clone(),
config, config,
project_remote_id: None,
background_snapshot: Arc::new(Mutex::new(snapshot)), background_snapshot: Arc::new(Mutex::new(snapshot)),
last_scan_state_rx, last_scan_state_rx,
_background_scanner_task: None, _background_scanner_task: None,
@ -965,10 +973,6 @@ impl LocalWorktree {
Ok((tree, scan_states_tx)) Ok((tree, scan_states_tx))
} }
pub fn set_project_remote_id(&mut self, id: Option<u64>) {
self.project_remote_id = id;
}
pub fn authorized_logins(&self) -> Vec<String> { pub fn authorized_logins(&self) -> Vec<String> {
self.config.collaborators.clone() self.config.collaborators.clone()
} }
@ -1244,63 +1248,54 @@ impl LocalWorktree {
}) })
} }
pub fn share(&mut self, cx: &mut ModelContext<Worktree>) -> Task<anyhow::Result<()>> { pub fn share(
&mut self,
project_id: u64,
cx: &mut ModelContext<Worktree>,
) -> Task<anyhow::Result<()>> {
if self.share.is_some() {
return Task::ready(Ok(()));
}
let snapshot = self.snapshot(); let snapshot = self.snapshot();
let rpc = self.client.clone(); let rpc = self.client.clone();
let project_id = self.project_remote_id;
let worktree_id = cx.model_id() as u64; let worktree_id = cx.model_id() as u64;
cx.spawn(|this, mut cx| async move { let (snapshots_to_send_tx, snapshots_to_send_rx) = smol::channel::unbounded::<Snapshot>();
let project_id = project_id.ok_or_else(|| anyhow!("no project id"))?; self.share = Some(ShareState {
project_id,
snapshots_tx: snapshots_to_send_tx,
});
let (snapshots_to_send_tx, snapshots_to_send_rx) = cx.background()
smol::channel::unbounded::<Snapshot>(); .spawn({
cx.background() let rpc = rpc.clone();
.spawn({ let snapshot = snapshot.clone();
let rpc = rpc.clone(); async move {
async move { let mut prev_snapshot = snapshot;
let mut prev_snapshot = snapshot; while let Ok(snapshot) = snapshots_to_send_rx.recv().await {
while let Ok(snapshot) = snapshots_to_send_rx.recv().await { let message =
let message = snapshot.build_update( snapshot.build_update(&prev_snapshot, project_id, worktree_id, false);
&prev_snapshot, match rpc.send(message).await {
project_id, Ok(()) => prev_snapshot = snapshot,
worktree_id, Err(err) => log::error!("error sending snapshot diff {}", err),
false,
);
match rpc.send(message).await {
Ok(()) => prev_snapshot = snapshot,
Err(err) => log::error!("error sending snapshot diff {}", err),
}
} }
} }
}) }
.detach(); })
.detach();
this.update(&mut cx, |worktree, _| { let share_message = cx.background().spawn(async move {
let worktree = worktree.as_local_mut().unwrap(); proto::ShareWorktree {
worktree.share = Some(ShareState { project_id,
snapshots_tx: snapshots_to_send_tx, worktree: Some(snapshot.to_proto()),
}); }
}); });
cx.foreground().spawn(async move {
rpc.request(share_message.await).await?;
Ok(()) Ok(())
}) })
} }
pub fn to_proto(&self, cx: &mut ModelContext<Worktree>) -> proto::Worktree {
let id = cx.model_id() as u64;
let snapshot = self.snapshot();
let root_name = self.root_name.clone();
proto::Worktree {
id,
root_name,
entries: snapshot
.entries_by_path
.cursor::<()>()
.filter(|e| !e.is_ignored)
.map(Into::into)
.collect(),
}
}
} }
fn build_gitignore(abs_path: &Path, fs: &dyn Fs) -> Result<Gitignore> { fn build_gitignore(abs_path: &Path, fs: &dyn Fs) -> Result<Gitignore> {
@ -1339,6 +1334,10 @@ impl fmt::Debug for LocalWorktree {
} }
impl RemoteWorktree { impl RemoteWorktree {
pub fn remote_id(&self) -> u64 {
self.remote_id
}
fn get_open_buffer( fn get_open_buffer(
&mut self, &mut self,
path: &Path, path: &Path,
@ -1368,7 +1367,7 @@ impl RemoteWorktree {
) -> Task<Result<ModelHandle<Buffer>>> { ) -> Task<Result<ModelHandle<Buffer>>> {
let rpc = self.client.clone(); let rpc = self.client.clone();
let replica_id = self.replica_id; let replica_id = self.replica_id;
let project_id = self.project_remote_id; let project_id = self.project_id;
let remote_worktree_id = self.remote_id; let remote_worktree_id = self.remote_id;
let root_path = self.snapshot.abs_path.clone(); let root_path = self.snapshot.abs_path.clone();
let path: Arc<Path> = Arc::from(path); let path: Arc<Path> = Arc::from(path);
@ -1481,6 +1480,20 @@ impl Snapshot {
self.id self.id
} }
pub fn to_proto(&self) -> proto::Worktree {
let root_name = self.root_name.clone();
proto::Worktree {
id: self.id as u64,
root_name,
entries: self
.entries_by_path
.cursor::<()>()
.filter(|e| !e.is_ignored)
.map(Into::into)
.collect(),
}
}
pub fn build_update( pub fn build_update(
&self, &self,
other: &Self, other: &Self,
@ -1540,6 +1553,7 @@ impl Snapshot {
proto::UpdateWorktree { proto::UpdateWorktree {
project_id, project_id,
worktree_id, worktree_id,
root_name: self.root_name().to_string(),
updated_entries, updated_entries,
removed_entries, removed_entries,
} }
@ -1902,7 +1916,7 @@ impl language::File for File {
self.worktree.update(cx, |worktree, cx| match worktree { self.worktree.update(cx, |worktree, cx| match worktree {
Worktree::Local(worktree) => { Worktree::Local(worktree) => {
let rpc = worktree.client.clone(); let rpc = worktree.client.clone();
let project_id = worktree.project_remote_id; let project_id = worktree.share.as_ref().map(|share| share.project_id);
let save = worktree.save(self.path.clone(), text, cx); let save = worktree.save(self.path.clone(), text, cx);
cx.background().spawn(async move { cx.background().spawn(async move {
let entry = save.await?; let entry = save.await?;
@ -1921,7 +1935,7 @@ impl language::File for File {
} }
Worktree::Remote(worktree) => { Worktree::Remote(worktree) => {
let rpc = worktree.client.clone(); let rpc = worktree.client.clone();
let project_id = worktree.project_remote_id; let project_id = worktree.project_id;
cx.foreground().spawn(async move { cx.foreground().spawn(async move {
let response = rpc let response = rpc
.request(proto::SaveBuffer { .request(proto::SaveBuffer {
@ -1961,7 +1975,7 @@ impl language::File for File {
let worktree_id = self.worktree.id() as u64; let worktree_id = self.worktree.id() as u64;
self.worktree.update(cx, |worktree, cx| { self.worktree.update(cx, |worktree, cx| {
if let Worktree::Remote(worktree) = worktree { if let Worktree::Remote(worktree) = worktree {
let project_id = worktree.project_remote_id; let project_id = worktree.project_id;
let rpc = worktree.client.clone(); let rpc = worktree.client.clone();
cx.background() cx.background()
.spawn(async move { .spawn(async move {

View file

@ -617,12 +617,13 @@ mod tests {
) )
.await; .await;
let project = cx.add_model(|_| { let project = cx.add_model(|cx| {
Project::new( Project::local(
params.languages.clone(), params.languages.clone(),
params.client.clone(), params.client.clone(),
params.user_store.clone(), params.user_store.clone(),
params.fs.clone(), params.fs.clone(),
cx,
) )
}); });
let root1 = project let root1 = project

View file

@ -96,7 +96,7 @@ message LeaveProject {
message RegisterWorktree { message RegisterWorktree {
uint64 project_id = 1; uint64 project_id = 1;
Worktree worktree = 2; string root_name = 2;
repeated string authorized_logins = 3; repeated string authorized_logins = 3;
} }
@ -113,8 +113,9 @@ message ShareWorktree {
message UpdateWorktree { message UpdateWorktree {
uint64 project_id = 1; uint64 project_id = 1;
uint64 worktree_id = 2; uint64 worktree_id = 2;
repeated Entry updated_entries = 3; string root_name = 3;
repeated uint64 removed_entries = 4; repeated Entry updated_entries = 4;
repeated uint64 removed_entries = 5;
} }
message AddProjectCollaborator { message AddProjectCollaborator {

View file

@ -152,6 +152,7 @@ messages!(
ShareWorktree, ShareWorktree,
UnregisterProject, UnregisterProject,
UnregisterWorktree, UnregisterWorktree,
UnshareProject,
UpdateBuffer, UpdateBuffer,
UpdateContacts, UpdateContacts,
UpdateWorktree, UpdateWorktree,
@ -183,7 +184,7 @@ entity_messages!(
OpenBuffer, OpenBuffer,
CloseBuffer, CloseBuffer,
SaveBuffer, SaveBuffer,
RegisterWorktree, ShareWorktree,
UnregisterWorktree, UnregisterWorktree,
UpdateBuffer, UpdateBuffer,
UpdateWorktree, UpdateWorktree,

View file

@ -155,10 +155,10 @@ pub struct ContactsPanel {
pub host_username: ContainedText, pub host_username: ContainedText,
pub tree_branch_width: f32, pub tree_branch_width: f32,
pub tree_branch_color: Color, pub tree_branch_color: Color,
pub shared_worktree: WorktreeRow, pub shared_project: WorktreeRow,
pub hovered_shared_worktree: WorktreeRow, pub hovered_shared_project: WorktreeRow,
pub unshared_worktree: WorktreeRow, pub unshared_project: WorktreeRow,
pub hovered_unshared_worktree: WorktreeRow, pub hovered_unshared_project: WorktreeRow,
} }
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]

View file

@ -358,12 +358,13 @@ pub struct Workspace {
impl Workspace { impl Workspace {
pub fn new(params: &WorkspaceParams, cx: &mut ViewContext<Self>) -> Self { pub fn new(params: &WorkspaceParams, cx: &mut ViewContext<Self>) -> Self {
let project = cx.add_model(|_| { let project = cx.add_model(|cx| {
Project::new( Project::local(
params.languages.clone(), params.languages.clone(),
params.client.clone(), params.client.clone(),
params.user_store.clone(), params.user_store.clone(),
params.fs.clone(), params.fs.clone(),
cx,
) )
}); });
cx.observe(&project, |_, _, cx| cx.notify()).detach(); cx.observe(&project, |_, _, cx| cx.notify()).detach();
@ -988,24 +989,25 @@ impl Workspace {
} }
fn render_collaborators(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> Vec<ElementBox> { fn render_collaborators(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> Vec<ElementBox> {
let mut elements = Vec::new(); let mut collaborators = self
if let Some(active_worktree) = self.project.read(cx).active_worktree() { .project
let collaborators = active_worktree .read(cx)
.read(cx) .collaborators()
.collaborators() .values()
.values() .cloned()
.cloned() .collect::<Vec<_>>();
.collect::<Vec<_>>(); collaborators.sort_unstable_by_key(|collaborator| collaborator.replica_id);
for collaborator in collaborators { collaborators
elements.push(self.render_avatar( .into_iter()
.map(|collaborator| {
self.render_avatar(
Some(&collaborator.user), Some(&collaborator.user),
Some(collaborator.replica_id), Some(collaborator.replica_id),
theme, theme,
cx, cx,
)); )
} })
} .collect()
elements
} }
fn render_avatar( fn render_avatar(