cx.background_executor().spawn(...)
-> cx.background_spawn(...)
(#25103)
Done automatically with > ast-grep -p '$A.background_executor().spawn($B)' -r '$A.background_spawn($B)' --update-all --globs "\!crates/gpui" Followed by: * `cargo fmt` * Unexpected need to remove some trailing whitespace. * Manually adding imports of `gpui::{AppContext as _}` which provides `background_spawn` * Added `AppContext as _` to existing use of `AppContext` Release Notes: - N/A
This commit is contained in:
parent
f606b0641e
commit
b1872e3afd
120 changed files with 1146 additions and 1267 deletions
|
@ -171,7 +171,7 @@ impl WrapMap {
|
|||
|
||||
let text_system = cx.text_system().clone();
|
||||
let (font, font_size) = self.font_with_size.clone();
|
||||
let task = cx.background_executor().spawn(async move {
|
||||
let task = cx.background_spawn(async move {
|
||||
let mut line_wrapper = text_system.line_wrapper(font, font_size);
|
||||
let tab_snapshot = new_snapshot.tab_snapshot.clone();
|
||||
let range = TabPoint::zero()..tab_snapshot.max_point();
|
||||
|
@ -255,7 +255,7 @@ impl WrapMap {
|
|||
let mut snapshot = self.snapshot.clone();
|
||||
let text_system = cx.text_system().clone();
|
||||
let (font, font_size) = self.font_with_size.clone();
|
||||
let update_task = cx.background_executor().spawn(async move {
|
||||
let update_task = cx.background_spawn(async move {
|
||||
let mut edits = Patch::default();
|
||||
let mut line_wrapper = text_system.line_wrapper(font, font_size);
|
||||
for (tab_snapshot, tab_edits) in pending_edits {
|
||||
|
|
|
@ -4798,7 +4798,7 @@ impl Editor {
|
|||
let Some(matches_task) = editor
|
||||
.read_with(&mut cx, |editor, cx| {
|
||||
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||
cx.background_executor().spawn(async move {
|
||||
cx.background_spawn(async move {
|
||||
let mut ranges = Vec::new();
|
||||
let buffer_ranges =
|
||||
vec![buffer.anchor_before(0)..buffer.anchor_after(buffer.len())];
|
||||
|
@ -10221,13 +10221,12 @@ impl Editor {
|
|||
return;
|
||||
}
|
||||
let new_rows =
|
||||
cx.background_executor()
|
||||
.spawn({
|
||||
let snapshot = display_snapshot.clone();
|
||||
async move {
|
||||
Self::fetch_runnable_ranges(&snapshot, Anchor::min()..Anchor::max())
|
||||
}
|
||||
})
|
||||
cx.background_spawn({
|
||||
let snapshot = display_snapshot.clone();
|
||||
async move {
|
||||
Self::fetch_runnable_ranges(&snapshot, Anchor::min()..Anchor::max())
|
||||
}
|
||||
})
|
||||
.await;
|
||||
|
||||
let rows = Self::runnable_rows(project, display_snapshot, new_rows, cx.clone());
|
||||
|
@ -10989,7 +10988,7 @@ impl Editor {
|
|||
HoverLink::InlayHint(lsp_location, server_id) => {
|
||||
let computation =
|
||||
self.compute_target_location(lsp_location, server_id, window, cx);
|
||||
cx.background_executor().spawn(async move {
|
||||
cx.background_spawn(async move {
|
||||
let location = computation.await?;
|
||||
Ok(TargetTaskResult::Location(location))
|
||||
})
|
||||
|
@ -15587,7 +15586,7 @@ fn snippet_completions(
|
|||
let scope = language.map(|language| language.default_scope());
|
||||
let executor = cx.background_executor().clone();
|
||||
|
||||
cx.background_executor().spawn(async move {
|
||||
cx.background_spawn(async move {
|
||||
let classifier = CharClassifier::new(scope).for_completion(true);
|
||||
let mut last_word = chars
|
||||
.chars()
|
||||
|
@ -15717,7 +15716,7 @@ impl CompletionProvider for Entity<Project> {
|
|||
self.update(cx, |project, cx| {
|
||||
let snippets = snippet_completions(project, buffer, buffer_position, cx);
|
||||
let project_completions = project.completions(buffer, buffer_position, options, cx);
|
||||
cx.background_executor().spawn(async move {
|
||||
cx.background_spawn(async move {
|
||||
let mut completions = project_completions.await?;
|
||||
let snippets_completions = snippets.await?;
|
||||
completions.extend(snippets_completions);
|
||||
|
|
|
@ -5264,8 +5264,7 @@ impl EditorElement {
|
|||
Some(cx.spawn_in(window, |editor, mut cx| async move {
|
||||
let scrollbar_size = scrollbar_layout.hitbox.size;
|
||||
let scrollbar_markers = cx
|
||||
.background_executor()
|
||||
.spawn(async move {
|
||||
.background_spawn(async move {
|
||||
let max_point = snapshot.display_snapshot.buffer_snapshot.max_point();
|
||||
let mut marker_quads = Vec::new();
|
||||
if scrollbar_settings.git_diff {
|
||||
|
|
|
@ -4,7 +4,7 @@ use git::{
|
|||
blame::{Blame, BlameEntry},
|
||||
parse_git_remote_url, GitHostingProvider, GitHostingProviderRegistry, Oid,
|
||||
};
|
||||
use gpui::{App, Context, Entity, Subscription, Task};
|
||||
use gpui::{App, AppContext as _, Context, Entity, Subscription, Task};
|
||||
use http_client::HttpClient;
|
||||
use language::{markdown, Bias, Buffer, BufferSnapshot, Edit, LanguageRegistry, ParsedMarkdown};
|
||||
use multi_buffer::RowInfo;
|
||||
|
@ -360,8 +360,7 @@ impl GitBlame {
|
|||
|
||||
self.task = cx.spawn(|this, mut cx| async move {
|
||||
let result = cx
|
||||
.background_executor()
|
||||
.spawn({
|
||||
.background_spawn({
|
||||
let snapshot = snapshot.clone();
|
||||
async move {
|
||||
let Some(Blame {
|
||||
|
@ -549,7 +548,7 @@ async fn parse_markdown(text: &str, language_registry: &Arc<LanguageRegistry>) -
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use gpui::{AppContext as _, Context};
|
||||
use gpui::Context;
|
||||
use language::{Point, Rope};
|
||||
use project::FakeFs;
|
||||
use rand::prelude::*;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use collections::{HashMap, HashSet};
|
||||
use git::diff::DiffHunkStatus;
|
||||
use gpui::{
|
||||
Action, AppContext, Corner, CursorStyle, Focusable as _, Hsla, Model, MouseButton,
|
||||
Action, AppContext as _, Corner, CursorStyle, Focusable as _, Hsla, Model, MouseButton,
|
||||
Subscription, Task,
|
||||
};
|
||||
use language::{Buffer, BufferId, Point};
|
||||
|
@ -372,7 +372,7 @@ impl Editor {
|
|||
|
||||
self.diff_map
|
||||
.hunk_update_tasks
|
||||
.insert(None, cx.background_executor().spawn(new_toggle_task));
|
||||
.insert(None, cx.background_spawn(new_toggle_task));
|
||||
}
|
||||
|
||||
pub(super) fn expand_diff_hunk(
|
||||
|
@ -1089,10 +1089,9 @@ impl Editor {
|
|||
.ok();
|
||||
});
|
||||
|
||||
diff_map.hunk_update_tasks.insert(
|
||||
Some(buffer_id),
|
||||
cx.background_executor().spawn(new_sync_task),
|
||||
);
|
||||
diff_map
|
||||
.hunk_update_tasks
|
||||
.insert(Some(buffer_id), cx.background_spawn(new_sync_task));
|
||||
}
|
||||
|
||||
fn go_to_subsequent_hunk(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{ops::Range, time::Duration};
|
||||
|
||||
use collections::HashSet;
|
||||
use gpui::{App, Context, Task, Window};
|
||||
use gpui::{App, AppContext as _, Context, Task, Window};
|
||||
use language::language_settings::language_settings;
|
||||
use multi_buffer::{IndentGuide, MultiBufferRow};
|
||||
use text::{LineIndent, Point};
|
||||
|
@ -102,9 +102,7 @@ impl Editor {
|
|||
|
||||
let snapshot = snapshot.clone();
|
||||
|
||||
let task = cx
|
||||
.background_executor()
|
||||
.spawn(resolve_indented_range(snapshot, cursor_row));
|
||||
let task = cx.background_spawn(resolve_indented_range(snapshot, cursor_row));
|
||||
|
||||
// Try to resolve the indent in a short amount of time, otherwise move it to a background task.
|
||||
match cx
|
||||
|
@ -115,7 +113,7 @@ impl Editor {
|
|||
Err(future) => {
|
||||
state.pending_refresh =
|
||||
Some(cx.spawn_in(window, |editor, mut cx| async move {
|
||||
let result = cx.background_executor().spawn(future).await;
|
||||
let result = cx.background_spawn(future).await;
|
||||
editor
|
||||
.update(&mut cx, |editor, _| {
|
||||
editor.active_indent_guides_state.active_indent_range = result;
|
||||
|
|
|
@ -19,7 +19,7 @@ use crate::{
|
|||
use anyhow::Context as _;
|
||||
use clock::Global;
|
||||
use futures::future;
|
||||
use gpui::{AsyncApp, Context, Entity, Task, Window};
|
||||
use gpui::{AppContext as _, AsyncApp, Context, Entity, Task, Window};
|
||||
use language::{language_settings::InlayHintKind, Buffer, BufferSnapshot};
|
||||
use parking_lot::RwLock;
|
||||
use project::{InlayHint, ResolveState};
|
||||
|
@ -996,19 +996,17 @@ fn fetch_and_update_hints(
|
|||
|
||||
let background_task_buffer_snapshot = buffer_snapshot.clone();
|
||||
let background_fetch_range = fetch_range.clone();
|
||||
let new_update = cx
|
||||
.background_executor()
|
||||
.spawn(async move {
|
||||
calculate_hint_updates(
|
||||
query.excerpt_id,
|
||||
invalidate,
|
||||
background_fetch_range,
|
||||
new_hints,
|
||||
&background_task_buffer_snapshot,
|
||||
cached_excerpt_hints,
|
||||
&visible_hints,
|
||||
)
|
||||
})
|
||||
let new_update = cx.background_spawn(async move {
|
||||
calculate_hint_updates(
|
||||
query.excerpt_id,
|
||||
invalidate,
|
||||
background_fetch_range,
|
||||
new_hints,
|
||||
&background_task_buffer_snapshot,
|
||||
cached_excerpt_hints,
|
||||
&visible_hints,
|
||||
)
|
||||
})
|
||||
.await;
|
||||
if let Some(new_update) = new_update {
|
||||
log::debug!(
|
||||
|
|
|
@ -1225,28 +1225,27 @@ impl SerializableItem for Editor {
|
|||
let snapshot = buffer.read(cx).snapshot();
|
||||
|
||||
Some(cx.spawn_in(window, |_this, cx| async move {
|
||||
cx.background_executor()
|
||||
.spawn(async move {
|
||||
let (contents, language) = if serialize_dirty_buffers && is_dirty {
|
||||
let contents = snapshot.text();
|
||||
let language = snapshot.language().map(|lang| lang.name().to_string());
|
||||
(Some(contents), language)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
cx.background_spawn(async move {
|
||||
let (contents, language) = if serialize_dirty_buffers && is_dirty {
|
||||
let contents = snapshot.text();
|
||||
let language = snapshot.language().map(|lang| lang.name().to_string());
|
||||
(Some(contents), language)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let editor = SerializedEditor {
|
||||
abs_path,
|
||||
contents,
|
||||
language,
|
||||
mtime,
|
||||
};
|
||||
DB.save_serialized_editor(item_id, workspace_id, editor)
|
||||
.await
|
||||
.context("failed to save serialized editor")
|
||||
})
|
||||
.await
|
||||
.context("failed to save contents of buffer")?;
|
||||
let editor = SerializedEditor {
|
||||
abs_path,
|
||||
contents,
|
||||
language,
|
||||
mtime,
|
||||
};
|
||||
DB.save_serialized_editor(item_id, workspace_id, editor)
|
||||
.await
|
||||
.context("failed to save serialized editor")
|
||||
})
|
||||
.await
|
||||
.context("failed to save contents of buffer")?;
|
||||
|
||||
Ok(())
|
||||
}))
|
||||
|
@ -1540,7 +1539,7 @@ impl SearchableItem for Editor {
|
|||
ranges.iter().cloned().collect::<Vec<_>>()
|
||||
});
|
||||
|
||||
cx.background_executor().spawn(async move {
|
||||
cx.background_spawn(async move {
|
||||
let mut ranges = Vec::new();
|
||||
|
||||
let search_within_ranges = if search_within_ranges.is_empty() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::Editor;
|
||||
|
||||
use gpui::{App, Task as AsyncTask, Window};
|
||||
use gpui::{App, AppContext as _, Task as AsyncTask, Window};
|
||||
use project::Location;
|
||||
use task::{TaskContext, TaskVariables, VariableName};
|
||||
use text::{ToOffset, ToPoint};
|
||||
|
@ -88,7 +88,6 @@ pub fn task_context(
|
|||
};
|
||||
editor.update(cx, |editor, cx| {
|
||||
let context_task = task_context_with_editor(editor, window, cx);
|
||||
cx.background_executor()
|
||||
.spawn(async move { context_task.await.unwrap_or_default() })
|
||||
cx.background_spawn(async move { context_task.await.unwrap_or_default() })
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue