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

@ -78,7 +78,7 @@ pub fn open_prompt_library(
cx: &mut App,
) -> Task<Result<WindowHandle<PromptLibrary>>> {
let store = PromptStore::global(cx);
cx.spawn(|cx| async move {
cx.spawn(async move |cx| {
// We query windows in spawn so that all windows have been returned to GPUI
let existing_window = cx
.update(|cx| {
@ -213,7 +213,7 @@ impl PickerDelegate for PromptPickerDelegate {
) -> Task<()> {
let search = self.store.search(query);
let prev_prompt_id = self.matches.get(self.selected_index).map(|mat| mat.id);
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
let (matches, selected_index) = cx
.background_spawn(async move {
let matches = search.await;
@ -227,7 +227,7 @@ impl PickerDelegate for PromptPickerDelegate {
})
.await;
this.update_in(&mut cx, |this, window, cx| {
this.update_in(cx, |this, window, cx| {
this.delegate.matches = matches;
this.delegate.set_selected_index(selected_index, window, cx);
cx.notify();
@ -409,9 +409,9 @@ impl PromptLibrary {
let save = self.store.save(prompt_id, None, false, "".into());
self.picker
.update(cx, |picker, cx| picker.refresh(window, cx));
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
save.await?;
this.update_in(&mut cx, |this, window, cx| {
this.update_in(cx, |this, window, cx| {
this.load_prompt(prompt_id, true, window, cx)
})
})
@ -449,10 +449,10 @@ impl PromptLibrary {
prompt_editor.next_title_and_body_to_save = Some((title, body));
if prompt_editor.pending_save.is_none() {
prompt_editor.pending_save = Some(cx.spawn_in(window, |this, mut cx| {
prompt_editor.pending_save = Some(cx.spawn_in(window, async move |this, cx| {
async move {
loop {
let title_and_body = this.update(&mut cx, |this, _| {
let title_and_body = this.update(cx, |this, _| {
this.prompt_editors
.get_mut(&prompt_id)?
.next_title_and_body_to_save
@ -469,7 +469,7 @@ impl PromptLibrary {
.save(prompt_id, title, prompt_metadata.default, body)
.await
.log_err();
this.update_in(&mut cx, |this, window, cx| {
this.update_in(cx, |this, window, cx| {
this.picker
.update(cx, |picker, cx| picker.refresh(window, cx));
cx.notify();
@ -481,13 +481,14 @@ impl PromptLibrary {
}
}
this.update(&mut cx, |this, _cx| {
this.update(cx, |this, _cx| {
if let Some(prompt_editor) = this.prompt_editors.get_mut(&prompt_id) {
prompt_editor.pending_save = None;
}
})
}
.log_err()
.await
}));
}
}
@ -548,10 +549,10 @@ impl PromptLibrary {
let language_registry = self.language_registry.clone();
let prompt = self.store.load(prompt_id);
let make_completion_provider = self.make_completion_provider.clone();
self.pending_load = cx.spawn_in(window, |this, mut cx| async move {
self.pending_load = cx.spawn_in(window, async move |this, cx| {
let prompt = prompt.await;
let markdown = language_registry.language_for_name("Markdown").await;
this.update_in(&mut cx, |this, window, cx| match prompt {
this.update_in(cx, |this, window, cx| match prompt {
Ok(prompt) => {
let title_editor = cx.new(|cx| {
let mut editor = Editor::auto_width(window, cx);
@ -684,9 +685,9 @@ impl PromptLibrary {
cx,
);
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
if confirmation.await.ok() == Some(0) {
this.update_in(&mut cx, |this, window, cx| {
this.update_in(cx, |this, window, cx| {
if this.active_prompt_id == Some(prompt_id) {
this.set_active_prompt(None, window, cx);
}
@ -740,9 +741,9 @@ impl PromptLibrary {
.save(new_id, Some(title.into()), false, body.into());
self.picker
.update(cx, |picker, cx| picker.refresh(window, cx));
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
save.await?;
this.update_in(&mut cx, |prompt_library, window, cx| {
this.update_in(cx, |prompt_library, window, cx| {
prompt_library.load_prompt(new_id, true, window, cx)
})
})
@ -886,7 +887,7 @@ impl PromptLibrary {
let editor = &prompt.body_editor.read(cx);
let buffer = &editor.buffer().read(cx).as_singleton().unwrap().read(cx);
let body = buffer.as_rope().clone();
prompt.pending_token_count = cx.spawn_in(window, |this, mut cx| {
prompt.pending_token_count = cx.spawn_in(window, async move |this, cx| {
async move {
const DEBOUNCE_TIMEOUT: Duration = Duration::from_secs(1);
@ -909,13 +910,14 @@ impl PromptLibrary {
})?
.await?;
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
let prompt_editor = this.prompt_editors.get_mut(&prompt_id).unwrap();
prompt_editor.token_count = Some(token_count);
cx.notify();
})
}
.log_err()
.await
});
}
}