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:
parent
7f2e3fb5bd
commit
1aefa5178b
256 changed files with 3110 additions and 3200 deletions
|
@ -30,40 +30,38 @@ impl ActiveToolchain {
|
|||
}
|
||||
}
|
||||
fn spawn_tracker_task(window: &mut Window, cx: &mut Context<Self>) -> Task<Option<()>> {
|
||||
cx.spawn_in(window, |this, mut cx| async move {
|
||||
cx.spawn_in(window, async move |this, cx| {
|
||||
let active_file = this
|
||||
.update(&mut cx, |this, _| {
|
||||
.update(cx, |this, _| {
|
||||
this.active_buffer
|
||||
.as_ref()
|
||||
.map(|(_, buffer, _)| buffer.clone())
|
||||
})
|
||||
.ok()
|
||||
.flatten()?;
|
||||
let workspace = this
|
||||
.update(&mut cx, |this, _| this.workspace.clone())
|
||||
.ok()?;
|
||||
let workspace = this.update(cx, |this, _| this.workspace.clone()).ok()?;
|
||||
let language_name = active_file
|
||||
.update(&mut cx, |this, _| Some(this.language()?.name()))
|
||||
.update(cx, |this, _| Some(this.language()?.name()))
|
||||
.ok()
|
||||
.flatten()?;
|
||||
let term = workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
.update(cx, |workspace, cx| {
|
||||
let languages = workspace.project().read(cx).languages();
|
||||
Project::toolchain_term(languages.clone(), language_name.clone())
|
||||
})
|
||||
.ok()?
|
||||
.await?;
|
||||
let _ = this.update(&mut cx, |this, cx| {
|
||||
let _ = this.update(cx, |this, cx| {
|
||||
this.term = term;
|
||||
cx.notify();
|
||||
});
|
||||
let worktree_id = active_file
|
||||
.update(&mut cx, |this, cx| Some(this.file()?.worktree_id(cx)))
|
||||
.update(cx, |this, cx| Some(this.file()?.worktree_id(cx)))
|
||||
.ok()
|
||||
.flatten()?;
|
||||
let toolchain =
|
||||
Self::active_toolchain(workspace, worktree_id, language_name, &mut cx).await?;
|
||||
let _ = this.update(&mut cx, |this, cx| {
|
||||
Self::active_toolchain(workspace, worktree_id, language_name, cx).await?;
|
||||
let _ = this.update(cx, |this, cx| {
|
||||
this.active_toolchain = Some(toolchain);
|
||||
|
||||
cx.notify();
|
||||
|
@ -104,13 +102,13 @@ impl ActiveToolchain {
|
|||
language_name: LanguageName,
|
||||
cx: &mut AsyncWindowContext,
|
||||
) -> Task<Option<Toolchain>> {
|
||||
cx.spawn(move |mut cx| async move {
|
||||
cx.spawn(async move |cx| {
|
||||
let workspace_id = workspace
|
||||
.update(&mut cx, |this, _| this.database_id())
|
||||
.update(cx, |this, _| this.database_id())
|
||||
.ok()
|
||||
.flatten()?;
|
||||
let selected_toolchain = workspace
|
||||
.update(&mut cx, |this, cx| {
|
||||
.update(cx, |this, cx| {
|
||||
this.project()
|
||||
.read(cx)
|
||||
.active_toolchain(worktree_id, language_name.clone(), cx)
|
||||
|
@ -121,7 +119,7 @@ impl ActiveToolchain {
|
|||
Some(toolchain)
|
||||
} else {
|
||||
let project = workspace
|
||||
.update(&mut cx, |this, _| this.project().clone())
|
||||
.update(cx, |this, _| this.project().clone())
|
||||
.ok()?;
|
||||
let toolchains = cx
|
||||
.update(|_, cx| {
|
||||
|
@ -138,7 +136,7 @@ impl ActiveToolchain {
|
|||
.await
|
||||
.ok()?;
|
||||
project
|
||||
.update(&mut cx, |this, cx| {
|
||||
.update(cx, |this, cx| {
|
||||
this.activate_toolchain(worktree_id, toolchain.clone(), cx)
|
||||
})
|
||||
.ok()?
|
||||
|
|
|
@ -57,14 +57,14 @@ impl ToolchainSelector {
|
|||
.abs_path();
|
||||
let workspace_id = workspace.database_id()?;
|
||||
let weak = workspace.weak_handle();
|
||||
cx.spawn_in(window, move |workspace, mut cx| async move {
|
||||
cx.spawn_in(window, async move |workspace, cx| {
|
||||
let active_toolchain = workspace::WORKSPACE_DB
|
||||
.toolchain(workspace_id, worktree_id, language_name.clone())
|
||||
.await
|
||||
.ok()
|
||||
.flatten();
|
||||
workspace
|
||||
.update_in(&mut cx, |this, window, cx| {
|
||||
.update_in(cx, |this, window, cx| {
|
||||
this.toggle_modal(window, cx, move |window, cx| {
|
||||
ToolchainSelector::new(
|
||||
weak,
|
||||
|
@ -155,26 +155,26 @@ impl ToolchainSelectorDelegate {
|
|||
) -> Self {
|
||||
let _fetch_candidates_task = cx.spawn_in(window, {
|
||||
let project = project.clone();
|
||||
move |this, mut cx| async move {
|
||||
async move |this, cx| {
|
||||
let term = project
|
||||
.update(&mut cx, |this, _| {
|
||||
.update(cx, |this, _| {
|
||||
Project::toolchain_term(this.languages().clone(), language_name.clone())
|
||||
})
|
||||
.ok()?
|
||||
.await?;
|
||||
let placeholder_text = format!("Select a {}…", term.to_lowercase()).into();
|
||||
let _ = this.update_in(&mut cx, move |this, window, cx| {
|
||||
let _ = this.update_in(cx, move |this, window, cx| {
|
||||
this.delegate.placeholder_text = placeholder_text;
|
||||
this.refresh_placeholder(window, cx);
|
||||
});
|
||||
let available_toolchains = project
|
||||
.update(&mut cx, |this, cx| {
|
||||
.update(cx, |this, cx| {
|
||||
this.available_toolchains(worktree_id, language_name, cx)
|
||||
})
|
||||
.ok()?
|
||||
.await?;
|
||||
|
||||
let _ = this.update_in(&mut cx, move |this, window, cx| {
|
||||
let _ = this.update_in(cx, move |this, window, cx| {
|
||||
this.delegate.candidates = available_toolchains;
|
||||
|
||||
if let Some(active_toolchain) = active_toolchain {
|
||||
|
@ -239,13 +239,13 @@ impl PickerDelegate for ToolchainSelectorDelegate {
|
|||
{
|
||||
let workspace = self.workspace.clone();
|
||||
let worktree_id = self.worktree_id;
|
||||
cx.spawn_in(window, |_, mut cx| async move {
|
||||
cx.spawn_in(window, async move |_, cx| {
|
||||
workspace::WORKSPACE_DB
|
||||
.set_toolchain(workspace_id, worktree_id, toolchain.clone())
|
||||
.await
|
||||
.log_err();
|
||||
workspace
|
||||
.update(&mut cx, |this, cx| {
|
||||
.update(cx, |this, cx| {
|
||||
this.project().update(cx, |this, cx| {
|
||||
this.activate_toolchain(worktree_id, toolchain, cx)
|
||||
})
|
||||
|
@ -288,7 +288,7 @@ impl PickerDelegate for ToolchainSelectorDelegate {
|
|||
let background = cx.background_executor().clone();
|
||||
let candidates = self.candidates.clone();
|
||||
let worktree_root_path = self.worktree_abs_path_root.clone();
|
||||
cx.spawn_in(window, |this, mut cx| async move {
|
||||
cx.spawn_in(window, async move |this, cx| {
|
||||
let matches = if query.is_empty() {
|
||||
candidates
|
||||
.toolchains
|
||||
|
@ -327,7 +327,7 @@ impl PickerDelegate for ToolchainSelectorDelegate {
|
|||
.await
|
||||
};
|
||||
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
let delegate = &mut this.delegate;
|
||||
delegate.matches = matches;
|
||||
delegate.selected_index = delegate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue