Move "async move" a few characters to the left in cx.spawn() (#26758)

This is the core change:
https://github.com/zed-industries/zed/pull/26758/files#diff-044302c0d57147af17e68a0009fee3e8dcdfb4f32c27a915e70cfa80e987f765R1052

TODO:
- [x] Use AsyncFn instead of Fn() -> Future in GPUI spawn methods
- [x] Implement it in the whole app
- [x] Implement it in the debugger 
- [x] Glance at the RPC crate, and see if those box future methods can
be switched over. Answer: It can't directly, as you can't make an
AsyncFn* into a trait object. There's ways around that, but they're all
more complex than just keeping the code as is.
- [ ] Fix platform specific code

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-03-18 19:09:02 -07:00 committed by GitHub
parent 7f2e3fb5bd
commit 1aefa5178b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
256 changed files with 3110 additions and 3200 deletions

View file

@ -48,7 +48,7 @@ pub fn init(cx: &mut App) {
.register_action(|_, _: &CopySystemSpecsIntoClipboard, window, cx| {
let specs = SystemSpecs::new(window, cx);
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
let specs = specs.await.to_string();
cx.update(|_, cx| {
@ -67,7 +67,7 @@ pub fn init(cx: &mut App) {
.detach();
})
.register_action(|_, _: &RequestFeature, window, cx| {
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
cx.update(|_, cx| {
cx.open_url(&request_feature_url());
})
@ -77,7 +77,7 @@ pub fn init(cx: &mut App) {
})
.register_action(move |_, _: &FileBugReport, window, cx| {
let specs = SystemSpecs::new(window, cx);
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
let specs = specs.await;
cx.update(|_, cx| {
cx.open_url(&file_bug_report_url(&specs));

View file

@ -115,9 +115,9 @@ impl ModalView for FeedbackModal {
cx,
);
cx.spawn_in(window, move |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
if answer.await.ok() == Some(0) {
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.dismiss_modal = true;
cx.emit(DismissEvent)
})
@ -144,14 +144,14 @@ impl FeedbackModal {
let project = workspace.project().clone();
let system_specs = SystemSpecs::new(window, cx);
cx.spawn_in(window, |workspace, mut cx| async move {
cx.spawn_in(window, async move |workspace, cx| {
let markdown = markdown.await.log_err();
let buffer = project.update(&mut cx, |project, cx| {
let buffer = project.update(cx, |project, cx| {
project.create_local_buffer("", markdown, cx)
})?;
let system_specs = system_specs.await;
workspace.update_in(&mut cx, |workspace, window, cx| {
workspace.update_in(cx, |workspace, window, cx| {
workspace.toggle_modal(window, cx, move |window, cx| {
FeedbackModal::new(system_specs, project, buffer, window, cx)
});
@ -240,10 +240,10 @@ impl FeedbackModal {
);
let client = Client::global(cx).clone();
let specs = self.system_specs.clone();
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
let answer = answer.await.ok();
if answer == Some(0) {
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.submission_state = Some(SubmissionState::CannotSubmit {
reason: CannotSubmitReason::AwaitingSubmission,
});
@ -256,7 +256,7 @@ impl FeedbackModal {
match res {
Ok(_) => {
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.dismiss_modal = true;
cx.notify();
cx.emit(DismissEvent)
@ -265,7 +265,7 @@ impl FeedbackModal {
}
Err(error) => {
log::error!("{}", error);
this.update_in(&mut cx, |this, window, cx| {
this.update_in(cx, |this, window, cx| {
let prompt = window.prompt(
PromptLevel::Critical,
FEEDBACK_SUBMISSION_ERROR_TEXT,
@ -273,7 +273,7 @@ impl FeedbackModal {
&["OK"],
cx,
);
cx.spawn_in(window, |_, _cx| async move {
cx.spawn_in(window, async move |_, _cx| {
prompt.await.ok();
})
.detach();
@ -369,20 +369,18 @@ impl FeedbackModal {
fn update_email_in_store(&self, window: &mut Window, cx: &mut Context<Self>) {
let email = self.email_address_editor.read(cx).text_option(cx);
cx.spawn_in(window, |_, _| async move {
match email {
Some(email) => {
KEY_VALUE_STORE
.write_kvp(DATABASE_KEY_NAME.to_string(), email)
.await
.ok();
}
None => {
KEY_VALUE_STORE
.delete_kvp(DATABASE_KEY_NAME.to_string())
.await
.ok();
}
cx.spawn_in(window, async move |_, _| match email {
Some(email) => {
KEY_VALUE_STORE
.write_kvp(DATABASE_KEY_NAME.to_string(), email)
.await
.ok();
}
None => {
KEY_VALUE_STORE
.delete_kvp(DATABASE_KEY_NAME.to_string())
.await
.ok();
}
})
.detach();
@ -516,9 +514,8 @@ impl Render for FeedbackModal {
.style(ButtonStyle::Subtle)
.color(Color::Muted)
.on_click(cx.listener(move |_, _, window, cx| {
cx.spawn_in(window, |this, mut cx| async move {
this.update(&mut cx, |_, cx| cx.emit(DismissEvent))
.ok();
cx.spawn_in(window, async move |this, cx| {
this.update(cx, |_, cx| cx.emit(DismissEvent)).ok();
})
.detach();
})),