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

@ -109,7 +109,7 @@ fn files_not_created_on_launch(errors: HashMap<io::ErrorKind, Vec<&Path>>) {
cx,
);
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
response.await?;
cx.update(|_, cx| cx.quit())
})
@ -138,7 +138,7 @@ fn fail_to_open_window(e: anyhow::Error, _cx: &mut App) {
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
{
use ashpd::desktop::notification::{Notification, NotificationProxy, Priority};
_cx.spawn(|_cx| async move {
_cx.spawn(async move |_cx| {
let Ok(proxy) = NotificationProxy::new().await else {
process::exit(1);
};
@ -285,7 +285,7 @@ fn main() {
{
cx.spawn({
let app_state = app_state.clone();
|mut cx| async move {
async move |mut cx| {
if let Err(e) = restore_or_create_workspace(app_state, &mut cx).await {
fail_to_open_window_async(e, &mut cx)
}
@ -580,7 +580,7 @@ fn main() {
cx.spawn({
let client = app_state.client.clone();
|cx| async move { authenticate(client, &cx).await }
async move |cx| authenticate(client, &cx).await
})
.detach_and_log_err(cx);
@ -606,7 +606,7 @@ fn main() {
None => {
cx.spawn({
let app_state = app_state.clone();
|mut cx| async move {
async move |mut cx| {
if let Err(e) = restore_or_create_workspace(app_state, &mut cx).await {
fail_to_open_window_async(e, &mut cx)
}
@ -620,7 +620,7 @@ fn main() {
component_preview::init(app_state.clone(), cx);
cx.spawn(move |cx| async move {
cx.spawn(async move |cx| {
while let Some(urls) = open_rx.next().await {
cx.update(|cx| {
if let Some(request) = OpenRequest::parse(urls, cx).log_err() {
@ -637,7 +637,7 @@ fn main() {
fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut App) {
if let Some(connection) = request.cli_connection {
let app_state = app_state.clone();
cx.spawn(move |cx| handle_cli_connection(connection, app_state, cx))
cx.spawn(async move |cx| handle_cli_connection(connection, app_state, cx).await)
.detach();
return;
}
@ -648,7 +648,7 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
}
if let Some(connection_options) = request.ssh_connection {
cx.spawn(|mut cx| async move {
cx.spawn(async move |mut cx| {
let paths_with_position =
derive_paths_with_position(app_state.fs.as_ref(), request.open_paths).await;
open_ssh_project(
@ -667,7 +667,7 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
let mut task = None;
if !request.open_paths.is_empty() {
let app_state = app_state.clone();
task = Some(cx.spawn(|mut cx| async move {
task = Some(cx.spawn(async move |mut cx| {
let paths_with_position =
derive_paths_with_position(app_state.fs.as_ref(), request.open_paths).await;
let (_window, results) = open_paths_with_positions(
@ -687,7 +687,7 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
}
if !request.open_channel_notes.is_empty() || request.join_channel.is_some() {
cx.spawn(|mut cx| async move {
cx.spawn(async move |mut cx| {
let result = maybe!(async {
if let Some(task) = task {
task.await?;
@ -711,7 +711,7 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
let workspace_window =
workspace::get_any_active_workspace(app_state, cx.clone()).await?;
let workspace = workspace_window.entity(&cx)?;
let workspace = workspace_window.entity(cx)?;
let mut promises = Vec::new();
for (channel_id, heading) in request.open_channel_notes {
@ -736,7 +736,7 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
})
.detach()
} else if let Some(task) = task {
cx.spawn(|mut cx| async move {
cx.spawn(async move |mut cx| {
if let Err(err) = task.await {
fail_to_open_window_async(err, &mut cx);
}
@ -821,13 +821,13 @@ async fn restore_or_create_workspace(app_state: Arc<AppState>, cx: &mut AsyncApp
.connection_options_for(ssh.host, ssh.port, ssh.user)
})?;
let app_state = app_state.clone();
cx.spawn(move |mut cx| async move {
cx.spawn(async move |cx| {
recent_projects::open_ssh_project(
connection_options,
ssh.paths.into_iter().map(PathBuf::from).collect(),
app_state,
workspace::OpenOptions::default(),
&mut cx,
cx,
)
.await
.log_err();
@ -1040,7 +1040,7 @@ fn eager_load_active_theme_and_icon_theme(fs: Arc<dyn Fs>, cx: &App) {
cx.spawn({
let theme_registry = theme_registry.clone();
let fs = fs.clone();
|cx| async move {
async move |cx| {
theme_registry.load_user_theme(&theme_path, fs).await?;
cx.update(|cx| {
@ -1066,7 +1066,7 @@ fn eager_load_active_theme_and_icon_theme(fs: Arc<dyn Fs>, cx: &App) {
cx.spawn({
let theme_registry = theme_registry.clone();
let fs = fs.clone();
|cx| async move {
async move |cx| {
theme_registry
.load_icon_theme(&icon_theme_path, &icons_root_path, fs)
.await?;
@ -1086,7 +1086,7 @@ fn eager_load_active_theme_and_icon_theme(fs: Arc<dyn Fs>, cx: &App) {
fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut App) {
cx.spawn({
let fs = fs.clone();
|cx| async move {
async move |cx| {
if let Some(theme_registry) =
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
{
@ -1119,7 +1119,7 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut App) {
/// Spawns a background task to watch the themes directory for changes.
fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut App) {
use std::time::Duration;
cx.spawn(|cx| async move {
cx.spawn(async move |cx| {
let (mut events, _) = fs
.watch(paths::themes_dir(), Duration::from_millis(100))
.await;
@ -1157,7 +1157,7 @@ fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>, cx: &m
full_path
};
cx.spawn(|_| async move {
cx.spawn(async move |_| {
let (mut events, _) = fs.watch(path.as_path(), Duration::from_millis(100)).await;
while let Some(event) = events.next().await {
let has_language_file = event.iter().any(|event| {