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

@ -118,7 +118,7 @@ impl DisconnectedOverlay {
let paths = ssh_project.paths.iter().map(PathBuf::from).collect();
cx.spawn_in(window, move |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
open_ssh_project(
connection_options,
paths,
@ -127,7 +127,7 @@ impl DisconnectedOverlay {
replace_window: Some(window_handle),
..Default::default()
},
&mut cx,
cx,
)
.await?;
Ok(())

View file

@ -62,13 +62,13 @@ impl RecentProjects {
let _subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent));
// We do not want to block the UI on a potentially lengthy call to DB, so we're gonna swap
// out workspace locations once the future runs to completion.
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
let workspaces = WORKSPACE_DB
.recent_workspaces_on_disk()
.await
.log_err()
.unwrap_or_default();
this.update_in(&mut cx, move |this, window, cx| {
this.update_in(cx, move |this, window, cx| {
this.picker.update(cx, move |picker, cx| {
picker.delegate.set_workspaces(workspaces);
picker.update_matches(picker.query(cx), window, cx)
@ -281,9 +281,9 @@ impl PickerDelegate for RecentProjectsDelegate {
SerializedWorkspaceLocation::Local(paths, _) => {
let paths = paths.paths().to_vec();
if replace_current_window {
cx.spawn_in(window, move |workspace, mut cx| async move {
cx.spawn_in(window, async move |workspace, cx| {
let continue_replacing = workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
workspace.prepare_to_close(
CloseIntent::ReplaceWindow,
window,
@ -293,7 +293,7 @@ impl PickerDelegate for RecentProjectsDelegate {
.await?;
if continue_replacing {
workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
workspace.open_workspace_for_paths(
true, paths, window, cx,
)
@ -330,13 +330,13 @@ impl PickerDelegate for RecentProjectsDelegate {
let paths = ssh_project.paths.iter().map(PathBuf::from).collect();
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
open_ssh_project(
connection_options,
paths,
app_state,
open_options,
&mut cx,
cx,
)
.await
})
@ -541,13 +541,13 @@ impl RecentProjectsDelegate {
) {
if let Some(selected_match) = self.matches.get(ix) {
let (workspace_id, _) = self.workspaces[selected_match.candidate_id];
cx.spawn_in(window, move |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
let _ = WORKSPACE_DB.delete_workspace_by_id(workspace_id).await;
let workspaces = WORKSPACE_DB
.recent_workspaces_on_disk()
.await
.unwrap_or_default();
this.update_in(&mut cx, move |picker, window, cx| {
this.update_in(cx, move |picker, window, cx| {
picker.delegate.set_workspaces(workspaces);
picker
.delegate

View file

@ -141,10 +141,10 @@ impl ProjectPicker {
let _path_task = cx
.spawn_in(window, {
let workspace = workspace.clone();
move |this, mut cx| async move {
async move |this, cx| {
let Ok(Some(paths)) = rx.await else {
workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
let weak = cx.entity().downgrade();
workspace.toggle_modal(window, cx, |window, cx| {
RemoteServerProjects::new(window, cx, weak)
@ -155,7 +155,7 @@ impl ProjectPicker {
};
let app_state = workspace
.update(&mut cx, |workspace, _| workspace.app_state().clone())
.update(cx, |workspace, _| workspace.app_state().clone())
.ok()?;
let options = cx
.update(|_, cx| (app_state.build_window_options)(None, cx))
@ -190,7 +190,7 @@ impl ProjectPicker {
})
.collect::<Vec<_>>();
window
.spawn(cx, |_| async move {
.spawn(cx, async move |_| {
for task in tasks {
task.await?;
}
@ -206,7 +206,7 @@ impl ProjectPicker {
})
})
.log_err();
this.update(&mut cx, |_, cx| {
this.update(cx, |_, cx| {
cx.emit(DismissEvent);
})
.ok();
@ -404,10 +404,10 @@ impl RemoteServerProjects {
.prompt_err("Failed to connect", window, cx, |_, _, _| None);
let address_editor = editor.clone();
let creating = cx.spawn(move |this, mut cx| async move {
let creating = cx.spawn(async move |this, cx| {
match connection.await {
Some(Some(client)) => this
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
telemetry::event!("SSH Server Created");
this.retained_connections.push(client);
this.add_ssh_server(connection_options, cx);
@ -416,7 +416,7 @@ impl RemoteServerProjects {
})
.log_err(),
_ => this
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
address_editor.update(cx, |this, _| {
this.set_read_only(false);
});
@ -492,11 +492,11 @@ impl RemoteServerProjects {
)
.prompt_err("Failed to connect", window, cx, |_, _, _| None);
cx.spawn_in(window, move |workspace, mut cx| async move {
cx.spawn_in(window, async move |workspace, cx| {
let session = connect.await;
workspace
.update(&mut cx, |workspace, cx| {
.update(cx, |workspace, cx| {
if let Some(prompt) = workspace.active_modal::<SshConnectionModal>(cx) {
prompt.update(cx, |prompt, cx| prompt.finished(cx))
}
@ -505,7 +505,7 @@ impl RemoteServerProjects {
let Some(Some(session)) = session else {
workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
let weak = cx.entity().downgrade();
workspace.toggle_modal(window, cx, |window, cx| {
RemoteServerProjects::new(window, cx, weak)
@ -516,7 +516,7 @@ impl RemoteServerProjects {
};
workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
let app_state = workspace.app_state().clone();
let weak = cx.entity().downgrade();
let project = project::Project::ssh(
@ -758,13 +758,13 @@ impl RemoteServerProjects {
let project = project.clone();
let server = server.connection.clone();
cx.emit(DismissEvent);
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
let result = open_ssh_project(
server.into(),
project.paths.into_iter().map(PathBuf::from).collect(),
app_state,
OpenOptions::default(),
&mut cx,
cx,
)
.await;
if let Err(e) = result {
@ -1111,15 +1111,15 @@ impl RemoteServerProjects {
cx,
);
cx.spawn(|mut cx| async move {
cx.spawn(async move |cx| {
if confirmation.await.ok() == Some(0) {
remote_servers
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
this.delete_ssh_server(index, cx);
})
.ok();
remote_servers
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
this.mode = Mode::default_mode(cx);
cx.notify();
})

View file

@ -455,13 +455,13 @@ impl remote::SshClientDelegate for SshClientDelegate {
version: Option<SemanticVersion>,
cx: &mut AsyncApp,
) -> Task<anyhow::Result<PathBuf>> {
cx.spawn(|mut cx| async move {
cx.spawn(async move |cx| {
let binary_path = AutoUpdater::download_remote_server_release(
platform.os,
platform.arch,
release_channel,
version,
&mut cx,
cx,
)
.await
.map_err(|e| {
@ -486,13 +486,13 @@ impl remote::SshClientDelegate for SshClientDelegate {
version: Option<SemanticVersion>,
cx: &mut AsyncApp,
) -> Task<Result<Option<(String, String)>>> {
cx.spawn(|mut cx| async move {
cx.spawn(async move |cx| {
AutoUpdater::get_remote_server_release_url(
platform.os,
platform.arch,
release_channel,
version,
&mut cx,
cx,
)
.await
})