Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge main

Nathan Sobo65bb05af4c8e
diff --cc crates/workspace2/src/workspace2.rs
index c063a02174b,3780f56b843..2439e19d04e
--- a/crates/workspace2/src/workspace2.rs
+++ b/crates/workspace2/src/workspace2.rs
@@@ -2371,150 -2270,147 +2270,161 @@@ impl Workspace
cx.notify();
}
- // fn start_following(
- // &mut self,
- // leader_id: PeerId,
- // cx: &mut ViewContext<Self>,
- // ) -> Option<Task<Result<()>>> {
- // let pane = self.active_pane().clone();
-
- // self.last_leaders_by_pane
- // .insert(pane.downgrade(), leader_id);
- // self.unfollow(&pane, cx);
- // self.follower_states.insert(
- // pane.clone(),
- // FollowerState {
- // leader_id,
- // active_view_id: None,
- // items_by_leader_view_id: Default::default(),
- // },
- // );
- // cx.notify();
-
- // let room_id = self.active_call()?.read(cx).room()?.read(cx).id();
- // let project_id = self.project.read(cx).remote_id();
- // let request = self.app_state.client.request(proto::Follow {
- // room_id,
- // project_id,
- // leader_id: Some(leader_id),
- // });
-
- // Some(cx.spawn(|this, mut cx| async move {
- // let response = request.await?;
- // this.update(&mut cx, |this, _| {
- // let state = this
- // .follower_states
- // .get_mut(&pane)
- // .ok_or_else(|| anyhow!("following interrupted"))?;
- // state.active_view_id = if let Some(active_view_id) = response.active_view_id {
- // Some(ViewId::from_proto(active_view_id)?)
- // } else {
- // None
- // };
- // Ok::<_, anyhow::Error>(())
- // })??;
- // Self::add_views_from_leader(
- // this.clone(),
- // leader_id,
- // vec![pane],
- // response.views,
- // &mut cx,
- // )
- // .await?;
- // this.update(&mut cx, |this, cx| this.leader_updated(leader_id, cx))?;
- // Ok(())
- // }))
- // }
+ fn start_following(
+ &mut self,
+ leader_id: PeerId,
+ cx: &mut ViewContext<Self>,
+ ) -> Option<Task<Result<()>>> {
+ let pane = self.active_pane().clone();
+
+ self.last_leaders_by_pane
+ .insert(pane.downgrade(), leader_id);
+ self.unfollow(&pane, cx);
+ self.follower_states.insert(
+ pane.clone(),
+ FollowerState {
+ leader_id,
+ active_view_id: None,
+ items_by_leader_view_id: Default::default(),
+ },
+ );
+ cx.notify();
+
+ let room_id = self.active_call()?.read(cx).room()?.read(cx).id();
+ let project_id = self.project.read(cx).remote_id();
+ let request = self.app_state.client.request(proto::Follow {
+ room_id,
+ project_id,
+ leader_id: Some(leader_id),
+ });
+
+ Some(cx.spawn(|this, mut cx| async move {
+ let response = request.await?;
+ this.update(&mut cx, |this, _| {
+ let state = this
+ .follower_states
+ .get_mut(&pane)
+ .ok_or_else(|| anyhow!("following interrupted"))?;
+ state.active_view_id = if let Some(active_view_id) = response.active_view_id {
+ Some(ViewId::from_proto(active_view_id)?)
+ } else {
+ None
+ };
+ Ok::<_, anyhow::Error>(())
+ })??;
+ Self::add_views_from_leader(
+ this.clone(),
+ leader_id,
+ vec![pane],
+ response.views,
+ &mut cx,
+ )
+ .await?;
+ this.update(&mut cx, |this, cx| this.leader_updated(leader_id, cx))?;
+ Ok(())
+ }))
+ }
- // pub fn follow_next_collaborator(
- // &mut self,
- // _: &FollowNextCollaborator,
- // cx: &mut ViewContext<Self>,
- // ) -> Option<Task<Result<()>>> {
- // let collaborators = self.project.read(cx).collaborators();
- // let next_leader_id = if let Some(leader_id) = self.leader_for_pane(&self.active_pane) {
- // let mut collaborators = collaborators.keys().copied();
- // for peer_id in collaborators.by_ref() {
- // if peer_id == leader_id {
- // break;
- // }
- // }
- // collaborators.next()
- // } else if let Some(last_leader_id) =
- // self.last_leaders_by_pane.get(&self.active_pane.downgrade())
- // {
- // if collaborators.contains_key(last_leader_id) {
- // Some(*last_leader_id)
- // } else {
- // None
+ // pub fn follow_next_collaborator(
+ // &mut self,
+ // _: &FollowNextCollaborator,
+ // cx: &mut ViewContext<Self>,
+ // ) {
+ // let collaborators = self.project.read(cx).collaborators();
+ // let next_leader_id = if let Some(leader_id) = self.leader_for_pane(&self.active_pane) {
+ // let mut collaborators = collaborators.keys().copied();
+ // for peer_id in collaborators.by_ref() {
+ // if peer_id == leader_id {
+ // break;
// }
+ // }
+ // collaborators.next()
+ // } else if let Some(last_leader_id) =
+ // self.last_leaders_by_pane.get(&self.active_pane.downgrade())
+ // {
+ // if collaborators.contains_key(last_leader_id) {
+ // Some(*last_leader_id)
// } else {
// None
- // };
-
- // let pane = self.active_pane.clone();
- // let Some(leader_id) = next_leader_id.or_else(|| collaborators.keys().copied().next())
- // else {
- // return None;
- // };
- // if Some(leader_id) == self.unfollow(&pane, cx) {
- // return None;
// }
- // self.follow(leader_id, cx)
+ // } else {
+ // None
+ // };
+
+ // let pane = self.active_pane.clone();
+ // let Some(leader_id) = next_leader_id.or_else(|| collaborators.keys().copied().next())
+ // else {
+ // return;
+ // };
+ // if Some(leader_id) == self.unfollow(&pane, cx) {
+ // return;
+ // }
+ // if let Some(task) = self.follow(leader_id, cx) {
+ // task.detach();
// }
+ // }
- // pub fn follow(
- // &mut self,
- // leader_id: PeerId,
- // cx: &mut ViewContext<Self>,
- // ) -> Option<Task<Result<()>>> {
- // let room = ActiveCall::global(cx).read(cx).room()?.read(cx);
- // let project = self.project.read(cx);
+ pub fn follow(
+ &mut self,
+ leader_id: PeerId,
+ cx: &mut ViewContext<Self>,
+ ) -> Option<Task<Result<()>>> {
+ let room = ActiveCall::global(cx).read(cx).room()?.read(cx);
+ let project = self.project.read(cx);
- // let Some(remote_participant) = room.remote_participant_for_peer_id(leader_id) else {
- // return None;
- // };
+ let Some(remote_participant) = room.remote_participant_for_peer_id(leader_id) else {
+ return None;
+ };
- // let other_project_id = match remote_participant.location {
- // call::ParticipantLocation::External => None,
- // call::ParticipantLocation::UnsharedProject => None,
- // call::ParticipantLocation::SharedProject { project_id } => {
- // if Some(project_id) == project.remote_id() {
- // None
- // } else {
- // Some(project_id)
- // }
- // }
- // };
+ let other_project_id = match remote_participant.location {
+ call::ParticipantLocation::External => None,
+ call::ParticipantLocation::UnsharedProject => None,
+ call::ParticipantLocation::SharedProject { project_id } => {
+ if Some(project_id) == project.remote_id() {
+ None
+ } else {
+ Some(project_id)
+ }
+ }
+ };
- // // if they are active in another project, follow there.
- // if let Some(project_id) = other_project_id {
- // let app_state = self.app_state.clone();
- // return Some(crate::join_remote_project(
- // project_id,
- // remote_participant.user.id,
- // app_state,
- // cx,
- // ));
- // }
+ // if they are active in another project, follow there.
+ if let Some(project_id) = other_project_id {
+ let app_state = self.app_state.clone();
+ return Some(crate::join_remote_project(
+ project_id,
+ remote_participant.user.id,
+ app_state,
+ cx,
+ ));
+ }
+
+ // if you're already following, find the right pane and focus it.
+ for (pane, state) in &self.follower_states {
+ if leader_id == state.leader_id {
+ cx.focus_view(pane);
+ return None;
+ }
+ }
+
+ // Otherwise, follow.
+ self.start_following(leader_id, cx)
+ }
+ // // if you're already following, find the right pane and focus it.
+ // for (pane, state) in &self.follower_states {
+ // if leader_id == state.leader_id {
+ // cx.focus(pane);
+ // return None;
+ // }
+ // }
+
+ // // Otherwise, follow.
+ // self.start_following(leader_id, cx)
+ // }
+
pub fn unfollow(&mut self, pane: &View<Pane>, cx: &mut ViewContext<Self>) -> Option<PeerId> {
- let follower_states = &mut self.follower_states;
- let state = follower_states.remove(pane)?;
+ let state = self.follower_states.remove(pane)?;
let leader_id = state.leader_id;
for (_, item) in state.items_by_leader_view_id {
item.set_leader_peer_id(None, cx);