Remove one todo from the critical path

This commit is contained in:
Nathan Sobo 2023-10-31 21:19:32 -06:00
parent 0ecf6bde73
commit 4da8ee1e1d
2 changed files with 84 additions and 67 deletions

View file

@ -1993,6 +1993,23 @@ impl<V: 'static> WindowHandle<V> {
state_type: PhantomData, state_type: PhantomData,
} }
} }
pub fn update<R>(
&self,
cx: &mut AppContext,
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
) -> Result<R> {
cx.update_window(self.any_handle, |cx| {
let root_view = cx
.window
.root_view
.clone()
.unwrap()
.downcast::<V>()
.unwrap();
root_view.update(cx, update)
})
}
} }
impl<V: 'static> Into<AnyWindowHandle> for WindowHandle<V> { impl<V: 'static> Into<AnyWindowHandle> for WindowHandle<V> {

View file

@ -25,7 +25,7 @@ use futures::{
use gpui2::{ use gpui2::{
AnyModel, AnyView, AppContext, AsyncAppContext, AsyncWindowContext, DisplayId, Entity, AnyModel, AnyView, AppContext, AsyncAppContext, AsyncWindowContext, DisplayId, Entity,
EventEmitter, MainThread, Model, ModelContext, Subscription, Task, View, ViewContext, EventEmitter, MainThread, Model, ModelContext, Subscription, Task, View, ViewContext,
VisualContext, WeakModel, WeakView, WindowBounds, WindowContext, WindowHandle, WindowOptions, VisualContext, WeakView, WindowBounds, WindowContext, WindowHandle, WindowOptions,
}; };
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem}; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
use language2::LanguageRegistry; use language2::LanguageRegistry;
@ -2812,54 +2812,56 @@ impl Workspace {
// // RPC handlers // // RPC handlers
// fn handle_follow( fn handle_follow(
// &mut self, &mut self,
// follower_project_id: Option<u64>, follower_project_id: Option<u64>,
// cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
// ) -> proto::FollowResponse { ) -> proto::FollowResponse {
// let client = &self.app_state.client; todo!()
// let project_id = self.project.read(cx).remote_id();
// let active_view_id = self.active_item(cx).and_then(|i| { // let client = &self.app_state.client;
// Some( // let project_id = self.project.read(cx).remote_id();
// i.to_followable_item_handle(cx)?
// .remote_id(client, cx)?
// .to_proto(),
// )
// });
// cx.notify(); // let active_view_id = self.active_item(cx).and_then(|i| {
// Some(
// i.to_followable_item_handle(cx)?
// .remote_id(client, cx)?
// .to_proto(),
// )
// });
// self.last_active_view_id = active_view_id.clone(); // cx.notify();
// proto::FollowResponse {
// active_view_id, // self.last_active_view_id = active_view_id.clone();
// views: self // proto::FollowResponse {
// .panes() // active_view_id,
// .iter() // views: self
// .flat_map(|pane| { // .panes()
// let leader_id = self.leader_for_pane(pane); // .iter()
// pane.read(cx).items().filter_map({ // .flat_map(|pane| {
// let cx = &cx; // let leader_id = self.leader_for_pane(pane);
// move |item| { // pane.read(cx).items().filter_map({
// let item = item.to_followable_item_handle(cx)?; // let cx = &cx;
// if (project_id.is_none() || project_id != follower_project_id) // move |item| {
// && item.is_project_item(cx) // let item = item.to_followable_item_handle(cx)?;
// { // if (project_id.is_none() || project_id != follower_project_id)
// return None; // && item.is_project_item(cx)
// } // {
// let id = item.remote_id(client, cx)?.to_proto(); // return None;
// let variant = item.to_state_proto(cx)?; // }
// Some(proto::View { // let id = item.remote_id(client, cx)?.to_proto();
// id: Some(id), // let variant = item.to_state_proto(cx)?;
// leader_id, // Some(proto::View {
// variant: Some(variant), // id: Some(id),
// }) // leader_id,
// } // variant: Some(variant),
// }) // })
// }) // }
// .collect(), // })
// } // })
// } // .collect(),
// }
}
fn handle_update_followers( fn handle_update_followers(
&mut self, &mut self,
@ -3942,7 +3944,7 @@ impl WorkspaceStore {
.log_err() .log_err()
} }
async fn handle_follow( pub async fn handle_follow(
this: Model<Self>, this: Model<Self>,
envelope: TypedEnvelope<proto::Follow>, envelope: TypedEnvelope<proto::Follow>,
_: Arc<Client>, _: Arc<Client>,
@ -3953,30 +3955,28 @@ impl WorkspaceStore {
project_id: envelope.payload.project_id, project_id: envelope.payload.project_id,
peer_id: envelope.original_sender_id()?, peer_id: envelope.original_sender_id()?,
}; };
let active_project = ActiveCall::global(cx).read(cx).location(); let active_project = ActiveCall::global(cx).read(cx).location().cloned();
let mut response = proto::FollowResponse::default(); let mut response = proto::FollowResponse::default();
for workspace in &this.workspaces { for workspace in &this.workspaces {
let Some(workspace) = workspace.upgrade(cx) else { workspace
continue; .update(cx, |workspace, cx| {
}; let handler_response = workspace.handle_follow(follower.project_id, cx);
if response.views.is_empty() {
workspace.update(cx, |workspace, cx| { response.views = handler_response.views;
let handler_response = workspace.handle_follow(follower.project_id, cx); } else {
if response.views.is_empty() { response.views.extend_from_slice(&handler_response.views);
response.views = handler_response.views;
} else {
response.views.extend_from_slice(&handler_response.views);
}
if let Some(active_view_id) = handler_response.active_view_id.clone() {
if response.active_view_id.is_none()
|| Some(workspace.project.downgrade()) == active_project
{
response.active_view_id = Some(active_view_id);
} }
}
}); if let Some(active_view_id) = handler_response.active_view_id.clone() {
if response.active_view_id.is_none()
|| Some(workspace.project.downgrade()) == active_project
{
response.active_view_id = Some(active_view_id);
}
}
})
.ok();
} }
if let Err(ix) = this.followers.binary_search(&follower) { if let Err(ix) = this.followers.binary_search(&follower) {