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,
}
}
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> {

View file

@ -25,7 +25,7 @@ use futures::{
use gpui2::{
AnyModel, AnyView, AppContext, AsyncAppContext, AsyncWindowContext, DisplayId, Entity,
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 language2::LanguageRegistry;
@ -2812,11 +2812,13 @@ impl Workspace {
// // RPC handlers
// fn handle_follow(
// &mut self,
// follower_project_id: Option<u64>,
// cx: &mut ViewContext<Self>,
// ) -> proto::FollowResponse {
fn handle_follow(
&mut self,
follower_project_id: Option<u64>,
cx: &mut ViewContext<Self>,
) -> proto::FollowResponse {
todo!()
// let client = &self.app_state.client;
// let project_id = self.project.read(cx).remote_id();
@ -2859,7 +2861,7 @@ impl Workspace {
// })
// .collect(),
// }
// }
}
fn handle_update_followers(
&mut self,
@ -3942,7 +3944,7 @@ impl WorkspaceStore {
.log_err()
}
async fn handle_follow(
pub async fn handle_follow(
this: Model<Self>,
envelope: TypedEnvelope<proto::Follow>,
_: Arc<Client>,
@ -3953,15 +3955,12 @@ impl WorkspaceStore {
project_id: envelope.payload.project_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();
for workspace in &this.workspaces {
let Some(workspace) = workspace.upgrade(cx) else {
continue;
};
workspace.update(cx, |workspace, cx| {
workspace
.update(cx, |workspace, cx| {
let handler_response = workspace.handle_follow(follower.project_id, cx);
if response.views.is_empty() {
response.views = handler_response.views;
@ -3976,7 +3975,8 @@ impl WorkspaceStore {
response.active_view_id = Some(active_view_id);
}
}
});
})
.ok();
}
if let Err(ix) = this.followers.binary_search(&follower) {