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
|
@ -246,7 +246,7 @@ impl SearchState {
|
|||
);
|
||||
}
|
||||
}),
|
||||
_search_match_notify: cx.spawn_in(window, |outline_panel, mut cx| async move {
|
||||
_search_match_notify: cx.spawn_in(window, async move |outline_panel, cx| {
|
||||
loop {
|
||||
match notify_rx.recv().await {
|
||||
Ok(()) => {}
|
||||
|
@ -255,7 +255,7 @@ impl SearchState {
|
|||
while let Ok(()) = notify_rx.try_recv() {
|
||||
//
|
||||
}
|
||||
let update_result = outline_panel.update(&mut cx, |_, cx| {
|
||||
let update_result = outline_panel.update(cx, |_, cx| {
|
||||
cx.notify();
|
||||
});
|
||||
if update_result.is_err() {
|
||||
|
@ -1794,9 +1794,9 @@ impl OutlinePanel {
|
|||
let Some(active_editor) = self.active_editor() else {
|
||||
return Task::ready(());
|
||||
};
|
||||
cx.spawn_in(window, |outline_panel, mut cx| async move {
|
||||
cx.spawn_in(window, async move |outline_panel, cx| {
|
||||
outline_panel
|
||||
.update_in(&mut cx, |outline_panel, window, cx| {
|
||||
.update_in(cx, |outline_panel, window, cx| {
|
||||
active_editor.update(cx, |editor, cx| {
|
||||
for buffer_id in buffers {
|
||||
outline_panel
|
||||
|
@ -1906,14 +1906,14 @@ impl OutlinePanel {
|
|||
return;
|
||||
}
|
||||
let project = self.project.clone();
|
||||
self.reveal_selection_task = cx.spawn_in(window, |outline_panel, mut cx| async move {
|
||||
self.reveal_selection_task = cx.spawn_in(window, async move |outline_panel, cx| {
|
||||
cx.background_executor().timer(UPDATE_DEBOUNCE).await;
|
||||
let entry_with_selection =
|
||||
outline_panel.update_in(&mut cx, |outline_panel, window, cx| {
|
||||
outline_panel.update_in(cx, |outline_panel, window, cx| {
|
||||
outline_panel.location_for_editor_selection(&editor, window, cx)
|
||||
})?;
|
||||
let Some(entry_with_selection) = entry_with_selection else {
|
||||
outline_panel.update(&mut cx, |outline_panel, cx| {
|
||||
outline_panel.update(cx, |outline_panel, cx| {
|
||||
outline_panel.selected_entry = SelectedEntry::None;
|
||||
cx.notify();
|
||||
})?;
|
||||
|
@ -1924,7 +1924,7 @@ impl OutlinePanel {
|
|||
worktree_id,
|
||||
buffer_id,
|
||||
..
|
||||
})) => project.update(&mut cx, |project, cx| {
|
||||
})) => project.update(cx, |project, cx| {
|
||||
let entry_id = project
|
||||
.buffer_for_id(*buffer_id, cx)
|
||||
.and_then(|buffer| buffer.read(cx).entry_id(cx));
|
||||
|
@ -1938,7 +1938,7 @@ impl OutlinePanel {
|
|||
})?,
|
||||
PanelEntry::Outline(outline_entry) => {
|
||||
let (buffer_id, excerpt_id) = outline_entry.ids();
|
||||
outline_panel.update(&mut cx, |outline_panel, cx| {
|
||||
outline_panel.update(cx, |outline_panel, cx| {
|
||||
outline_panel
|
||||
.collapsed_entries
|
||||
.remove(&CollapsedEntry::ExternalFile(buffer_id));
|
||||
|
@ -1970,7 +1970,7 @@ impl OutlinePanel {
|
|||
.buffer_id
|
||||
.or(match_range.end.buffer_id)
|
||||
.map(|buffer_id| {
|
||||
outline_panel.update(&mut cx, |outline_panel, cx| {
|
||||
outline_panel.update(cx, |outline_panel, cx| {
|
||||
outline_panel
|
||||
.collapsed_entries
|
||||
.remove(&CollapsedEntry::ExternalFile(buffer_id));
|
||||
|
@ -1999,7 +1999,7 @@ impl OutlinePanel {
|
|||
_ => return anyhow::Ok(()),
|
||||
};
|
||||
if let Some((worktree, buffer_entry)) = related_buffer_entry {
|
||||
outline_panel.update(&mut cx, |outline_panel, cx| {
|
||||
outline_panel.update(cx, |outline_panel, cx| {
|
||||
let worktree_id = worktree.read(cx).id();
|
||||
let mut dirs_to_expand = Vec::new();
|
||||
{
|
||||
|
@ -2039,7 +2039,7 @@ impl OutlinePanel {
|
|||
})?
|
||||
}
|
||||
|
||||
outline_panel.update_in(&mut cx, |outline_panel, window, cx| {
|
||||
outline_panel.update_in(cx, |outline_panel, window, cx| {
|
||||
outline_panel.select_entry(entry_with_selection, false, window, cx);
|
||||
outline_panel.update_cached_entries(None, window, cx);
|
||||
})?;
|
||||
|
@ -2556,7 +2556,7 @@ impl OutlinePanel {
|
|||
let active_multi_buffer = active_editor.read(cx).buffer().clone();
|
||||
let new_entries = self.new_entries_for_fs_update.clone();
|
||||
self.updating_fs_entries = true;
|
||||
self.fs_entries_update_task = cx.spawn_in(window, |outline_panel, mut cx| async move {
|
||||
self.fs_entries_update_task = cx.spawn_in(window, async move |outline_panel, cx| {
|
||||
if let Some(debounce) = debounce {
|
||||
cx.background_executor().timer(debounce).await;
|
||||
}
|
||||
|
@ -2565,7 +2565,7 @@ impl OutlinePanel {
|
|||
let mut new_unfolded_dirs = HashMap::default();
|
||||
let mut root_entries = HashSet::default();
|
||||
let mut new_excerpts = HashMap::<BufferId, HashMap<ExcerptId, Excerpt>>::default();
|
||||
let Ok(buffer_excerpts) = outline_panel.update(&mut cx, |outline_panel, cx| {
|
||||
let Ok(buffer_excerpts) = outline_panel.update(cx, |outline_panel, cx| {
|
||||
new_collapsed_entries = outline_panel.collapsed_entries.clone();
|
||||
new_unfolded_dirs = outline_panel.unfolded_dirs.clone();
|
||||
let multi_buffer_snapshot = active_multi_buffer.read(cx).snapshot(cx);
|
||||
|
@ -2898,7 +2898,7 @@ impl OutlinePanel {
|
|||
};
|
||||
|
||||
outline_panel
|
||||
.update_in(&mut cx, |outline_panel, window, cx| {
|
||||
.update_in(cx, |outline_panel, window, cx| {
|
||||
outline_panel.updating_fs_entries = false;
|
||||
outline_panel.new_entries_for_fs_update.clear();
|
||||
outline_panel.excerpts = new_excerpts;
|
||||
|
@ -3211,7 +3211,7 @@ impl OutlinePanel {
|
|||
let first_update = first_update.clone();
|
||||
self.outline_fetch_tasks.insert(
|
||||
(buffer_id, excerpt_id),
|
||||
cx.spawn_in(window, |outline_panel, mut cx| async move {
|
||||
cx.spawn_in(window, async move |outline_panel, cx| {
|
||||
let fetched_outlines = cx
|
||||
.background_spawn(async move {
|
||||
buffer_snapshot
|
||||
|
@ -3224,7 +3224,7 @@ impl OutlinePanel {
|
|||
})
|
||||
.await;
|
||||
outline_panel
|
||||
.update_in(&mut cx, |outline_panel, window, cx| {
|
||||
.update_in(cx, |outline_panel, window, cx| {
|
||||
if let Some(excerpt) = outline_panel
|
||||
.excerpts
|
||||
.entry(buffer_id)
|
||||
|
@ -3396,12 +3396,12 @@ impl OutlinePanel {
|
|||
let is_singleton = self.is_singleton_active(cx);
|
||||
let query = self.query(cx);
|
||||
self.updating_cached_entries = true;
|
||||
self.cached_entries_update_task = cx.spawn_in(window, |outline_panel, mut cx| async move {
|
||||
self.cached_entries_update_task = cx.spawn_in(window, async move |outline_panel, cx| {
|
||||
if let Some(debounce) = debounce {
|
||||
cx.background_executor().timer(debounce).await;
|
||||
}
|
||||
let Some(new_cached_entries) = outline_panel
|
||||
.update_in(&mut cx, |outline_panel, window, cx| {
|
||||
.update_in(cx, |outline_panel, window, cx| {
|
||||
outline_panel.generate_cached_entries(is_singleton, query, window, cx)
|
||||
})
|
||||
.ok()
|
||||
|
@ -3410,7 +3410,7 @@ impl OutlinePanel {
|
|||
};
|
||||
let (new_cached_entries, max_width_item_index) = new_cached_entries.await;
|
||||
outline_panel
|
||||
.update_in(&mut cx, |outline_panel, window, cx| {
|
||||
.update_in(cx, |outline_panel, window, cx| {
|
||||
outline_panel.cached_entries = new_cached_entries;
|
||||
outline_panel.max_width_item_index = max_width_item_index;
|
||||
if outline_panel.selected_entry.is_invalidated()
|
||||
|
@ -3448,10 +3448,10 @@ impl OutlinePanel {
|
|||
let Some(active_editor) = self.active_editor() else {
|
||||
return Task::ready((Vec::new(), None));
|
||||
};
|
||||
cx.spawn_in(window, |outline_panel, mut cx| async move {
|
||||
cx.spawn_in(window, async move |outline_panel, cx| {
|
||||
let mut generation_state = GenerationState::default();
|
||||
|
||||
let Ok(()) = outline_panel.update(&mut cx, |outline_panel, cx| {
|
||||
let Ok(()) = outline_panel.update(cx, |outline_panel, cx| {
|
||||
let auto_fold_dirs = OutlinePanelSettings::get_global(cx).auto_fold_dirs;
|
||||
let mut folded_dirs_entry = None::<(usize, FoldedDirsEntry)>;
|
||||
let track_matches = query.is_some();
|
||||
|
@ -4380,12 +4380,12 @@ impl OutlinePanel {
|
|||
if !Self::should_autohide_scrollbar(cx) {
|
||||
return;
|
||||
}
|
||||
self.hide_scrollbar_task = Some(cx.spawn_in(window, |panel, mut cx| async move {
|
||||
self.hide_scrollbar_task = Some(cx.spawn_in(window, 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();
|
||||
})
|
||||
|
@ -4811,9 +4811,9 @@ impl Panel for OutlinePanel {
|
|||
}
|
||||
|
||||
fn set_active(&mut self, active: bool, window: &mut Window, cx: &mut Context<Self>) {
|
||||
cx.spawn_in(window, |outline_panel, mut cx| async move {
|
||||
cx.spawn_in(window, async move |outline_panel, cx| {
|
||||
outline_panel
|
||||
.update_in(&mut cx, |outline_panel, window, cx| {
|
||||
.update_in(cx, |outline_panel, window, cx| {
|
||||
let old_active = outline_panel.active;
|
||||
outline_panel.active = active;
|
||||
if old_active != active {
|
||||
|
@ -6512,7 +6512,11 @@ outline: struct OutlineEntryExcerpt
|
|||
let window = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
|
||||
let outline_panel = window
|
||||
.update(cx, |_, window, cx| cx.spawn_in(window, OutlinePanel::load))
|
||||
.update(cx, |_, window, cx| {
|
||||
cx.spawn_in(window, async |this, cx| {
|
||||
OutlinePanel::load(this, cx.clone()).await
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
.await
|
||||
.expect("Failed to load outline panel");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue