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

@ -90,8 +90,8 @@ pub(crate) fn deserialize_terminal_panel(
window: &mut Window,
cx: &mut App,
) -> Task<anyhow::Result<Entity<TerminalPanel>>> {
window.spawn(cx, move |mut cx| async move {
let terminal_panel = workspace.update_in(&mut cx, |workspace, window, cx| {
window.spawn(cx, async move |cx| {
let terminal_panel = workspace.update_in(cx, |workspace, window, cx| {
cx.new(|cx| {
let mut panel = TerminalPanel::new(workspace, window, cx);
panel.height = serialized_panel.height.map(|h| h.round());
@ -106,11 +106,11 @@ pub(crate) fn deserialize_terminal_panel(
project,
workspace,
item_ids.as_slice(),
&mut cx,
cx,
)
.await;
let active_item = serialized_panel.active_item_id;
terminal_panel.update_in(&mut cx, |terminal_panel, window, cx| {
terminal_panel.update_in(cx, |terminal_panel, window, cx| {
terminal_panel.active_pane.update(cx, |pane, cx| {
populate_pane_items(pane, items, active_item, window, cx);
});
@ -123,11 +123,11 @@ pub(crate) fn deserialize_terminal_panel(
terminal_panel.clone(),
database_id,
serialized_pane_group,
&mut cx,
cx,
)
.await;
if let Some((center_group, active_pane)) = center_pane {
terminal_panel.update(&mut cx, |terminal_panel, _| {
terminal_panel.update(cx, |terminal_panel, _| {
terminal_panel.center = PaneGroup::with_root(center_group);
terminal_panel.active_pane =
active_pane.unwrap_or_else(|| terminal_panel.center.first_pane());

View file

@ -232,7 +232,7 @@ impl TerminalPanel {
let mut terminal_panel = None;
match workspace
.read_with(&mut cx, |workspace, _| {
.read_with(&cx, |workspace, _| {
workspace
.database_id()
.zip(TerminalPanel::serialization_key(workspace))
@ -535,9 +535,9 @@ impl TerminalPanel {
self.deferred_tasks.insert(
task.id.clone(),
cx.spawn_in(window, |terminal_panel, mut cx| async move {
wait_for_terminals_tasks(terminals_for_task, &mut cx).await;
let task = terminal_panel.update_in(&mut cx, |terminal_panel, window, cx| {
cx.spawn_in(window, async move |terminal_panel, cx| {
wait_for_terminals_tasks(terminals_for_task, cx).await;
let task = terminal_panel.update_in(cx, |terminal_panel, window, cx| {
if task.use_new_terminal {
terminal_panel
.spawn_in_new_terminal(task, window, cx)
@ -669,14 +669,14 @@ impl TerminalPanel {
}
let window_handle = window.window_handle();
let project = workspace.project().downgrade();
cx.spawn_in(window, move |workspace, mut cx| async move {
cx.spawn_in(window, async move |workspace, cx| {
let terminal = project
.update(&mut cx, |project, cx| {
.update(cx, |project, cx| {
project.create_terminal(kind, window_handle, cx)
})?
.await?;
workspace.update_in(&mut cx, |workspace, window, cx| {
workspace.update_in(cx, |workspace, window, cx| {
let terminal_view = cx.new(|cx| {
TerminalView::new(
terminal.clone(),
@ -701,24 +701,22 @@ impl TerminalPanel {
cx: &mut Context<Self>,
) -> Task<Result<Entity<Terminal>>> {
let workspace = self.workspace.clone();
cx.spawn_in(window, |terminal_panel, mut cx| async move {
if workspace.update(&mut cx, |workspace, cx| {
!is_enabled_in_workspace(workspace, cx)
})? {
cx.spawn_in(window, async move |terminal_panel, cx| {
if workspace.update(cx, |workspace, cx| !is_enabled_in_workspace(workspace, cx))? {
anyhow::bail!("terminal not yet supported for remote projects");
}
let pane = terminal_panel.update(&mut cx, |terminal_panel, _| {
let pane = terminal_panel.update(cx, |terminal_panel, _| {
terminal_panel.pending_terminals_to_add += 1;
terminal_panel.active_pane.clone()
})?;
let project = workspace.update(&mut cx, |workspace, _| workspace.project().clone())?;
let project = workspace.update(cx, |workspace, _| workspace.project().clone())?;
let window_handle = cx.window_handle();
let terminal = project
.update(&mut cx, |project, cx| {
.update(cx, |project, cx| {
project.create_terminal(kind, window_handle, cx)
})?
.await?;
let result = workspace.update_in(&mut cx, |workspace, window, cx| {
let result = workspace.update_in(cx, |workspace, window, cx| {
let terminal_view = Box::new(cx.new(|cx| {
TerminalView::new(
terminal.clone(),
@ -748,7 +746,7 @@ impl TerminalPanel {
Ok(terminal)
})?;
terminal_panel.update(&mut cx, |this, cx| {
terminal_panel.update(cx, |this, cx| {
this.pending_terminals_to_add = this.pending_terminals_to_add.saturating_sub(1);
this.serialize(cx)
})?;
@ -769,13 +767,13 @@ impl TerminalPanel {
else {
return;
};
self.pending_serialization = cx.spawn(|terminal_panel, mut cx| async move {
self.pending_serialization = cx.spawn(async move |terminal_panel, cx| {
cx.background_executor()
.timer(Duration::from_millis(50))
.await;
let terminal_panel = terminal_panel.upgrade()?;
let items = terminal_panel
.update(&mut cx, |terminal_panel, cx| {
.update(cx, |terminal_panel, cx| {
SerializedItems::WithSplits(serialize_pane_group(
&terminal_panel.center,
&terminal_panel.active_pane,
@ -818,9 +816,9 @@ impl TerminalPanel {
let reveal_target = spawn_task.reveal_target;
let window_handle = window.window_handle();
let task_workspace = self.workspace.clone();
cx.spawn_in(window, move |terminal_panel, mut cx| async move {
cx.spawn_in(window, async move |terminal_panel, cx| {
let project = terminal_panel
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
this.workspace
.update(cx, |workspace, _| workspace.project().clone())
.ok()
@ -828,14 +826,14 @@ impl TerminalPanel {
.ok()
.flatten()?;
let new_terminal = project
.update(&mut cx, |project, cx| {
.update(cx, |project, cx| {
project.create_terminal(TerminalKind::Task(spawn_task), window_handle, cx)
})
.ok()?
.await
.log_err()?;
terminal_to_replace
.update_in(&mut cx, |terminal_to_replace, window, cx| {
.update_in(cx, |terminal_to_replace, window, cx| {
terminal_to_replace.set_terminal(new_terminal, window, cx);
})
.ok()?;
@ -844,7 +842,7 @@ impl TerminalPanel {
RevealStrategy::Always => match reveal_target {
RevealTarget::Center => {
task_workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
workspace
.active_item(cx)
.context("retrieving active terminal item in the workspace")
@ -857,7 +855,7 @@ impl TerminalPanel {
}
RevealTarget::Dock => {
terminal_panel
.update_in(&mut cx, |terminal_panel, window, cx| {
.update_in(cx, |terminal_panel, window, cx| {
terminal_panel.activate_terminal_view(
&task_pane,
terminal_item_index,
@ -868,9 +866,9 @@ impl TerminalPanel {
})
.ok()?;
cx.spawn(|mut cx| async move {
cx.spawn(async move |cx| {
task_workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
workspace.focus_panel::<Self>(window, cx)
})
.ok()
@ -881,14 +879,14 @@ impl TerminalPanel {
RevealStrategy::NoFocus => match reveal_target {
RevealTarget::Center => {
task_workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
workspace.active_pane().focus_handle(cx).focus(window);
})
.ok()?;
}
RevealTarget::Dock => {
terminal_panel
.update_in(&mut cx, |terminal_panel, window, cx| {
.update_in(cx, |terminal_panel, window, cx| {
terminal_panel.activate_terminal_view(
&task_pane,
terminal_item_index,
@ -899,9 +897,9 @@ impl TerminalPanel {
})
.ok()?;
cx.spawn(|mut cx| async move {
cx.spawn(async move |cx| {
task_workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
workspace.open_panel::<Self>(window, cx)
})
.ok()
@ -1080,7 +1078,7 @@ pub fn new_terminal_pane(
match new_split_pane.transpose() {
// Source pane may be the one currently updated, so defer the move.
Ok(Some(new_pane)) => cx
.spawn_in(window, |_, mut cx| async move {
.spawn_in(window, async move |_, cx| {
cx.update(|window, cx| {
move_item(
&source,

View file

@ -494,12 +494,10 @@ impl TerminalView {
cx.notify();
let epoch = self.next_blink_epoch();
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
Timer::after(CURSOR_BLINK_INTERVAL).await;
this.update_in(&mut cx, |this, window, cx| {
this.blink_cursors(epoch, window, cx)
})
.ok();
this.update_in(cx, |this, window, cx| this.blink_cursors(epoch, window, cx))
.ok();
})
.detach();
}
@ -510,9 +508,9 @@ impl TerminalView {
cx.notify();
let epoch = self.next_blink_epoch();
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
Timer::after(CURSOR_BLINK_INTERVAL).await;
this.update_in(&mut cx, |this, window, cx| {
this.update_in(cx, |this, window, cx| {
this.resume_cursor_blinking(epoch, window, cx)
})
.ok();
@ -727,12 +725,12 @@ impl TerminalView {
if !Self::should_autohide_scrollbar(cx) {
return;
}
self.hide_scrollbar_task = Some(cx.spawn(|panel, mut cx| async move {
self.hide_scrollbar_task = Some(cx.spawn(async move |panel, cx| {
cx.background_executor()
.timer(SCROLLBAR_SHOW_INTERVAL)
.await;
panel
.update(&mut cx, |panel, cx| {
.update(cx, |panel, cx| {
panel.show_scrollbar = false;
cx.notify();
})
@ -900,9 +898,9 @@ fn subscribe_for_terminal_events(
}
let task_workspace = workspace.clone();
let path_like_target = path_like_target.clone();
cx.spawn_in(window, |terminal_view, mut cx| async move {
cx.spawn_in(window, async move |terminal_view, cx| {
let open_target = terminal_view
.update(&mut cx, |_, cx| {
.update(cx, |_, cx| {
possible_open_target(
&task_workspace,
&path_like_target.terminal_dir,
@ -914,7 +912,7 @@ fn subscribe_for_terminal_events(
if let Some(open_target) = open_target {
let path_to_open = open_target.path();
let opened_items = task_workspace
.update_in(&mut cx, |workspace, window, cx| {
.update_in(cx, |workspace, window, cx| {
workspace.open_paths(
vec![path_to_open.path.clone()],
OpenOptions {
@ -945,7 +943,7 @@ fn subscribe_for_terminal_events(
{
active_editor
.downgrade()
.update_in(&mut cx, |editor, window, cx| {
.update_in(cx, |editor, window, cx| {
editor.go_to_singleton_buffer_point(
language::Point::new(
row.saturating_sub(1),
@ -960,7 +958,7 @@ fn subscribe_for_terminal_events(
}
}
} else if open_target.is_dir() {
task_workspace.update(&mut cx, |workspace, cx| {
task_workspace.update(cx, |workspace, cx| {
workspace.project().update(cx, |_, cx| {
cx.emit(project::Event::ActivateProjectPanel);
})
@ -1496,8 +1494,10 @@ impl SerializableItem for TerminalView {
window: &mut Window,
cx: &mut App,
) -> Task<gpui::Result<()>> {
window.spawn(cx, |_| {
TERMINAL_DB.delete_unloaded_items(workspace_id, alive_items)
window.spawn(cx, async move |_| {
TERMINAL_DB
.delete_unloaded_items(workspace_id, alive_items)
.await
})
}
@ -1538,7 +1538,7 @@ impl SerializableItem for TerminalView {
cx: &mut App,
) -> Task<anyhow::Result<Entity<Self>>> {
let window_handle = window.window_handle();
window.spawn(cx, |mut cx| async move {
window.spawn(cx, async move |cx| {
let cwd = cx
.update(|_window, cx| {
let from_db = TERMINAL_DB
@ -1560,7 +1560,7 @@ impl SerializableItem for TerminalView {
.flatten();
let terminal = project
.update(&mut cx, |project, cx| {
.update(cx, |project, cx| {
project.create_terminal(TerminalKind::Shell(cwd), window_handle, cx)
})?
.await?;