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

@ -86,11 +86,11 @@ impl PrettierStore {
}
}
}
cx.spawn(|prettier_store, mut cx| async move {
cx.spawn(async move |prettier_store, cx| {
while let Some(prettier_server_id) = prettier_instances_to_clean.next().await {
if let Some(prettier_server_id) = prettier_server_id {
prettier_store
.update(&mut cx, |_, cx| {
.update(cx, |_, cx| {
cx.emit(PrettierStoreEvent::LanguageServerRemoved(
prettier_server_id,
));
@ -119,7 +119,7 @@ impl PrettierStore {
Some((worktree_id, buffer_path)) => {
let fs = Arc::clone(&self.fs);
let installed_prettiers = self.prettier_instances.keys().cloned().collect();
cx.spawn(|lsp_store, mut cx| async move {
cx.spawn(async move |lsp_store, cx| {
match cx
.background_spawn(async move {
Prettier::locate_prettier_installation(
@ -134,7 +134,7 @@ impl PrettierStore {
Ok(ControlFlow::Break(())) => None,
Ok(ControlFlow::Continue(None)) => {
let default_instance = lsp_store
.update(&mut cx, |lsp_store, cx| {
.update(cx, |lsp_store, cx| {
lsp_store
.prettiers_per_worktree
.entry(worktree_id)
@ -151,7 +151,7 @@ impl PrettierStore {
}
Ok(ControlFlow::Continue(Some(prettier_dir))) => {
lsp_store
.update(&mut cx, |lsp_store, _| {
.update(cx, |lsp_store, _| {
lsp_store
.prettiers_per_worktree
.entry(worktree_id)
@ -160,7 +160,7 @@ impl PrettierStore {
})
.ok()?;
if let Some(prettier_task) = lsp_store
.update(&mut cx, |lsp_store, cx| {
.update(cx, |lsp_store, cx| {
lsp_store.prettier_instances.get_mut(&prettier_dir).map(
|existing_instance| {
existing_instance.prettier_task(
@ -180,7 +180,7 @@ impl PrettierStore {
log::info!("Found prettier in {prettier_dir:?}, starting.");
let new_prettier_task = lsp_store
.update(&mut cx, |lsp_store, cx| {
.update(cx, |lsp_store, cx| {
let new_prettier_task = Self::start_prettier(
node,
prettier_dir.clone(),
@ -208,7 +208,7 @@ impl PrettierStore {
}
None => {
let new_task = self.default_prettier.prettier_task(&node, None, cx);
cx.spawn(|_, _| async move { Some((None, new_task?.log_err().await?)) })
cx.spawn(async move |_, _| Some((None, new_task?.log_err().await?)))
}
}
}
@ -231,7 +231,7 @@ impl PrettierStore {
.get(&worktree_id)
.cloned()
.unwrap_or_default();
cx.spawn(|lsp_store, mut cx| async move {
cx.spawn(async move |lsp_store, cx| {
match cx
.background_spawn(async move {
Prettier::locate_prettier_ignore(
@ -248,7 +248,7 @@ impl PrettierStore {
Ok(ControlFlow::Continue(Some(ignore_dir))) => {
log::debug!("Found prettier ignore in {ignore_dir:?}");
lsp_store
.update(&mut cx, |store, _| {
.update(cx, |store, _| {
store
.prettier_ignores_per_worktree
.entry(worktree_id)
@ -277,9 +277,9 @@ impl PrettierStore {
worktree_id: Option<WorktreeId>,
cx: &mut Context<Self>,
) -> PrettierTask {
cx.spawn(|prettier_store, mut cx| async move {
cx.spawn(async move |prettier_store, cx| {
log::info!("Starting prettier at path {prettier_dir:?}");
let new_server_id = prettier_store.update(&mut cx, |prettier_store, _| {
let new_server_id = prettier_store.update(cx, |prettier_store, _| {
prettier_store.languages.next_language_server_id()
})?;
@ -293,7 +293,7 @@ impl PrettierStore {
&new_prettier,
worktree_id,
new_server_id,
&mut cx,
cx,
);
Ok(new_prettier)
})
@ -305,8 +305,8 @@ impl PrettierStore {
worktree_id: Option<WorktreeId>,
cx: &mut Context<PrettierStore>,
) -> Task<anyhow::Result<PrettierTask>> {
cx.spawn(|prettier_store, mut cx| async move {
let installation_task = prettier_store.update(&mut cx, |prettier_store, _| {
cx.spawn(async move |prettier_store, cx| {
let installation_task = prettier_store.update(cx, |prettier_store, _| {
match &prettier_store.default_prettier.prettier {
PrettierInstallation::NotInstalled {
installation_task, ..
@ -323,7 +323,7 @@ impl PrettierStore {
ControlFlow::Continue(Some(installation_task)) => {
log::info!("Waiting for default prettier to install");
if let Err(e) = installation_task.await {
prettier_store.update(&mut cx, |project, _| {
prettier_store.update(cx, |project, _| {
if let PrettierInstallation::NotInstalled {
installation_task,
attempts,
@ -339,7 +339,7 @@ impl PrettierStore {
);
}
let new_default_prettier =
prettier_store.update(&mut cx, |prettier_store, cx| {
prettier_store.update(cx, |prettier_store, cx| {
let new_default_prettier = Self::start_prettier(
node,
default_prettier_dir().clone(),
@ -359,7 +359,7 @@ impl PrettierStore {
Some(instance) => Ok(instance),
None => {
let new_default_prettier =
prettier_store.update(&mut cx, |prettier_store, cx| {
prettier_store.update(cx, |prettier_store, cx| {
let new_default_prettier = Self::start_prettier(
node,
default_prettier_dir().clone(),
@ -578,7 +578,7 @@ impl PrettierStore {
let plugins_to_install = new_plugins.clone();
let fs = Arc::clone(&self.fs);
let new_installation_task = cx
.spawn(|project, mut cx| async move {
.spawn(async move |project, cx| {
match locate_prettier_installation
.await
.context("locate prettier installation")
@ -593,7 +593,7 @@ impl PrettierStore {
if let Some(previous_installation_task) = previous_installation_task {
if let Err(e) = previous_installation_task.await {
log::error!("Failed to install default prettier: {e:#}");
project.update(&mut cx, |project, _| {
project.update(cx, |project, _| {
if let PrettierInstallation::NotInstalled { attempts, not_installed_plugins, .. } = &mut project.default_prettier.prettier {
*attempts += 1;
new_plugins.extend(not_installed_plugins.iter().cloned());
@ -604,7 +604,7 @@ impl PrettierStore {
}
};
if installation_attempt > prettier::FAIL_THRESHOLD {
project.update(&mut cx, |project, _| {
project.update(cx, |project, _| {
if let PrettierInstallation::NotInstalled { installation_task, .. } = &mut project.default_prettier.prettier {
*installation_task = None;
};
@ -614,7 +614,7 @@ impl PrettierStore {
);
return Ok(());
}
project.update(&mut cx, |project, _| {
project.update(cx, |project, _| {
new_plugins.retain(|plugin| {
!project.default_prettier.installed_plugins.contains(plugin)
});
@ -638,7 +638,7 @@ impl PrettierStore {
.context("prettier & plugins install")
.map_err(Arc::new)?;
log::info!("Initialized prettier with plugins: {installed_plugins:?}");
project.update(&mut cx, |project, _| {
project.update(cx, |project, _| {
project.default_prettier.prettier =
PrettierInstallation::Installed(PrettierInstance {
attempt: 0,
@ -865,9 +865,9 @@ impl PrettierInstance {
None => {
self.attempt += 1;
let node = node.clone();
cx.spawn(|prettier_store, mut cx| async move {
cx.spawn(async move |prettier_store, cx| {
prettier_store
.update(&mut cx, |_, cx| {
.update(cx, |_, cx| {
PrettierStore::start_default_prettier(node, worktree_id, cx)
})?
.await