diff --git a/crates/call/src/call.rs b/crates/call/src/call.rs index 66187e08c5..353c234282 100644 --- a/crates/call/src/call.rs +++ b/crates/call/src/call.rs @@ -114,7 +114,6 @@ impl ActiveCall { async fn handle_incoming_call( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let user_store = this.update(&mut cx, |this, _| this.user_store.clone())?; @@ -142,7 +141,6 @@ impl ActiveCall { async fn handle_call_canceled( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, _| { diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index 287e4a125b..f51221908f 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -697,7 +697,6 @@ impl Room { async fn handle_room_updated( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let room = envelope diff --git a/crates/channel/src/channel_buffer.rs b/crates/channel/src/channel_buffer.rs index c2115a7cab..7ce291ef4a 100644 --- a/crates/channel/src/channel_buffer.rs +++ b/crates/channel/src/channel_buffer.rs @@ -138,7 +138,6 @@ impl ChannelBuffer { async fn handle_update_channel_buffer( this: Model, update_channel_buffer: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let ops = update_channel_buffer @@ -160,7 +159,6 @@ impl ChannelBuffer { async fn handle_update_channel_buffer_collaborators( this: Model, message: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { diff --git a/crates/channel/src/channel_chat.rs b/crates/channel/src/channel_chat.rs index 46074665b8..8a1250fd69 100644 --- a/crates/channel/src/channel_chat.rs +++ b/crates/channel/src/channel_chat.rs @@ -528,7 +528,6 @@ impl ChannelChat { async fn handle_message_sent( this: Model, message: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let user_store = this.update(&mut cx, |this, _| this.user_store.clone())?; @@ -553,7 +552,6 @@ impl ChannelChat { async fn handle_message_removed( this: Model, message: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -565,7 +563,6 @@ impl ChannelChat { async fn handle_message_updated( this: Model, message: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let user_store = this.update(&mut cx, |this, _| this.user_store.clone())?; diff --git a/crates/channel/src/channel_store.rs b/crates/channel/src/channel_store.rs index 967c7a47a2..cbc605ffda 100644 --- a/crates/channel/src/channel_store.rs +++ b/crates/channel/src/channel_store.rs @@ -888,7 +888,6 @@ impl ChannelStore { async fn handle_update_channels( this: Model, message: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, _| { @@ -902,7 +901,6 @@ impl ChannelStore { async fn handle_update_user_channels( this: Model, message: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index a33bffd2b0..5cf63ee76d 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -689,6 +689,22 @@ impl Client { entity: WeakModel, handler: H, ) -> Subscription + where + M: EnvelopedMessage, + E: 'static, + H: 'static + Sync + Fn(Model, TypedEnvelope, AsyncAppContext) -> F + Send + Sync, + F: 'static + Future>, + { + self.add_message_handler_impl(entity, move |model, message, _, cx| { + handler(model, message, cx) + }) + } + + fn add_message_handler_impl( + self: &Arc, + entity: WeakModel, + handler: H, + ) -> Subscription where M: EnvelopedMessage, E: 'static, @@ -737,19 +753,11 @@ impl Client { where M: RequestMessage, E: 'static, - H: 'static - + Sync - + Fn(Model, TypedEnvelope, Arc, AsyncAppContext) -> F - + Send - + Sync, + H: 'static + Sync + Fn(Model, TypedEnvelope, AsyncAppContext) -> F + Send + Sync, F: 'static + Future>, { - self.add_message_handler(model, move |handle, envelope, this, cx| { - Self::respond_to_request( - envelope.receipt(), - handler(handle, envelope, this.clone(), cx), - this, - ) + self.add_message_handler_impl(model, move |handle, envelope, this, cx| { + Self::respond_to_request(envelope.receipt(), handler(handle, envelope, cx), this) }) } @@ -757,11 +765,11 @@ impl Client { where M: EntityMessage, E: 'static, - H: 'static + Fn(Model, TypedEnvelope, Arc, AsyncAppContext) -> F + Send + Sync, + H: 'static + Fn(Model, TypedEnvelope, AsyncAppContext) -> F + Send + Sync, F: 'static + Future>, { - self.add_entity_message_handler::(move |subscriber, message, client, cx| { - handler(subscriber.downcast::().unwrap(), message, client, cx) + self.add_entity_message_handler::(move |subscriber, message, _, cx| { + handler(subscriber.downcast::().unwrap(), message, cx) }) } @@ -808,13 +816,13 @@ impl Client { where M: EntityMessage + RequestMessage, E: 'static, - H: 'static + Fn(Model, TypedEnvelope, Arc, AsyncAppContext) -> F + Send + Sync, + H: 'static + Fn(Model, TypedEnvelope, AsyncAppContext) -> F + Send + Sync, F: 'static + Future>, { - self.add_model_message_handler(move |entity, envelope, client, cx| { + self.add_entity_message_handler::(move |entity, envelope, client, cx| { Self::respond_to_request::( envelope.receipt(), - handler(entity, envelope, client.clone(), cx), + handler(entity.downcast::().unwrap(), envelope, cx), client, ) }) @@ -1912,7 +1920,7 @@ mod tests { let (done_tx1, mut done_rx1) = smol::channel::unbounded(); let (done_tx2, mut done_rx2) = smol::channel::unbounded(); client.add_model_message_handler( - move |model: Model, _: TypedEnvelope, _, mut cx| { + move |model: Model, _: TypedEnvelope, mut cx| { match model.update(&mut cx, |model, _| model.id).unwrap() { 1 => done_tx1.try_send(()).unwrap(), 2 => done_tx2.try_send(()).unwrap(), @@ -1974,7 +1982,7 @@ mod tests { let (done_tx2, mut done_rx2) = smol::channel::unbounded(); let subscription1 = client.add_message_handler( model.downgrade(), - move |_, _: TypedEnvelope, _, _| { + move |_, _: TypedEnvelope, _| { done_tx1.try_send(()).unwrap(); async { Ok(()) } }, @@ -1982,7 +1990,7 @@ mod tests { drop(subscription1); let _subscription2 = client.add_message_handler( model.downgrade(), - move |_, _: TypedEnvelope, _, _| { + move |_, _: TypedEnvelope, _| { done_tx2.try_send(()).unwrap(); async { Ok(()) } }, @@ -2008,7 +2016,7 @@ mod tests { let (done_tx, mut done_rx) = smol::channel::unbounded(); let subscription = client.add_message_handler( model.clone().downgrade(), - move |model: Model, _: TypedEnvelope, _, mut cx| { + move |model: Model, _: TypedEnvelope, mut cx| { model .update(&mut cx, |model, _| model.subscription.take()) .unwrap(); diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index 5f9889e3e5..cd5bed6828 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -242,7 +242,6 @@ impl UserStore { async fn handle_update_invite_info( this: Model, message: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -258,7 +257,6 @@ impl UserStore { async fn handle_show_contacts( this: Model, _: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |_, cx| cx.emit(Event::ShowContacts))?; @@ -272,7 +270,6 @@ impl UserStore { async fn handle_update_contacts( this: Model, message: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, _| { diff --git a/crates/dev_server_projects/src/dev_server_projects.rs b/crates/dev_server_projects/src/dev_server_projects.rs index e69c905a14..792d20df48 100644 --- a/crates/dev_server_projects/src/dev_server_projects.rs +++ b/crates/dev_server_projects/src/dev_server_projects.rs @@ -124,7 +124,6 @@ impl Store { async fn handle_dev_server_projects_update( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { diff --git a/crates/headless/src/headless.rs b/crates/headless/src/headless.rs index ae359c2f08..2aaca69650 100644 --- a/crates/headless/src/headless.rs +++ b/crates/headless/src/headless.rs @@ -119,7 +119,6 @@ impl DevServer { async fn handle_dev_server_instructions( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let (added_projects, removed_projects_ids) = this.read_with(&mut cx, |this, _| { @@ -162,7 +161,6 @@ impl DevServer { async fn handle_validate_dev_server_project_request( this: Model, envelope: TypedEnvelope, - _: Arc, cx: AsyncAppContext, ) -> Result { let expanded = shellexpand::tilde(&envelope.payload.path).to_string(); @@ -180,7 +178,6 @@ impl DevServer { async fn handle_shutdown( this: Model, _envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { diff --git a/crates/notifications/src/notification_store.rs b/crates/notifications/src/notification_store.rs index 100398f3f4..dacf7b6e76 100644 --- a/crates/notifications/src/notification_store.rs +++ b/crates/notifications/src/notification_store.rs @@ -209,7 +209,6 @@ impl NotificationStore { async fn handle_new_notification( this: Model, envelope: TypedEnvelope, - _: Arc, cx: AsyncAppContext, ) -> Result<()> { Self::add_notifications( @@ -228,7 +227,6 @@ impl NotificationStore { async fn handle_delete_notification( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -240,7 +238,6 @@ impl NotificationStore { async fn handle_update_notification( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 15f86322a7..9c4daac5aa 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -4028,7 +4028,6 @@ impl Project { async fn handle_restart_language_servers( project: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { project.update(&mut cx, |project, cx| { @@ -8561,7 +8560,6 @@ impl Project { async fn handle_blame_buffer( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let buffer_id = BufferId::new(envelope.payload.buffer_id)?; @@ -8592,7 +8590,6 @@ impl Project { async fn handle_multi_lsp_query( project: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let sender_id = envelope.original_sender_id()?; @@ -8704,7 +8701,6 @@ impl Project { async fn handle_unshare_project( this: Model, _: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -8720,7 +8716,6 @@ impl Project { async fn handle_add_collaborator( this: Model, mut envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let collaborator = envelope @@ -8744,7 +8739,6 @@ impl Project { async fn handle_update_project_collaborator( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let old_peer_id = envelope @@ -8793,7 +8787,6 @@ impl Project { async fn handle_remove_collaborator( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -8822,7 +8815,6 @@ impl Project { async fn handle_update_project( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -8837,7 +8829,6 @@ impl Project { async fn handle_update_worktree( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -8855,7 +8846,6 @@ impl Project { async fn handle_update_worktree_settings( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -8879,7 +8869,6 @@ impl Project { async fn handle_create_project_entry( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let worktree = this.update(&mut cx, |this, cx| { @@ -8893,7 +8882,6 @@ impl Project { async fn handle_rename_project_entry( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let entry_id = ProjectEntryId::from_proto(envelope.payload.entry_id); @@ -8907,7 +8895,6 @@ impl Project { async fn handle_copy_project_entry( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let entry_id = ProjectEntryId::from_proto(envelope.payload.entry_id); @@ -8921,7 +8908,6 @@ impl Project { async fn handle_delete_project_entry( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let entry_id = ProjectEntryId::from_proto(envelope.payload.entry_id); @@ -8936,7 +8922,6 @@ impl Project { async fn handle_expand_project_entry( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let entry_id = ProjectEntryId::from_proto(envelope.payload.entry_id); @@ -8949,7 +8934,6 @@ impl Project { async fn handle_update_diagnostic_summary( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -8997,7 +8981,6 @@ impl Project { async fn handle_start_language_server( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let server = envelope @@ -9022,7 +9005,6 @@ impl Project { async fn handle_update_language_server( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -9085,7 +9067,6 @@ impl Project { async fn handle_update_buffer( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { this.update(&mut cx, |this, cx| { @@ -9123,7 +9104,6 @@ impl Project { async fn handle_create_buffer_for_peer( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -9209,7 +9189,6 @@ impl Project { async fn handle_update_diff_base( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, cx| { @@ -9232,7 +9211,6 @@ impl Project { async fn handle_update_buffer_file( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let buffer_id = envelope.payload.buffer_id; @@ -9263,7 +9241,6 @@ impl Project { async fn handle_save_buffer( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let buffer_id = BufferId::new(envelope.payload.buffer_id)?; @@ -9305,7 +9282,6 @@ impl Project { async fn handle_reload_buffers( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let sender_id = envelope.original_sender_id()?; @@ -9335,7 +9311,6 @@ impl Project { async fn handle_synchronize_buffers( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let project_id = envelope.payload.project_id; @@ -9426,7 +9401,6 @@ impl Project { async fn handle_format_buffers( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let sender_id = envelope.original_sender_id()?; @@ -9457,7 +9431,6 @@ impl Project { async fn handle_apply_additional_edits_for_completion( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let (buffer, completion) = this.update(&mut cx, |this, _| { @@ -9509,7 +9482,6 @@ impl Project { async fn handle_resolve_completion_documentation( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let lsp_completion = serde_json::from_slice(&envelope.payload.lsp_completion)?; @@ -9577,7 +9549,6 @@ impl Project { async fn handle_apply_code_action( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let sender_id = envelope.original_sender_id()?; @@ -9609,7 +9580,6 @@ impl Project { async fn handle_on_type_formatting( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let on_type_formatting = this.update(&mut cx, |this, cx| { @@ -9642,7 +9612,6 @@ impl Project { async fn handle_inlay_hints( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let sender_id = envelope.original_sender_id()?; @@ -9691,7 +9660,6 @@ impl Project { async fn handle_resolve_inlay_hint( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let proto_hint = envelope @@ -9726,7 +9694,6 @@ impl Project { async fn handle_task_context_for_location( project: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let location = envelope @@ -9769,7 +9736,6 @@ impl Project { async fn handle_task_templates( project: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let worktree = envelope.payload.worktree_id.map(WorktreeId::from_proto); @@ -9935,7 +9901,6 @@ impl Project { async fn handle_refresh_inlay_hints( this: Model, _: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { this.update(&mut cx, |_, cx| { @@ -9947,7 +9912,6 @@ impl Project { async fn handle_lsp_command( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<::Response> where @@ -9993,7 +9957,6 @@ impl Project { async fn handle_get_project_symbols( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let symbols = this @@ -10010,7 +9973,6 @@ impl Project { async fn handle_search_project( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let peer_id = envelope.original_sender_id()?; @@ -10050,7 +10012,6 @@ impl Project { async fn handle_open_buffer_for_symbol( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let peer_id = envelope.original_sender_id()?; @@ -10116,7 +10077,6 @@ impl Project { async fn handle_open_buffer_by_id( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let peer_id = envelope.original_sender_id()?; @@ -10130,7 +10090,6 @@ impl Project { async fn handle_open_buffer_by_path( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let peer_id = envelope.original_sender_id()?; @@ -10152,7 +10111,6 @@ impl Project { async fn handle_open_new_buffer( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { let buffer = this.update(&mut cx, |this, cx| this.create_local_buffer("", None, cx))?; @@ -10547,7 +10505,6 @@ impl Project { async fn handle_buffer_saved( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let version = deserialize_version(&envelope.payload.version); @@ -10572,7 +10529,6 @@ impl Project { async fn handle_buffer_reloaded( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let payload = envelope.payload; diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index acdf294aac..e3f478765c 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -4350,7 +4350,6 @@ impl WorkspaceStore { pub async fn handle_follow( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result { this.update(&mut cx, |this, cx| { @@ -4396,7 +4395,6 @@ impl WorkspaceStore { async fn handle_update_followers( this: Model, envelope: TypedEnvelope, - _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { let leader_id = envelope.original_sender_id()?;