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
Unified · Split
| @@ -3012,7 +3012,7 @@ impl CodegenAlternative { · 3011 unmodified lines | ||
| 3012 | 3012 | let executor = cx.background_executor().clone(); |
| 3013 | 3013 | let message_id = message_id.clone(); |
| 3014 | 3014 | let line_based_stream_diff: Task<anyhow::Result<()>> = |
| 3015 | − cx.background_executor().spawn(async move { | |
| 3015 | + cx.background_spawn(async move { | |
| 3016 | 3016 | let mut response_latency = None; |
| 3017 | 3017 | let request_start = Instant::now(); |
| 3018 | 3018 | let diff = async { |
| @@ -3326,8 +3326,7 @@ impl CodegenAlternative { · 307 unmodified lines | ||
| 3326 | 3326 | |
| 3327 | 3327 | cx.spawn(|codegen, mut cx| async move { |
| 3328 | 3328 | let (deleted_row_ranges, inserted_row_ranges) = cx |
| 3329 | − .background_executor() | |
| 3330 | − .spawn(async move { | |
| 3329 | + .background_spawn(async move { | |
| 3331 | 3330 | let old_text = old_snapshot |
| 3332 | 3331 | .text_for_range( |
| 3333 | 3332 | Point::new(old_range.start.row, 0) |
| @@ -1149,7 +1149,7 @@ impl Codegen { · 1148 unmodified lines | ||
| 1149 | 1149 | |
| 1150 | 1150 | let (mut hunks_tx, mut hunks_rx) = mpsc::channel(1); |
| 1151 | 1151 | |
| 1152 | − let task = cx.background_executor().spawn({ | |
| 1152 | + let task = cx.background_spawn({ | |
| 1153 | 1153 | let message_id = message_id.clone(); |
| 1154 | 1154 | let executor = cx.background_executor().clone(); |
| 1155 | 1155 | async move { |
| @@ -493,7 +493,7 @@ impl CodegenAlternative { · 492 unmodified lines | ||
| 493 | 493 | let executor = cx.background_executor().clone(); |
| 494 | 494 | let message_id = message_id.clone(); |
| 495 | 495 | let line_based_stream_diff: Task<anyhow::Result<()>> = |
| 496 | − cx.background_executor().spawn(async move { | |
| 496 | + cx.background_spawn(async move { | |
| 497 | 497 | let mut response_latency = None; |
| 498 | 498 | let request_start = Instant::now(); |
| 499 | 499 | let diff = async { |
| @@ -807,8 +807,7 @@ impl CodegenAlternative { · 307 unmodified lines | ||
| 807 | 807 | |
| 808 | 808 | cx.spawn(|codegen, mut cx| async move { |
| 809 | 809 | let (deleted_row_ranges, inserted_row_ranges) = cx |
| 810 | − .background_executor() | |
| 811 | − .spawn(async move { | |
| 810 | + .background_spawn(async move { | |
| 812 | 811 | let old_text = old_snapshot |
| 813 | 812 | .text_for_range( |
| 814 | 813 | Point::new(old_range.start.row, 0) |
| @@ -208,8 +208,7 @@ impl PickerDelegate for FetchContextPickerDelegate { · 207 unmodified lines | ||
| 208 | 208 | let confirm_behavior = self.confirm_behavior; |
| 209 | 209 | cx.spawn_in(window, |this, mut cx| async move { |
| 210 | 210 | let text = cx |
| 211 | − .background_executor() | |
| 212 | − .spawn(Self::build_message(http_client, url.clone())) | |
| 211 | + .background_spawn(Self::build_message(http_client, url.clone())) | |
| 213 | 212 | .await?; |
| 214 | 213 | |
| 215 | 214 | this.update_in(&mut cx, |this, window, cx| { |
| @@ -123,7 +123,7 @@ impl PickerDelegate for ThreadContextPickerDelegate { · 122 unmodified lines | ||
| 123 | 123 | }; |
| 124 | 124 | |
| 125 | 125 | let executor = cx.background_executor().clone(); |
| 126 | − let search_task = cx.background_executor().spawn(async move { | |
| 126 | + let search_task = cx.background_spawn(async move { | |
| 127 | 127 | if query.is_empty() { |
| 128 | 128 | threads |
| 129 | 129 | } else { |
| @@ -4,7 +4,7 @@ use std::sync::Arc; · 3 unmodified lines | ||
| 4 | 4 | use anyhow::{anyhow, bail, Result}; |
| 5 | 5 | use collections::{BTreeMap, HashMap, HashSet}; |
| 6 | 6 | use futures::{self, future, Future, FutureExt}; |
| 7 | −use gpui::{App, AsyncApp, Context, Entity, SharedString, Task, WeakEntity}; | |
| 7 | +use gpui::{App, AppContext as _, AsyncApp, Context, Entity, SharedString, Task, WeakEntity}; | |
| 8 | 8 | use language::Buffer; |
| 9 | 9 | use project::{ProjectPath, Worktree}; |
| 10 | 10 | use rope::Rope; |
| @@ -456,9 +456,7 @@ fn collect_buffer_info_and_text( · 445 unmodified lines | ||
| 456 | 456 | }; |
| 457 | 457 | // Important to collect version at the same time as content so that staleness logic is correct. |
| 458 | 458 | let content = buffer.as_rope().clone(); |
| 459 | − let text_task = cx | |
| 460 | − .background_executor() | |
| 461 | − .spawn(async move { to_fenced_codeblock(&path, content) }); | |
| 459 | + let text_task = cx.background_spawn(async move { to_fenced_codeblock(&path, content) }); | |
| 462 | 460 | (buffer_info, text_task) |
| 463 | 461 | } |
| 464 | 462 | |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use crate::inline_prompt_editor::CodegenStatus; |
| 2 | 2 | use client::telemetry::Telemetry; |
| 3 | 3 | use futures::{channel::mpsc, SinkExt, StreamExt}; |
| 4 | −use gpui::{App, Context, Entity, EventEmitter, Task}; | |
| 4 | +use gpui::{App, AppContext as _, Context, Entity, EventEmitter, Task}; | |
| 5 | 5 | use language_model::{LanguageModelRegistry, LanguageModelRequest}; |
| 6 | 6 | use language_models::report_assistant_event; |
| 7 | 7 | use std::{sync::Arc, time::Instant}; |
| @@ -53,7 +53,7 @@ impl TerminalCodegen { · 45 unmodified lines | ||
| 53 | 53 | |
| 54 | 54 | let (mut hunks_tx, mut hunks_rx) = mpsc::channel(1); |
| 55 | 55 | |
| 56 | − let task = cx.background_executor().spawn({ | |
| 56 | + let task = cx.background_spawn({ | |
| 57 | 57 | let message_id = message_id.clone(); |
| 58 | 58 | let executor = cx.background_executor().clone(); |
| 59 | 59 | async move { |
| @@ -849,7 +849,7 @@ impl AssistantContext { · 848 unmodified lines | ||
| 849 | 849 | .collect::<Vec<_>>(); |
| 850 | 850 | context_ops.extend(self.pending_ops.iter().cloned()); |
| 851 | 851 | |
| 852 | − cx.background_executor().spawn(async move { | |
| 852 | + cx.background_spawn(async move { | |
| 853 | 853 | let buffer_ops = buffer_ops.await; |
| 854 | 854 | context_ops.sort_unstable_by_key(|op| op.timestamp()); |
| 855 | 855 | buffer_ops |
| @@ -265,19 +265,18 @@ impl ContextStore { · 264 unmodified lines | ||
| 265 | 265 | local_versions.push(context.version(cx).to_proto(context_id.clone())); |
| 266 | 266 | let client = this.client.clone(); |
| 267 | 267 | let project_id = envelope.payload.project_id; |
| 268 | − cx.background_executor() | |
| 269 | − .spawn(async move { | |
| 270 | − let operations = operations.await; | |
| 271 | − for operation in operations { | |
| 272 | − client.send(proto::UpdateContext { | |
| 273 | − project_id, | |
| 274 | − context_id: context_id.to_proto(), | |
| 275 | − operation: Some(operation), | |
| 276 | − })?; | |
| 277 | − } | |
| 278 | − anyhow::Ok(()) | |
| 279 | − }) | |
| 280 | − .detach_and_log_err(cx); | |
| 268 | + cx.background_spawn(async move { | |
| 269 | + let operations = operations.await; | |
| 270 | + for operation in operations { | |
| 271 | + client.send(proto::UpdateContext { | |
| 272 | + project_id, | |
| 273 | + context_id: context_id.to_proto(), | |
| 274 | + operation: Some(operation), | |
| 275 | + })?; | |
| 276 | + } | |
| 277 | + anyhow::Ok(()) | |
| 278 | + }) | |
| 279 | + .detach_and_log_err(cx); | |
| 281 | 280 | } |
| 282 | 281 | } |
| 283 | 282 | |
| @@ -401,8 +400,7 @@ impl ContextStore { · 117 unmodified lines | ||
| 401 | 400 | ) |
| 402 | 401 | })?; |
| 403 | 402 | let operations = cx |
| 404 | − .background_executor() | |
| 405 | − .spawn(async move { | |
| 403 | + .background_spawn(async move { | |
| 406 | 404 | context_proto |
| 407 | 405 | .operations |
| 408 | 406 | .into_iter() |
| @@ -436,7 +434,7 @@ impl ContextStore { · 27 unmodified lines | ||
| 436 | 434 | let languages = self.languages.clone(); |
| 437 | 435 | let project = self.project.clone(); |
| 438 | 436 | let telemetry = self.telemetry.clone(); |
| 439 | − let load = cx.background_executor().spawn({ | |
| 437 | + let load = cx.background_spawn({ | |
| 440 | 438 | let path = path.clone(); |
| 441 | 439 | async move { |
| 442 | 440 | let saved_context = fs.load(&path).await?; |
| @@ -539,8 +537,7 @@ impl ContextStore { · 96 unmodified lines | ||
| 539 | 537 | ) |
| 540 | 538 | })?; |
| 541 | 539 | let operations = cx |
| 542 | − .background_executor() | |
| 543 | − .spawn(async move { | |
| 540 | + .background_spawn(async move { | |
| 544 | 541 | context_proto |
| 545 | 542 | .operations |
| 546 | 543 | .into_iter() |
| @@ -693,7 +690,7 @@ impl ContextStore { · 146 unmodified lines | ||
| 693 | 690 | pub fn search(&self, query: String, cx: &App) -> Task<Vec<SavedContextMetadata>> { |
| 694 | 691 | let metadata = self.contexts_metadata.clone(); |
| 695 | 692 | let executor = cx.background_executor().clone(); |
| 696 | − cx.background_executor().spawn(async move { | |
| 693 | + cx.background_spawn(async move { | |
| 697 | 694 | if query.is_empty() { |
| 698 | 695 | metadata |
| 699 | 696 | } else { |
| @@ -2,7 +2,7 @@ use anyhow::{anyhow, Context as _, Result}; · 1 unmodified line | ||
| 2 | 2 | use collections::HashMap; |
| 3 | 3 | use editor::ProposedChangesEditor; |
| 4 | 4 | use futures::{future, TryFutureExt as _}; |
| 5 | −use gpui::{App, AsyncApp, Entity, SharedString}; | |
| 5 | +use gpui::{App, AppContext as _, AsyncApp, Entity, SharedString}; | |
| 6 | 6 | use language::{AutoindentMode, Buffer, BufferSnapshot}; |
| 7 | 7 | use project::{Project, ProjectPath}; |
| 8 | 8 | use std::{cmp, ops::Range, path::Path, sync::Arc}; |
| @@ -258,8 +258,7 @@ impl AssistantEdit { · 249 unmodified lines | ||
| 258 | 258 | |
| 259 | 259 | let snapshot = buffer.update(&mut cx, |buffer, _| buffer.snapshot())?; |
| 260 | 260 | let suggestion = cx |
| 261 | − .background_executor() | |
| 262 | − .spawn(async move { kind.resolve(&snapshot) }) | |
| 261 | + .background_spawn(async move { kind.resolve(&snapshot) }) | |
| 263 | 262 | .await; |
| 264 | 263 | |
| 265 | 264 | Ok((buffer, suggestion)) |
| @@ -547,7 +546,7 @@ impl Eq for AssistantPatch {} · 281 unmodified lines | ||
| 547 | 546 | #[cfg(test)] |
| 548 | 547 | mod tests { |
| 549 | 548 | use super::*; |
| 550 | − use gpui::{App, AppContext as _}; | |
| 549 | + use gpui::App; | |
| 551 | 550 | use language::{ |
| 552 | 551 | language_settings::AllLanguageSettings, Language, LanguageConfig, LanguageMatcher, |
| 553 | 552 | }; |
| @@ -4,7 +4,7 @@ pub use assistant_slash_command::SlashCommand; · 3 unmodified lines | ||
| 4 | 4 | use assistant_slash_command::{AfterCompletion, SlashCommandLine, SlashCommandWorkingSet}; |
| 5 | 5 | use editor::{CompletionProvider, Editor}; |
| 6 | 6 | use fuzzy::{match_strings, StringMatchCandidate}; |
| 7 | −use gpui::{App, Context, Entity, Task, WeakEntity, Window}; | |
| 7 | +use gpui::{App, AppContext as _, Context, Entity, Task, WeakEntity, Window}; | |
| 8 | 8 | use language::{Anchor, Buffer, CompletionDocumentation, LanguageServerId, ToPoint}; |
| 9 | 9 | use parking_lot::Mutex; |
| 10 | 10 | use project::CompletionIntent; |
| @@ -162,7 +162,7 @@ impl SlashCommandCompletionProvider { · 151 unmodified lines | ||
| 162 | 162 | let editor = self.editor.clone(); |
| 163 | 163 | let workspace = self.workspace.clone(); |
| 164 | 164 | let arguments = arguments.to_vec(); |
| 165 | − cx.background_executor().spawn(async move { | |
| 165 | + cx.background_spawn(async move { | |
| 166 | 166 | Ok(completions |
| 167 | 167 | .await? |
| 168 | 168 | .into_iter() |
| @@ -102,8 +102,7 @@ impl PickerDelegate for SlashCommandDelegate { · 101 unmodified lines | ||
| 102 | 102 | let all_commands = self.all_commands.clone(); |
| 103 | 103 | cx.spawn_in(window, |this, mut cx| async move { |
| 104 | 104 | let filtered_commands = cx |
| 105 | − .background_executor() | |
| 106 | − .spawn(async move { | |
| 105 | + .background_spawn(async move { | |
| 107 | 106 | if query.is_empty() { |
| 108 | 107 | all_commands |
| 109 | 108 | } else { |
| @@ -103,7 +103,7 @@ impl SlashCommand for ExtensionSlashCommand { · 102 unmodified lines | ||
| 103 | 103 | ) -> Task<Result<Vec<ArgumentCompletion>>> { |
| 104 | 104 | let command = self.command.clone(); |
| 105 | 105 | let arguments = arguments.to_owned(); |
| 106 | − cx.background_executor().spawn(async move { | |
| 106 | + cx.background_spawn(async move { | |
| 107 | 107 | let completions = self |
| 108 | 108 | .extension |
| 109 | 109 | .complete_slash_command_argument(command, arguments) |
| @@ -135,7 +135,7 @@ impl SlashCommand for ExtensionSlashCommand { · 25 unmodified lines | ||
| 135 | 135 | ) -> Task<SlashCommandResult> { |
| 136 | 136 | let command = self.command.clone(); |
| 137 | 137 | let arguments = arguments.to_owned(); |
| 138 | − let output = cx.background_executor().spawn(async move { | |
| 138 | + let output = cx.background_spawn(async move { | |
| 139 | 139 | let delegate = |
| 140 | 140 | delegate.map(|delegate| Arc::new(WorktreeDelegateAdapter(delegate.clone())) as _); |
| 141 | 141 | let output = self |
| @@ -82,7 +82,7 @@ impl SlashCommand for AutoCommand { · 81 unmodified lines | ||
| 82 | 82 | project_index.flush_summary_backlogs(cx) |
| 83 | 83 | })?; |
| 84 | 84 | |
| 85 | − cx.background_executor().spawn(task).await; | |
| 85 | + cx.background_spawn(task).await; | |
| 86 | 86 | |
| 87 | 87 | anyhow::Ok(Vec::new()) |
| 88 | 88 | }) |
| @@ -129,7 +129,7 @@ impl SlashCommand for AutoCommand { · 40 unmodified lines | ||
| 129 | 129 | // so you don't have to write it again. |
| 130 | 130 | let original_prompt = argument.to_string(); |
| 131 | 131 | |
| 132 | − cx.background_executor().spawn(async move { | |
| 132 | + cx.background_spawn(async move { | |
| 133 | 133 | let commands = task.await?; |
| 134 | 134 | let mut prompt = String::new(); |
| 135 | 135 | |
| @@ -285,57 +285,56 @@ async fn commands_for_summaries( · 149 unmodified lines | ||
| 285 | 285 | }) |
| 286 | 286 | .collect::<Vec<_>>(); |
| 287 | 287 | |
| 288 | − cx.background_executor() | |
| 289 | − .spawn(async move { | |
| 290 | − let futures = completion_streams | |
| 291 | − .into_iter() | |
| 292 | − .enumerate() | |
| 293 | − .map(|(ix, (stream, tx))| async move { | |
| 294 | − let start = std::time::Instant::now(); | |
| 295 | − let events = stream.await?; | |
| 296 | − log::info!("Time taken for awaiting /await chunk stream #{ix}: {:?}", start.elapsed()); | |
| 297 | − | |
| 298 | − let completion: String = events | |
| 299 | − .filter_map(|event| async { | |
| 300 | − if let Ok(LanguageModelCompletionEvent::Text(text)) = event { | |
| 301 | − Some(text) | |
| 302 | − } else { | |
| 303 | − None | |
| 304 | − } | |
| 305 | − }) | |
| 306 | − .collect() | |
| 307 | − .await; | |
| 308 | − | |
| 309 | − log::info!("Time taken for all /auto chunks to come back for #{ix}: {:?}", start.elapsed()); | |
| 310 | − | |
| 311 | − for line in completion.split('\n') { | |
| 312 | − if let Some(first_space) = line.find(' ') { | |
| 313 | − let command = &line[..first_space].trim(); | |
| 314 | − let arg = &line[first_space..].trim(); | |
| 315 | − | |
| 316 | − tx.send(CommandToRun { | |
| 317 | − name: command.to_string(), | |
| 318 | − arg: arg.to_string(), | |
| 319 | − }) | |
| 320 | − .await?; | |
| 321 | − } else if !line.trim().is_empty() { | |
| 322 | − // All slash-commands currently supported in context inference need a space for the argument. | |
| 323 | − log::warn!( | |
| 324 | − "Context inference returned a non-blank line that contained no spaces (meaning no argument for the slash command): {:?}", | |
| 325 | − line | |
| 326 | − ); | |
| 288 | + cx.background_spawn(async move { | |
| 289 | + let futures = completion_streams | |
| 290 | + .into_iter() | |
| 291 | + .enumerate() | |
| 292 | + .map(|(ix, (stream, tx))| async move { | |
| 293 | + let start = std::time::Instant::now(); | |
| 294 | + let events = stream.await?; | |
| 295 | + log::info!("Time taken for awaiting /await chunk stream #{ix}: {:?}", start.elapsed()); | |
| 296 | + | |
| 297 | + let completion: String = events | |
| 298 | + .filter_map(|event| async { | |
| 299 | + if let Ok(LanguageModelCompletionEvent::Text(text)) = event { | |
| 300 | + Some(text) | |
| 301 | + } else { | |
| 302 | + None | |
| 327 | 303 | } |
| 304 | + }) | |
| 305 | + .collect() | |
| 306 | + .await; | |
| 307 | + | |
| 308 | + log::info!("Time taken for all /auto chunks to come back for #{ix}: {:?}", start.elapsed()); | |
| 309 | + | |
| 310 | + for line in completion.split('\n') { | |
| 311 | + if let Some(first_space) = line.find(' ') { | |
| 312 | + let command = &line[..first_space].trim(); | |
| 313 | + let arg = &line[first_space..].trim(); | |
| 314 | + | |
| 315 | + tx.send(CommandToRun { | |
| 316 | + name: command.to_string(), | |
| 317 | + arg: arg.to_string(), | |
| 318 | + }) | |
| 319 | + .await?; | |
| 320 | + } else if !line.trim().is_empty() { | |
| 321 | + // All slash-commands currently supported in context inference need a space for the argument. | |
| 322 | + log::warn!( | |
| 323 | + "Context inference returned a non-blank line that contained no spaces (meaning no argument for the slash command): {:?}", | |
| 324 | + line | |
| 325 | + ); | |
| 328 | 326 | } |
| 327 | + } | |
| 329 | 328 | |
| 330 | − anyhow::Ok(()) | |
| 331 | − }) | |
| 332 | − .collect::<Vec<_>>(); | |
| 329 | + anyhow::Ok(()) | |
| 330 | + }) | |
| 331 | + .collect::<Vec<_>>(); | |
| 333 | 332 | |
| 334 | − let _ = futures::future::try_join_all(futures).await.log_err(); | |
| 333 | + let _ = futures::future::try_join_all(futures).await.log_err(); | |
| 335 | 334 | |
| 336 | − let duration = all_start.elapsed(); | |
| 337 | − eprintln!("All futures completed in {:?}", duration); | |
| 338 | − }) | |
| 335 | + let duration = all_start.elapsed(); | |
| 336 | + eprintln!("All futures completed in {:?}", duration); | |
| 337 | + }) | |
| 339 | 338 | .await; |
| 340 | 339 | |
| 341 | 340 | drop(tx); // Close the channel so that rx.collect() won't hang. This is safe because all futures have completed. |
| @@ -132,7 +132,7 @@ impl SlashCommand for CargoWorkspaceSlashCommand { · 131 unmodified lines | ||
| 132 | 132 | let project = workspace.project().clone(); |
| 133 | 133 | let fs = workspace.project().read(cx).fs().clone(); |
| 134 | 134 | let path = Self::path_to_cargo_toml(project, cx); |
| 135 | − let output = cx.background_executor().spawn(async move { | |
| 135 | + let output = cx.background_spawn(async move { | |
| 136 | 136 | let path = path.with_context(|| "Cargo.toml not found")?; |
| 137 | 137 | Self::build_message(fs, &path).await |
| 138 | 138 | }); |
| @@ -54,7 +54,7 @@ impl SlashCommand for DefaultSlashCommand { · 53 unmodified lines | ||
| 54 | 54 | cx: &mut App, |
| 55 | 55 | ) -> Task<SlashCommandResult> { |
| 56 | 56 | let store = PromptStore::global(cx); |
| 57 | − cx.background_executor().spawn(async move { | |
| 57 | + cx.background_spawn(async move { | |
| 58 | 58 | let store = store.await?; |
| 59 | 59 | let prompts = store.default_prompt_metadata(); |
| 60 | 60 | |
| @@ -86,7 +86,7 @@ impl SlashCommand for DeltaSlashCommand { · 85 unmodified lines | ||
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | − cx.background_executor().spawn(async move { | |
| 89 | + cx.background_spawn(async move { | |
| 90 | 90 | let mut output = SlashCommandOutput::default(); |
| 91 | 91 | let mut changes_detected = false; |
| 92 | 92 | |
| @@ -129,7 +129,7 @@ impl SlashCommand for DiagnosticsSlashCommand { · 128 unmodified lines | ||
| 129 | 129 | |
| 130 | 130 | let paths = self.search_paths(query.clone(), cancellation_flag.clone(), &workspace, cx); |
| 131 | 131 | let executor = cx.background_executor().clone(); |
| 132 | − cx.background_executor().spawn(async move { | |
| 132 | + cx.background_spawn(async move { | |
| 133 | 133 | let mut matches: Vec<String> = paths |
| 134 | 134 | .await |
| 135 | 135 | .into_iter() |
| @@ -176,7 +176,7 @@ impl SlashCommand for DocsSlashCommand { · 175 unmodified lines | ||
| 176 | 176 | .provider() |
| 177 | 177 | .ok_or_else(|| anyhow!("no docs provider specified")) |
| 178 | 178 | .and_then(|provider| IndexedDocsStore::try_global(provider, cx)); |
| 179 | − cx.background_executor().spawn(async move { | |
| 179 | + cx.background_spawn(async move { | |
| 180 | 180 | fn build_completions(items: Vec<String>) -> Vec<ArgumentCompletion> { |
| 181 | 181 | items |
| 182 | 182 | .into_iter() |
| @@ -284,7 +284,7 @@ impl SlashCommand for DocsSlashCommand { · 101 unmodified lines | ||
| 284 | 284 | |
| 285 | 285 | let args = DocsSlashCommandArgs::parse(arguments); |
| 286 | 286 | let executor = cx.background_executor().clone(); |
| 287 | − let task = cx.background_executor().spawn({ | |
| 287 | + let task = cx.background_spawn({ | |
| 288 | 288 | let store = args |
| 289 | 289 | .provider() |
| 290 | 290 | .ok_or_else(|| anyhow!("no docs provider specified")) |
| @@ -151,7 +151,7 @@ impl SlashCommand for FetchSlashCommand { · 150 unmodified lines | ||
| 151 | 151 | let http_client = workspace.read(cx).client().http_client(); |
| 152 | 152 | let url = argument.to_string(); |
| 153 | 153 | |
| 154 | − let text = cx.background_executor().spawn({ | |
| 154 | + let text = cx.background_spawn({ | |
| 155 | 155 | let url = url.clone(); |
| 156 | 156 | async move { Self::build_message(http_client, &url).await } |
| 157 | 157 | }); |
| @@ -156,7 +156,7 @@ impl SlashCommand for FileSlashCommand { · 155 unmodified lines | ||
| 156 | 156 | cx, |
| 157 | 157 | ); |
| 158 | 158 | let comment_id = cx.theme().syntax().highlight_id("comment").map(HighlightId); |
| 159 | − cx.background_executor().spawn(async move { | |
| 159 | + cx.background_spawn(async move { | |
| 160 | 160 | Ok(paths |
| 161 | 161 | .await |
| 162 | 162 | .into_iter() |
| @@ -130,49 +130,48 @@ impl SlashCommand for ProjectSlashCommand { · 129 unmodified lines | ||
| 130 | 130 | |
| 131 | 131 | let results = SemanticDb::load_results(results, &fs, &cx).await?; |
| 132 | 132 | |
| 133 | − cx.background_executor() | |
| 134 | − .spawn(async move { | |
| 135 | − let mut output = "Project context:\n".to_string(); | |
| 136 | − let mut sections = Vec::new(); | |
| 137 | − | |
| 138 | − for (ix, query) in search_queries.into_iter().enumerate() { | |
| 139 | − let start_ix = output.len(); | |
| 140 | − writeln!(&mut output, "Results for {query}:").unwrap(); | |
| 141 | − let mut has_results = false; | |
| 142 | − for result in &results { | |
| 143 | − if result.query_index == ix { | |
| 144 | − add_search_result_section(result, &mut output, &mut sections); | |
| 145 | − has_results = true; | |
| 146 | − } | |
| 147 | − } | |
| 148 | − if has_results { | |
| 149 | − sections.push(SlashCommandOutputSection { | |
| 150 | − range: start_ix..output.len(), | |
| 151 | − icon: IconName::MagnifyingGlass, | |
| 152 | − label: query.into(), | |
| 153 | − metadata: None, | |
| 154 | − }); | |
| 155 | − output.push('\n'); | |
| 156 | − } else { | |
| 157 | − output.truncate(start_ix); | |
| 133 | + cx.background_spawn(async move { | |
| 134 | + let mut output = "Project context:\n".to_string(); | |
| 135 | + let mut sections = Vec::new(); | |
| 136 | + | |
| 137 | + for (ix, query) in search_queries.into_iter().enumerate() { | |
| 138 | + let start_ix = output.len(); | |
| 139 | + writeln!(&mut output, "Results for {query}:").unwrap(); | |
| 140 | + let mut has_results = false; | |
| 141 | + for result in &results { | |
| 142 | + if result.query_index == ix { | |
| 143 | + add_search_result_section(result, &mut output, &mut sections); | |
| 144 | + has_results = true; | |
| 158 | 145 | } |
| 159 | 146 | } |
| 160 | − | |
| 161 | − sections.push(SlashCommandOutputSection { | |
| 162 | − range: 0..output.len(), | |
| 163 | − icon: IconName::Book, | |
| 164 | − label: "Project context".into(), | |
| 165 | − metadata: None, | |
| 166 | − }); | |
| 167 | − | |
| 168 | − Ok(SlashCommandOutput { | |
| 169 | − text: output, | |
| 170 | − sections, | |
| 171 | − run_commands_in_text: true, | |
| 147 | + if has_results { | |
| 148 | + sections.push(SlashCommandOutputSection { | |
| 149 | + range: start_ix..output.len(), | |
| 150 | + icon: IconName::MagnifyingGlass, | |
| 151 | + label: query.into(), | |
| 152 | + metadata: None, | |
| 153 | + }); | |
| 154 | + output.push('\n'); | |
| 155 | + } else { | |
| 156 | + output.truncate(start_ix); | |
| 172 | 157 | } |
| 173 | − .to_event_stream()) | |
| 174 | − }) | |
| 175 | − .await | |
| 158 | + } | |
| 159 | + | |
| 160 | + sections.push(SlashCommandOutputSection { | |
| 161 | + range: 0..output.len(), | |
| 162 | + icon: IconName::Book, | |
| 163 | + label: "Project context".into(), | |
| 164 | + metadata: None, | |
| 165 | + }); | |
| 166 | + | |
| 167 | + Ok(SlashCommandOutput { | |
| 168 | + text: output, | |
| 169 | + sections, | |
| 170 | + run_commands_in_text: true, | |
| 171 | + } | |
| 172 | + .to_event_stream()) | |
| 173 | + }) | |
| 174 | + .await | |
| 176 | 175 | }) |
| 177 | 176 | } |
| 178 | 177 | } |
| @@ -43,7 +43,7 @@ impl SlashCommand for PromptSlashCommand { · 42 unmodified lines | ||
| 43 | 43 | ) -> Task<Result<Vec<ArgumentCompletion>>> { |
| 44 | 44 | let store = PromptStore::global(cx); |
| 45 | 45 | let query = arguments.to_owned().join(" "); |
| 46 | − cx.background_executor().spawn(async move { | |
| 46 | + cx.background_spawn(async move { | |
| 47 | 47 | let prompts = store.await?.search(query).await; |
| 48 | 48 | Ok(prompts |
| 49 | 49 | .into_iter() |
| @@ -77,7 +77,7 @@ impl SlashCommand for PromptSlashCommand { · 27 unmodified lines | ||
| 77 | 77 | |
| 78 | 78 | let store = PromptStore::global(cx); |
| 79 | 79 | let title = SharedString::from(title.clone()); |
| 80 | − let prompt = cx.background_executor().spawn({ | |
| 80 | + let prompt = cx.background_spawn({ | |
| 81 | 81 | let title = title.clone(); |
| 82 | 82 | async move { |
| 83 | 83 | let store = store.await?; |
| @@ -119,8 +119,7 @@ impl SlashCommand for SearchSlashCommand { · 118 unmodified lines | ||
| 119 | 119 | let loaded_results = SemanticDb::load_results(results, &fs, &cx).await?; |
| 120 | 120 | |
| 121 | 121 | let output = cx |
| 122 | − .background_executor() | |
| 123 | − .spawn(async move { | |
| 122 | + .background_spawn(async move { | |
| 124 | 123 | let mut text = format!("Search results for {query}:\n"); |
| 125 | 124 | let mut sections = Vec::new(); |
| 126 | 125 | for loaded_result in &loaded_results { |
| @@ -63,56 +63,55 @@ impl SlashCommand for StreamingExampleSlashCommand { · 62 unmodified lines | ||
| 63 | 63 | cx: &mut App, |
| 64 | 64 | ) -> Task<SlashCommandResult> { |
| 65 | 65 | let (events_tx, events_rx) = mpsc::unbounded(); |
| 66 | − cx.background_executor() | |
| 67 | − .spawn(async move { | |
| 68 | − events_tx.unbounded_send(Ok(SlashCommandEvent::StartSection { | |
| 69 | − icon: IconName::FileRust, | |
| 70 | − label: "Section 1".into(), | |
| 71 | − metadata: None, | |
| 72 | − }))?; | |
| 73 | − events_tx.unbounded_send(Ok(SlashCommandEvent::Content( | |
| 74 | − SlashCommandContent::Text { | |
| 75 | − text: "Hello".into(), | |
| 76 | − run_commands_in_text: false, | |
| 77 | − }, | |
| 78 | − )))?; | |
| 79 | − events_tx.unbounded_send(Ok(SlashCommandEvent::EndSection))?; | |
| 80 | − | |
| 66 | + cx.background_spawn(async move { | |
| 67 | + events_tx.unbounded_send(Ok(SlashCommandEvent::StartSection { | |
| 68 | + icon: IconName::FileRust, | |
| 69 | + label: "Section 1".into(), | |
| 70 | + metadata: None, | |
| 71 | + }))?; | |
| 72 | + events_tx.unbounded_send(Ok(SlashCommandEvent::Content( | |
| 73 | + SlashCommandContent::Text { | |
| 74 | + text: "Hello".into(), | |
| 75 | + run_commands_in_text: false, | |
| 76 | + }, | |
| 77 | + )))?; | |
| 78 | + events_tx.unbounded_send(Ok(SlashCommandEvent::EndSection))?; | |
| 79 | + | |
| 80 | + Timer::after(Duration::from_secs(1)).await; | |
| 81 | + | |
| 82 | + events_tx.unbounded_send(Ok(SlashCommandEvent::StartSection { | |
| 83 | + icon: IconName::FileRust, | |
| 84 | + label: "Section 2".into(), | |
| 85 | + metadata: None, | |
| 86 | + }))?; | |
| 87 | + events_tx.unbounded_send(Ok(SlashCommandEvent::Content( | |
| 88 | + SlashCommandContent::Text { | |
| 89 | + text: "World".into(), | |
| 90 | + run_commands_in_text: false, | |
| 91 | + }, | |
| 92 | + )))?; | |
| 93 | + events_tx.unbounded_send(Ok(SlashCommandEvent::EndSection))?; | |
| 94 | + | |
| 95 | + for n in 1..=10 { | |
| 81 | 96 | Timer::after(Duration::from_secs(1)).await; |
| 82 | 97 | |
| 83 | 98 | events_tx.unbounded_send(Ok(SlashCommandEvent::StartSection { |
| 84 | − icon: IconName::FileRust, | |
| 85 | − label: "Section 2".into(), | |
| 99 | + icon: IconName::StarFilled, | |
| 100 | + label: format!("Section {n}").into(), | |
| 86 | 101 | metadata: None, |
| 87 | 102 | }))?; |
| 88 | 103 | events_tx.unbounded_send(Ok(SlashCommandEvent::Content( |
| 89 | 104 | SlashCommandContent::Text { |
| 90 | − text: "World".into(), | |
| 105 | + text: "lorem ipsum ".repeat(n).trim().into(), | |
| 91 | 106 | run_commands_in_text: false, |
| 92 | 107 | }, |
| 93 | 108 | )))?; |
| 94 | 109 | events_tx.unbounded_send(Ok(SlashCommandEvent::EndSection))?; |
| 110 | + } | |
| 95 | 111 | |
| 96 | − for n in 1..=10 { | |
| 97 | − Timer::after(Duration::from_secs(1)).await; | |
| 98 | − | |
| 99 | − events_tx.unbounded_send(Ok(SlashCommandEvent::StartSection { | |
| 100 | − icon: IconName::StarFilled, | |
| 101 | − label: format!("Section {n}").into(), | |
| 102 | − metadata: None, | |
| 103 | − }))?; | |
| 104 | − events_tx.unbounded_send(Ok(SlashCommandEvent::Content( | |
| 105 | − SlashCommandContent::Text { | |
| 106 | − text: "lorem ipsum ".repeat(n).trim().into(), | |
| 107 | − run_commands_in_text: false, | |
| 108 | − }, | |
| 109 | − )))?; | |
| 110 | − events_tx.unbounded_send(Ok(SlashCommandEvent::EndSection))?; | |
| 111 | − } | |
| 112 | − | |
| 113 | − anyhow::Ok(()) | |
| 114 | − }) | |
| 115 | − .detach_and_log_err(cx); | |
| 112 | + anyhow::Ok(()) | |
| 113 | + }) | |
| 114 | + .detach_and_log_err(cx); | |
| 116 | 115 | |
| 117 | 116 | Task::ready(Ok(events_rx.boxed())) |
| 118 | 117 | } |
| @@ -4,7 +4,7 @@ use assistant_slash_command::{ · 3 unmodified lines | ||
| 4 | 4 | SlashCommandResult, |
| 5 | 5 | }; |
| 6 | 6 | use editor::Editor; |
| 7 | −use gpui::{Task, WeakEntity}; | |
| 7 | +use gpui::{AppContext as _, Task, WeakEntity}; | |
| 8 | 8 | use language::{BufferSnapshot, LspAdapterDelegate}; |
| 9 | 9 | use std::sync::Arc; |
| 10 | 10 | use std::{path::Path, sync::atomic::AtomicBool}; |
| @@ -69,7 +69,7 @@ impl SlashCommand for OutlineSlashCommand { · 58 unmodified lines | ||
| 69 | 69 | let snapshot = buffer.read(cx).snapshot(); |
| 70 | 70 | let path = snapshot.resolve_file_path(cx, true); |
| 71 | 71 | |
| 72 | − cx.background_executor().spawn(async move { | |
| 72 | + cx.background_spawn(async move { | |
| 73 | 73 | let outline = snapshot |
| 74 | 74 | .outline(None) |
| 75 | 75 | .context("no symbols for active tab")?; |
| @@ -152,7 +152,7 @@ impl SlashCommand for TabSlashCommand { · 151 unmodified lines | ||
| 152 | 152 | cx, |
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | − cx.background_executor().spawn(async move { | |
| 155 | + cx.background_spawn(async move { | |
| 156 | 156 | let mut output = SlashCommandOutput::default(); |
| 157 | 157 | for (full_path, buffer, _) in tab_items_search.await? { |
| 158 | 158 | append_buffer_to_output(&buffer, full_path.as_deref(), &mut output).log_err(); |
| @@ -212,74 +212,73 @@ fn tab_items_for_queries( · 53 unmodified lines | ||
| 212 | 212 | })??; |
| 213 | 213 | |
| 214 | 214 | let background_executor = cx.background_executor().clone(); |
| 215 | − cx.background_executor() | |
| 216 | − .spawn(async move { | |
| 217 | − open_buffers.sort_by_key(|(_, _, timestamp)| *timestamp); | |
| 218 | − if empty_query | |
| 219 | − || queries | |
| 220 | − .iter() | |
| 221 | − .any(|query| query == ALL_TABS_COMPLETION_ITEM) | |
| 222 | − { | |
| 223 | − return Ok(open_buffers); | |
| 224 | − } | |
| 225 | − | |
| 226 | − let matched_items = if strict_match { | |
| 227 | − let match_candidates = open_buffers | |
| 228 | − .iter() | |
| 229 | − .enumerate() | |
| 230 | − .filter_map(|(id, (full_path, ..))| { | |
| 231 | − let path_string = full_path.as_deref()?.to_string_lossy().to_string(); | |
| 232 | − Some((id, path_string)) | |
| 233 | − }) | |
| 234 | − .fold(HashMap::default(), |mut candidates, (id, path_string)| { | |
| 235 | − candidates | |
| 236 | − .entry(path_string) | |
| 237 | − .or_insert_with(Vec::new) | |
| 238 | − .push(id); | |
| 239 | − candidates | |
| 240 | − }); | |
| 215 | + cx.background_spawn(async move { | |
| 216 | + open_buffers.sort_by_key(|(_, _, timestamp)| *timestamp); | |
| 217 | + if empty_query | |
| 218 | + || queries | |
| 219 | + .iter() | |
| 220 | + .any(|query| query == ALL_TABS_COMPLETION_ITEM) | |
| 221 | + { | |
| 222 | + return Ok(open_buffers); | |
| 223 | + } | |
| 241 | 224 | |
| 242 | − queries | |
| 243 | − .iter() | |
| 244 | − .filter_map(|query| match_candidates.get(query)) | |
| 245 | − .flatten() | |
| 246 | − .copied() | |
| 247 | − .filter_map(|id| open_buffers.get(id)) | |
| 248 | − .cloned() | |
| 249 | − .collect() | |
| 250 | − } else { | |
| 251 | − let match_candidates = open_buffers | |
| 252 | − .iter() | |
| 253 | − .enumerate() | |
| 254 | − .filter_map(|(id, (full_path, ..))| { | |
| 255 | − let path_string = full_path.as_deref()?.to_string_lossy().to_string(); | |
| 256 | − Some(fuzzy::StringMatchCandidate::new(id, &path_string)) | |
| 257 | − }) | |
| 258 | − .collect::<Vec<_>>(); | |
| 259 | − let mut processed_matches = HashSet::default(); | |
| 260 | − let file_queries = queries.iter().map(|query| { | |
| 261 | − fuzzy::match_strings( | |
| 262 | − &match_candidates, | |
| 263 | − query, | |
| 264 | − true, | |
| 265 | − usize::MAX, | |
| 266 | − &cancel, | |
| 267 | − background_executor.clone(), | |
| 268 | − ) | |
| 225 | + let matched_items = if strict_match { | |
| 226 | + let match_candidates = open_buffers | |
| 227 | + .iter() | |
| 228 | + .enumerate() | |
| 229 | + .filter_map(|(id, (full_path, ..))| { | |
| 230 | + let path_string = full_path.as_deref()?.to_string_lossy().to_string(); | |
| 231 | + Some((id, path_string)) | |
| 232 | + }) | |
| 233 | + .fold(HashMap::default(), |mut candidates, (id, path_string)| { | |
| 234 | + candidates | |
| 235 | + .entry(path_string) | |
| 236 | + .or_insert_with(Vec::new) | |
| 237 | + .push(id); | |
| 238 | + candidates | |
| 269 | 239 | }); |
| 270 | 240 | |
| 271 | − join_all(file_queries) | |
| 272 | − .await | |
| 273 | − .into_iter() | |
| 274 | − .flatten() | |
| 275 | − .filter(|string_match| processed_matches.insert(string_match.candidate_id)) | |
| 276 | − .filter_map(|string_match| open_buffers.get(string_match.candidate_id)) | |
| 277 | − .cloned() | |
| 278 | − .collect() | |
| 279 | − }; | |
| 280 | − Ok(matched_items) | |
| 281 | − }) | |
| 282 | − .await | |
| 241 | + queries | |
| 242 | + .iter() | |
| 243 | + .filter_map(|query| match_candidates.get(query)) | |
| 244 | + .flatten() | |
| 245 | + .copied() | |
| 246 | + .filter_map(|id| open_buffers.get(id)) | |
| 247 | + .cloned() | |
| 248 | + .collect() | |
| 249 | + } else { | |
| 250 | + let match_candidates = open_buffers | |
| 251 | + .iter() | |
| 252 | + .enumerate() | |
| 253 | + .filter_map(|(id, (full_path, ..))| { | |
| 254 | + let path_string = full_path.as_deref()?.to_string_lossy().to_string(); | |
| 255 | + Some(fuzzy::StringMatchCandidate::new(id, &path_string)) | |
| 256 | + }) | |
| 257 | + .collect::<Vec<_>>(); | |
| 258 | + let mut processed_matches = HashSet::default(); | |
| 259 | + let file_queries = queries.iter().map(|query| { | |
| 260 | + fuzzy::match_strings( | |
| 261 | + &match_candidates, | |
| 262 | + query, | |
| 263 | + true, | |
| 264 | + usize::MAX, | |
| 265 | + &cancel, | |
| 266 | + background_executor.clone(), | |
| 267 | + ) | |
| 268 | + }); | |
| 269 | + | |
| 270 | + join_all(file_queries) | |
| 271 | + .await | |
| 272 | + .into_iter() | |
| 273 | + .flatten() | |
| 274 | + .filter(|string_match| processed_matches.insert(string_match.candidate_id)) | |
| 275 | + .filter_map(|string_match| open_buffers.get(string_match.candidate_id)) | |
| 276 | + .cloned() | |
| 277 | + .collect() | |
| 278 | + }; | |
| 279 | + Ok(matched_items) | |
| 280 | + }) | |
| 281 | + .await | |
| 283 | 282 | }) |
| 284 | 283 | } |
| 285 | 284 | |
| @@ -513,7 +513,7 @@ impl AutoUpdater { · 512 unmodified lines | ||
| 513 | 513 | should_show: bool, |
| 514 | 514 | cx: &App, |
| 515 | 515 | ) -> Task<Result<()>> { |
| 516 | − cx.background_executor().spawn(async move { | |
| 516 | + cx.background_spawn(async move { | |
| 517 | 517 | if should_show { |
| 518 | 518 | KEY_VALUE_STORE |
| 519 | 519 | .write_kvp( |
| @@ -531,7 +531,7 @@ impl AutoUpdater { · 11 unmodified lines | ||
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | pub fn should_show_update_notification(&self, cx: &App) -> Task<Result<bool>> { |
| 534 | − cx.background_executor().spawn(async move { | |
| 534 | + cx.background_spawn(async move { | |
| 535 | 535 | Ok(KEY_VALUE_STORE |
| 536 | 536 | .read_kvp(SHOULD_SHOW_UPDATE_NOTIFICATION_KEY)? |
| 537 | 537 | .is_some()) |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use futures::{channel::oneshot, future::OptionFuture}; |
| 2 | 2 | use git2::{DiffLineType as GitDiffLineType, DiffOptions as GitOptions, Patch as GitPatch}; |
| 3 | −use gpui::{App, AsyncApp, Context, Entity, EventEmitter}; | |
| 3 | +use gpui::{App, AppContext as _, AsyncApp, Context, Entity, EventEmitter}; | |
| 4 | 4 | use language::{Language, LanguageRegistry}; |
| 5 | 5 | use rope::Rope; |
| 6 | 6 | use std::{cmp, future::Future, iter, ops::Range, sync::Arc}; |
| @@ -615,11 +615,9 @@ impl BufferDiff { · 608 unmodified lines | ||
| 615 | 615 | cx, |
| 616 | 616 | ) |
| 617 | 617 | }); |
| 618 | − let base_text_snapshot = cx | |
| 619 | − .background_executor() | |
| 620 | − .spawn(OptionFuture::from(base_text_snapshot)); | |
| 618 | + let base_text_snapshot = cx.background_spawn(OptionFuture::from(base_text_snapshot)); | |
| 621 | 619 | |
| 622 | − let hunks = cx.background_executor().spawn({ | |
| 620 | + let hunks = cx.background_spawn({ | |
| 623 | 621 | let buffer = buffer.clone(); |
| 624 | 622 | async move { compute_hunks(diff_base, buffer) } |
| 625 | 623 | }); |
| @@ -641,7 +639,7 @@ impl BufferDiff { · 15 unmodified lines | ||
| 641 | 639 | .clone() |
| 642 | 640 | .map(|buffer| buffer.as_rope().clone()), |
| 643 | 641 | ); |
| 644 | − cx.background_executor().spawn(async move { | |
| 642 | + cx.background_spawn(async move { | |
| 645 | 643 | BufferDiffInner { |
| 646 | 644 | hunks: compute_hunks(diff_base, buffer), |
| 647 | 645 | base_text: diff_base_buffer, |
| @@ -998,7 +996,7 @@ mod tests { · 350 unmodified lines | ||
| 998 | 996 | use std::fmt::Write as _; |
| 999 | 997 | |
| 1000 | 998 | use super::*; |
| 1001 | − use gpui::{AppContext as _, TestAppContext}; | |
| 999 | + use gpui::TestAppContext; | |
| 1002 | 1000 | use rand::{rngs::StdRng, Rng as _}; |
| 1003 | 1001 | use text::{Buffer, BufferId, Rope}; |
| 1004 | 1002 | use unindent::Unindent as _; |
| @@ -241,7 +241,7 @@ impl ActiveCall { · 240 unmodified lines | ||
| 241 | 241 | }) |
| 242 | 242 | .shared(); |
| 243 | 243 | self.pending_room_creation = Some(room.clone()); |
| 244 | − cx.background_executor().spawn(async move { | |
| 244 | + cx.background_spawn(async move { | |
| 245 | 245 | room.await.map_err(|err| anyhow!("{:?}", err))?; |
| 246 | 246 | anyhow::Ok(()) |
| 247 | 247 | }) |
| @@ -278,7 +278,7 @@ impl ActiveCall { · 30 unmodified lines | ||
| 278 | 278 | }; |
| 279 | 279 | |
| 280 | 280 | let client = self.client.clone(); |
| 281 | − cx.background_executor().spawn(async move { | |
| 281 | + cx.background_spawn(async move { | |
| 282 | 282 | client |
| 283 | 283 | .request(proto::CancelCall { |
| 284 | 284 | room_id, |
| @@ -13,7 +13,7 @@ use client::{ · 12 unmodified lines | ||
| 13 | 13 | use collections::{BTreeMap, HashMap, HashSet}; |
| 14 | 14 | use fs::Fs; |
| 15 | 15 | use futures::{FutureExt, StreamExt}; |
| 16 | −use gpui::{App, AppContext, AsyncApp, Context, Entity, EventEmitter, Task, WeakEntity}; | |
| 16 | +use gpui::{App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, Task, WeakEntity}; | |
| 17 | 17 | use language::LanguageRegistry; |
| 18 | 18 | #[cfg(not(all(target_os = "windows", target_env = "gnu")))] |
| 19 | 19 | use livekit::{ |
| @@ -255,7 +255,7 @@ impl Room { · 235 unmodified lines | ||
| 255 | 255 | fn app_will_quit(&mut self, cx: &mut Context<Self>) -> impl Future<Output = ()> { |
| 256 | 256 | let task = if self.status.is_online() { |
| 257 | 257 | let leave = self.leave_internal(cx); |
| 258 | − Some(cx.background_executor().spawn(async move { | |
| 258 | + Some(cx.background_spawn(async move { | |
| 259 | 259 | leave.await.log_err(); |
| 260 | 260 | })) |
| 261 | 261 | } else { |
| @@ -322,7 +322,7 @@ impl Room { · 60 unmodified lines | ||
| 322 | 322 | self.clear_state(cx); |
| 323 | 323 | |
| 324 | 324 | let leave_room = self.client.request(proto::LeaveRoom {}); |
| 325 | − cx.background_executor().spawn(async move { | |
| 325 | + cx.background_spawn(async move { | |
| 326 | 326 | leave_room.await?; |
| 327 | 327 | anyhow::Ok(()) |
| 328 | 328 | }) |
| @@ -1248,7 +1248,7 @@ impl Room { · 919 unmodified lines | ||
| 1248 | 1248 | }; |
| 1249 | 1249 | |
| 1250 | 1250 | cx.notify(); |
| 1251 | − cx.background_executor().spawn(async move { | |
| 1251 | + cx.background_spawn(async move { | |
| 1252 | 1252 | client |
| 1253 | 1253 | .request(proto::UpdateParticipantLocation { |
| 1254 | 1254 | room_id, |
| @@ -1373,11 +1373,10 @@ impl Room { · 118 unmodified lines | ||
| 1373 | 1373 | match publication { |
| 1374 | 1374 | Ok(publication) => { |
| 1375 | 1375 | if canceled { |
| 1376 | − cx.background_executor() | |
| 1377 | − .spawn(async move { | |
| 1378 | − participant.unpublish_track(&publication.sid()).await | |
| 1379 | − }) | |
| 1380 | − .detach_and_log_err(cx) | |
| 1376 | + cx.background_spawn(async move { | |
| 1377 | + participant.unpublish_track(&publication.sid()).await | |
| 1378 | + }) | |
| 1379 | + .detach_and_log_err(cx) | |
| 1381 | 1380 | } else { |
| 1382 | 1381 | if live_kit.muted_by_user || live_kit.deafened { |
| 1383 | 1382 | publication.mute(); |
| @@ -1465,11 +1464,10 @@ impl Room { · 81 unmodified lines | ||
| 1465 | 1464 | match publication { |
| 1466 | 1465 | Ok(publication) => { |
| 1467 | 1466 | if canceled { |
| 1468 | − cx.background_executor() | |
| 1469 | − .spawn(async move { | |
| 1470 | − participant.unpublish_track(&publication.sid()).await | |
| 1471 | − }) | |
| 1472 | − .detach() | |
| 1467 | + cx.background_spawn(async move { | |
| 1468 | + participant.unpublish_track(&publication.sid()).await | |
| 1469 | + }) | |
| 1470 | + .detach() | |
| 1473 | 1471 | } else { |
| 1474 | 1472 | live_kit.screen_track = LocalTrack::Published { |
| 1475 | 1473 | track_publication: publication, |
| @@ -1561,9 +1559,10 @@ impl Room { · 85 unmodified lines | ||
| 1561 | 1559 | { |
| 1562 | 1560 | let local_participant = live_kit.room.local_participant(); |
| 1563 | 1561 | let sid = track_publication.sid(); |
| 1564 | − cx.background_executor() | |
| 1565 | − .spawn(async move { local_participant.unpublish_track(&sid).await }) | |
| 1566 | − .detach_and_log_err(cx); | |
| 1562 | + cx.background_spawn( | |
| 1563 | + async move { local_participant.unpublish_track(&sid).await }, | |
| 1564 | + ) | |
| 1565 | + .detach_and_log_err(cx); | |
| 1567 | 1566 | cx.notify(); |
| 1568 | 1567 | } |
| 1569 | 1568 | |
| @@ -1722,13 +1721,12 @@ impl LiveKitRoom { · 152 unmodified lines | ||
| 1722 | 1721 | } |
| 1723 | 1722 | |
| 1724 | 1723 | let participant = self.room.local_participant(); |
| 1725 | − cx.background_executor() | |
| 1726 | − .spawn(async move { | |
| 1727 | − for sid in tracks_to_unpublish { | |
| 1728 | − participant.unpublish_track(&sid).await.log_err(); | |
| 1729 | − } | |
| 1730 | − }) | |
| 1731 | − .detach(); | |
| 1724 | + cx.background_spawn(async move { | |
| 1725 | + for sid in tracks_to_unpublish { | |
| 1726 | + participant.unpublish_track(&sid).await.log_err(); | |
| 1727 | + } | |
| 1728 | + }) | |
| 1729 | + .detach(); | |
| 1732 | 1730 | } |
| 1733 | 1731 | } |
| 1734 | 1732 | |
| @@ -234,7 +234,7 @@ impl ActiveCall { · 233 unmodified lines | ||
| 234 | 234 | }) |
| 235 | 235 | .shared(); |
| 236 | 236 | self.pending_room_creation = Some(room.clone()); |
| 237 | − cx.background_executor().spawn(async move { | |
| 237 | + cx.background_spawn(async move { | |
| 238 | 238 | room.await.map_err(|err| anyhow!("{:?}", err))?; |
| 239 | 239 | anyhow::Ok(()) |
| 240 | 240 | }) |
| @@ -271,7 +271,7 @@ impl ActiveCall { · 30 unmodified lines | ||
| 271 | 271 | }; |
| 272 | 272 | |
| 273 | 273 | let client = self.client.clone(); |
| 274 | − cx.background_executor().spawn(async move { | |
| 274 | + cx.background_spawn(async move { | |
| 275 | 275 | client |
| 276 | 276 | .request(proto::CancelCall { |
| 277 | 277 | room_id, |
| @@ -311,7 +311,7 @@ impl Room { · 310 unmodified lines | ||
| 311 | 311 | fn app_will_quit(&mut self, cx: &mut Context<Self>) -> impl Future<Output = ()> { |
| 312 | 312 | let task = if self.status.is_online() { |
| 313 | 313 | let leave = self.leave_internal(cx); |
| 314 | − Some(cx.background_executor().spawn(async move { | |
| 314 | + Some(cx.background_spawn(async move { | |
| 315 | 315 | leave.await.log_err(); |
| 316 | 316 | })) |
| 317 | 317 | } else { |
| @@ -378,7 +378,7 @@ impl Room { · 60 unmodified lines | ||
| 378 | 378 | self.clear_state(cx); |
| 379 | 379 | |
| 380 | 380 | let leave_room = self.client.request(proto::LeaveRoom {}); |
| 381 | − cx.background_executor().spawn(async move { | |
| 381 | + cx.background_spawn(async move { | |
| 382 | 382 | leave_room.await?; |
| 383 | 383 | anyhow::Ok(()) |
| 384 | 384 | }) |
| @@ -1268,7 +1268,7 @@ impl Room { · 883 unmodified lines | ||
| 1268 | 1268 | }; |
| 1269 | 1269 | |
| 1270 | 1270 | cx.notify(); |
| 1271 | − cx.background_executor().spawn(async move { | |
| 1271 | + cx.background_spawn(async move { | |
| 1272 | 1272 | client |
| 1273 | 1273 | .request(proto::UpdateParticipantLocation { |
| 1274 | 1274 | room_id, |
| @@ -1385,9 +1385,7 @@ impl Room { · 110 unmodified lines | ||
| 1385 | 1385 | live_kit.room.unpublish_track(publication); |
| 1386 | 1386 | } else { |
| 1387 | 1387 | if live_kit.muted_by_user || live_kit.deafened { |
| 1388 | − cx.background_executor() | |
| 1389 | − .spawn(publication.set_mute(true)) | |
| 1390 | − .detach(); | |
| 1388 | + cx.background_spawn(publication.set_mute(true)).detach(); | |
| 1391 | 1389 | } |
| 1392 | 1390 | live_kit.microphone_track = LocalTrack::Published { |
| 1393 | 1391 | track_publication: publication, |
| @@ -514,8 +514,7 @@ impl ChannelStore { · 513 unmodified lines | ||
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | }; |
| 517 | − cx.background_executor() | |
| 518 | − .spawn(async move { task.await.map_err(|error| anyhow!("{}", error)) }) | |
| 517 | + cx.background_spawn(async move { task.await.map_err(|error| anyhow!("{}", error)) }) | |
| 519 | 518 | } |
| 520 | 519 | |
| 521 | 520 | pub fn is_channel_admin(&self, channel_id: ChannelId) -> bool { |
| @@ -781,7 +780,7 @@ impl ChannelStore { · 259 unmodified lines | ||
| 781 | 780 | cx: &mut Context<Self>, |
| 782 | 781 | ) -> Task<Result<()>> { |
| 783 | 782 | let client = self.client.clone(); |
| 784 | − cx.background_executor().spawn(async move { | |
| 783 | + cx.background_spawn(async move { | |
| 785 | 784 | client |
| 786 | 785 | .request(proto::RespondToChannelInvite { |
| 787 | 786 | channel_id: channel_id.0, |
| @@ -975,21 +974,18 @@ impl ChannelStore { · 187 unmodified lines | ||
| 975 | 974 | |
| 976 | 975 | if let Some(operations) = operations { |
| 977 | 976 | let client = this.client.clone(); |
| 978 | − cx.background_executor() | |
| 979 | − .spawn(async move { | |
| 980 | − let operations = operations.await; | |
| 981 | − for chunk in | |
| 982 | − language::proto::split_operations(operations) | |
| 983 | − { | |
| 984 | − client | |
| 985 | − .send(proto::UpdateChannelBuffer { | |
| 986 | − channel_id: channel_id.0, | |
| 987 | − operations: chunk, | |
| 988 | − }) | |
| 989 | − .ok(); | |
| 990 | − } | |
| 991 | − }) | |
| 992 | − .detach(); | |
| 977 | + cx.background_spawn(async move { | |
| 978 | + let operations = operations.await; | |
| 979 | + for chunk in language::proto::split_operations(operations) { | |
| 980 | + client | |
| 981 | + .send(proto::UpdateChannelBuffer { | |
| 982 | + channel_id: channel_id.0, | |
| 983 | + operations: chunk, | |
| 984 | + }) | |
| 985 | + .ok(); | |
| 986 | + } | |
| 987 | + }) | |
| 988 | + .detach(); | |
| 993 | 989 | return true; |
| 994 | 990 | } |
| 995 | 991 | } |
| @@ -19,7 +19,7 @@ use futures::{ · 18 unmodified lines | ||
| 19 | 19 | channel::oneshot, future::BoxFuture, AsyncReadExt, FutureExt, SinkExt, Stream, StreamExt, |
| 20 | 20 | TryFutureExt as _, TryStreamExt, |
| 21 | 21 | }; |
| 22 | −use gpui::{actions, App, AsyncApp, Entity, Global, Task, WeakEntity}; | |
| 22 | +use gpui::{actions, App, AppContext as _, AsyncApp, Entity, Global, Task, WeakEntity}; | |
| 23 | 23 | use http_client::{AsyncBody, HttpClient, HttpClientWithUrl}; |
| 24 | 24 | use parking_lot::RwLock; |
| 25 | 25 | use postage::watch; |
| @@ -1064,7 +1064,7 @@ impl Client { · 1038 unmodified lines | ||
| 1064 | 1064 | let rpc_url = self.rpc_url(http, release_channel); |
| 1065 | 1065 | let system_id = self.telemetry.system_id(); |
| 1066 | 1066 | let metrics_id = self.telemetry.metrics_id(); |
| 1067 | − cx.background_executor().spawn(async move { | |
| 1067 | + cx.background_spawn(async move { | |
| 1068 | 1068 | use HttpOrHttps::*; |
| 1069 | 1069 | |
| 1070 | 1070 | #[derive(Debug)] |
| @@ -1743,7 +1743,7 @@ mod tests { · 672 unmodified lines | ||
| 1743 | 1743 | use crate::test::FakeServer; |
| 1744 | 1744 | |
| 1745 | 1745 | use clock::FakeSystemClock; |
| 1746 | − use gpui::{AppContext as _, BackgroundExecutor, TestAppContext}; | |
| 1746 | + use gpui::{BackgroundExecutor, TestAppContext}; | |
| 1747 | 1747 | use http_client::FakeHttpClient; |
| 1748 | 1748 | use parking_lot::Mutex; |
| 1749 | 1749 | use proto::TypedEnvelope; |
| @@ -1806,7 +1806,7 @@ mod tests { · 56 unmodified lines | ||
| 1806 | 1806 | |
| 1807 | 1807 | // Time out when client tries to connect. |
| 1808 | 1808 | client.override_authenticate(move |cx| { |
| 1809 | − cx.background_executor().spawn(async move { | |
| 1809 | + cx.background_spawn(async move { | |
| 1810 | 1810 | Ok(Credentials { |
| 1811 | 1811 | user_id, |
| 1812 | 1812 | access_token: "token".into(), |
| @@ -1814,7 +1814,7 @@ mod tests { · 1 unmodified line | ||
| 1814 | 1814 | }) |
| 1815 | 1815 | }); |
| 1816 | 1816 | client.override_establish_connection(|_, cx| { |
| 1817 | − cx.background_executor().spawn(async move { | |
| 1817 | + cx.background_spawn(async move { | |
| 1818 | 1818 | future::pending::<()>().await; |
| 1819 | 1819 | unreachable!() |
| 1820 | 1820 | }) |
| @@ -1848,7 +1848,7 @@ mod tests { · 27 unmodified lines | ||
| 1848 | 1848 | // Time out when re-establishing the connection. |
| 1849 | 1849 | server.allow_connections(); |
| 1850 | 1850 | client.override_establish_connection(|_, cx| { |
| 1851 | − cx.background_executor().spawn(async move { | |
| 1851 | + cx.background_spawn(async move { | |
| 1852 | 1852 | future::pending::<()>().await; |
| 1853 | 1853 | unreachable!() |
| 1854 | 1854 | }) |
| @@ -1887,7 +1887,7 @@ mod tests { · 32 unmodified lines | ||
| 1887 | 1887 | move |cx| { |
| 1888 | 1888 | let auth_count = auth_count.clone(); |
| 1889 | 1889 | let dropped_auth_count = dropped_auth_count.clone(); |
| 1890 | − cx.background_executor().spawn(async move { | |
| 1890 | + cx.background_spawn(async move { | |
| 1891 | 1891 | *auth_count.lock() += 1; |
| 1892 | 1892 | let _drop = util::defer(move || *dropped_auth_count.lock() += 1); |
| 1893 | 1893 | future::pending::<()>().await; |
| @@ -5,7 +5,7 @@ use anyhow::Result; · 4 unmodified lines | ||
| 5 | 5 | use clock::SystemClock; |
| 6 | 6 | use futures::channel::mpsc; |
| 7 | 7 | use futures::{Future, StreamExt}; |
| 8 | −use gpui::{App, BackgroundExecutor, Task}; | |
| 8 | +use gpui::{App, AppContext as _, BackgroundExecutor, Task}; | |
| 9 | 9 | use http_client::{self, AsyncBody, HttpClient, HttpClientWithUrl, Method, Request}; |
| 10 | 10 | use parking_lot::Mutex; |
| 11 | 11 | use release_channel::ReleaseChannel; |
| @@ -219,18 +219,17 @@ impl Telemetry { · 207 unmodified lines | ||
| 219 | 219 | })); |
| 220 | 220 | Self::log_file_path(); |
| 221 | 221 | |
| 222 | − cx.background_executor() | |
| 223 | − .spawn({ | |
| 224 | − let state = state.clone(); | |
| 225 | − let os_version = os_version(); | |
| 226 | − state.lock().os_version = Some(os_version.clone()); | |
| 227 | − async move { | |
| 228 | − if let Some(tempfile) = File::create(Self::log_file_path()).log_err() { | |
| 229 | − state.lock().log_file = Some(tempfile); | |
| 230 | − } | |
| 222 | + cx.background_spawn({ | |
| 223 | + let state = state.clone(); | |
| 224 | + let os_version = os_version(); | |
| 225 | + state.lock().os_version = Some(os_version.clone()); | |
| 226 | + async move { | |
| 227 | + if let Some(tempfile) = File::create(Self::log_file_path()).log_err() { | |
| 228 | + state.lock().log_file = Some(tempfile); | |
| 231 | 229 | } |
| 232 | − }) | |
| 233 | − .detach(); | |
| 230 | + } | |
| 231 | + }) | |
| 232 | + .detach(); | |
| 234 | 233 | |
| 235 | 234 | cx.observe_global::<SettingsStore>({ |
| 236 | 235 | let state = state.clone(); |
| @@ -252,17 +251,16 @@ impl Telemetry { · 15 unmodified lines | ||
| 252 | 251 | let (tx, mut rx) = mpsc::unbounded(); |
| 253 | 252 | ::telemetry::init(tx); |
| 254 | 253 | |
| 255 | − cx.background_executor() | |
| 256 | − .spawn({ | |
| 257 | − let this = Arc::downgrade(&this); | |
| 258 | − async move { | |
| 259 | − while let Some(event) = rx.next().await { | |
| 260 | − let Some(state) = this.upgrade() else { break }; | |
| 261 | − state.report_event(Event::Flexible(event)) | |
| 262 | − } | |
| 254 | + cx.background_spawn({ | |
| 255 | + let this = Arc::downgrade(&this); | |
| 256 | + async move { | |
| 257 | + while let Some(event) = rx.next().await { | |
| 258 | + let Some(state) = this.upgrade() else { break }; | |
| 259 | + state.report_event(Event::Flexible(event)) | |
| 263 | 260 | } |
| 264 | − }) | |
| 265 | − .detach(); | |
| 261 | + } | |
| 262 | + }) | |
| 263 | + .detach(); | |
| 266 | 264 | |
| 267 | 265 | // We should only ever have one instance of Telemetry, leak the subscription to keep it alive |
| 268 | 266 | // rather than store in TelemetryState, complicating spawn as subscriptions are not Send |
| @@ -85,7 +85,7 @@ impl FakeServer { · 84 unmodified lines | ||
| 85 | 85 | Connection::in_memory(cx.background_executor().clone()); |
| 86 | 86 | let (connection_id, io, incoming) = |
| 87 | 87 | peer.add_test_connection(server_conn, cx.background_executor().clone()); |
| 88 | − cx.background_executor().spawn(io).detach(); | |
| 88 | + cx.background_spawn(io).detach(); | |
| 89 | 89 | { |
| 90 | 90 | let mut state = state.lock(); |
| 91 | 91 | state.connection_id = Some(connection_id); |
| @@ -244,18 +244,17 @@ impl TestServer { · 243 unmodified lines | ||
| 244 | 244 | .await |
| 245 | 245 | .expect("retrieving user failed") |
| 246 | 246 | .unwrap(); |
| 247 | − cx.background_executor() | |
| 248 | − .spawn(server.handle_connection( | |
| 249 | − server_conn, | |
| 250 | − client_name, | |
| 251 | − Principal::User(user), | |
| 252 | − ZedVersion(SemanticVersion::new(1, 0, 0)), | |
| 253 | − None, | |
| 254 | − None, | |
| 255 | − Some(connection_id_tx), | |
| 256 | − Executor::Deterministic(cx.background_executor().clone()), | |
| 257 | − )) | |
| 258 | − .detach(); | |
| 247 | + cx.background_spawn(server.handle_connection( | |
| 248 | + server_conn, | |
| 249 | + client_name, | |
| 250 | + Principal::User(user), | |
| 251 | + ZedVersion(SemanticVersion::new(1, 0, 0)), | |
| 252 | + None, | |
| 253 | + None, | |
| 254 | + Some(connection_id_tx), | |
| 255 | + Executor::Deterministic(cx.background_executor().clone()), | |
| 256 | + )) | |
| 257 | + .detach(); | |
| 259 | 258 | let connection_id = connection_id_rx.await.map_err(|e| { |
| 260 | 259 | EstablishConnectionError::Other(anyhow!( |
| 261 | 260 | "{} (is server shutting down?)", |
| @@ -201,8 +201,7 @@ impl ChatPanel { · 200 unmodified lines | ||
| 201 | 201 | ) -> Task<Result<Entity<Self>>> { |
| 202 | 202 | cx.spawn(|mut cx| async move { |
| 203 | 203 | let serialized_panel = if let Some(panel) = cx |
| 204 | − .background_executor() | |
| 205 | − .spawn(async move { KEY_VALUE_STORE.read_kvp(CHAT_PANEL_KEY) }) | |
| 204 | + .background_spawn(async move { KEY_VALUE_STORE.read_kvp(CHAT_PANEL_KEY) }) | |
| 206 | 205 | .await |
| 207 | 206 | .log_err() |
| 208 | 207 | .flatten() |
| @@ -227,7 +226,7 @@ impl ChatPanel { · 18 unmodified lines | ||
| 227 | 226 | |
| 228 | 227 | fn serialize(&mut self, cx: &mut Context<Self>) { |
| 229 | 228 | let width = self.width; |
| 230 | − self.pending_serialization = cx.background_executor().spawn( | |
| 229 | + self.pending_serialization = cx.background_spawn( | |
| 231 | 230 | async move { |
| 232 | 231 | KEY_VALUE_STORE |
| 233 | 232 | .write_kvp( |
| @@ -454,8 +454,7 @@ impl MessageEditor { · 453 unmodified lines | ||
| 454 | 454 | mut cx: AsyncWindowContext, |
| 455 | 455 | ) { |
| 456 | 456 | let (buffer, ranges) = cx |
| 457 | − .background_executor() | |
| 458 | − .spawn(async move { | |
| 457 | + .background_spawn(async move { | |
| 459 | 458 | let ranges = MENTIONS_SEARCH.search(&buffer, None).await; |
| 460 | 459 | (buffer, ranges) |
| 461 | 460 | }) |
| @@ -319,8 +319,7 @@ impl CollabPanel { · 318 unmodified lines | ||
| 319 | 319 | mut cx: AsyncWindowContext, |
| 320 | 320 | ) -> anyhow::Result<Entity<Self>> { |
| 321 | 321 | let serialized_panel = cx |
| 322 | − .background_executor() | |
| 323 | − .spawn(async move { KEY_VALUE_STORE.read_kvp(COLLABORATION_PANEL_KEY) }) | |
| 322 | + .background_spawn(async move { KEY_VALUE_STORE.read_kvp(COLLABORATION_PANEL_KEY) }) | |
| 324 | 323 | .await |
| 325 | 324 | .map_err(|_| anyhow::anyhow!("Failed to read collaboration panel from key value store")) |
| 326 | 325 | .log_err() |
| @@ -351,7 +350,7 @@ impl CollabPanel { · 24 unmodified lines | ||
| 351 | 350 | fn serialize(&mut self, cx: &mut Context<Self>) { |
| 352 | 351 | let width = self.width; |
| 353 | 352 | let collapsed_channels = self.collapsed_channels.clone(); |
| 354 | − self.pending_serialization = cx.background_executor().spawn( | |
| 353 | + self.pending_serialization = cx.background_spawn( | |
| 355 | 354 | async move { |
| 356 | 355 | KEY_VALUE_STORE |
| 357 | 356 | .write_kvp( |
| @@ -183,8 +183,7 @@ impl NotificationPanel { · 182 unmodified lines | ||
| 183 | 183 | ) -> Task<Result<Entity<Self>>> { |
| 184 | 184 | cx.spawn(|mut cx| async move { |
| 185 | 185 | let serialized_panel = if let Some(panel) = cx |
| 186 | − .background_executor() | |
| 187 | − .spawn(async move { KEY_VALUE_STORE.read_kvp(NOTIFICATION_PANEL_KEY) }) | |
| 186 | + .background_spawn(async move { KEY_VALUE_STORE.read_kvp(NOTIFICATION_PANEL_KEY) }) | |
| 188 | 187 | .await |
| 189 | 188 | .log_err() |
| 190 | 189 | .flatten() |
| @@ -209,7 +208,7 @@ impl NotificationPanel { · 18 unmodified lines | ||
| 209 | 208 | |
| 210 | 209 | fn serialize(&mut self, cx: &mut Context<Self>) { |
| 211 | 210 | let width = self.width; |
| 212 | − self.pending_serialization = cx.background_executor().spawn( | |
| 211 | + self.pending_serialization = cx.background_spawn( | |
| 213 | 212 | async move { |
| 214 | 213 | KEY_VALUE_STORE |
| 215 | 214 | .write_kvp( |
| @@ -281,7 +281,7 @@ impl PickerDelegate for CommandPaletteDelegate { · 280 unmodified lines | ||
| 281 | 281 | query = alias.to_string(); |
| 282 | 282 | } |
| 283 | 283 | let (mut tx, mut rx) = postage::dispatch::channel(1); |
| 284 | − let task = cx.background_executor().spawn({ | |
| 284 | + let task = cx.background_spawn({ | |
| 285 | 285 | let mut commands = self.all_commands.clone(); |
| 286 | 286 | let hit_counts = cx.global::<HitCounts>().clone(); |
| 287 | 287 | let executor = cx.background_executor().clone(); |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use anyhow::{anyhow, Context as _, Result}; |
| 2 | 2 | use collections::HashMap; |
| 3 | 3 | use futures::{channel::oneshot, io::BufWriter, select, AsyncRead, AsyncWrite, FutureExt}; |
| 4 | −use gpui::{AsyncApp, BackgroundExecutor, Task}; | |
| 4 | +use gpui::{AppContext as _, AsyncApp, BackgroundExecutor, Task}; | |
| 5 | 5 | use parking_lot::Mutex; |
| 6 | 6 | use postage::barrier; |
| 7 | 7 | use serde::{de::DeserializeOwned, Deserialize, Serialize}; |
| @@ -192,7 +192,7 @@ impl Client { · 184 unmodified lines | ||
| 192 | 192 | let (stdout, stderr) = futures::join!(stdout_input_task, stderr_input_task); |
| 193 | 193 | stdout.or(stderr) |
| 194 | 194 | }); |
| 195 | − let output_task = cx.background_executor().spawn({ | |
| 195 | + let output_task = cx.background_spawn({ | |
| 196 | 196 | Self::handle_output( |
| 197 | 197 | stdin, |
| 198 | 198 | outbound_rx, |
| @@ -234,8 +234,7 @@ impl RegisteredBuffer { · 233 unmodified lines | ||
| 234 | 234 | let new_snapshot = buffer.update(&mut cx, |buffer, _| buffer.snapshot()).ok()?; |
| 235 | 235 | |
| 236 | 236 | let content_changes = cx |
| 237 | − .background_executor() | |
| 238 | − .spawn({ | |
| 237 | + .background_spawn({ | |
| 239 | 238 | let new_snapshot = new_snapshot.clone(); |
| 240 | 239 | async move { |
| 241 | 240 | new_snapshot |
| @@ -588,8 +587,7 @@ impl Copilot { · 346 unmodified lines | ||
| 588 | 587 | } |
| 589 | 588 | }; |
| 590 | 589 | |
| 591 | − cx.background_executor() | |
| 592 | − .spawn(task.map_err(|err| anyhow!("{:?}", err))) | |
| 590 | + cx.background_spawn(task.map_err(|err| anyhow!("{:?}", err))) | |
| 593 | 591 | } else { |
| 594 | 592 | // If we're downloading, wait until download is finished |
| 595 | 593 | // If we're in a stuck state, display to the user |
| @@ -601,7 +599,7 @@ impl Copilot { · 5 unmodified lines | ||
| 601 | 599 | self.update_sign_in_status(request::SignInStatus::NotSignedIn, cx); |
| 602 | 600 | if let CopilotServer::Running(RunningCopilotServer { lsp: server, .. }) = &self.server { |
| 603 | 601 | let server = server.clone(); |
| 604 | − cx.background_executor().spawn(async move { | |
| 602 | + cx.background_spawn(async move { | |
| 605 | 603 | server |
| 606 | 604 | .request::<request::SignOut>(request::SignOutParams {}) |
| 607 | 605 | .await?; |
| @@ -631,7 +629,7 @@ impl Copilot { · 23 unmodified lines | ||
| 631 | 629 | |
| 632 | 630 | cx.notify(); |
| 633 | 631 | |
| 634 | − cx.background_executor().spawn(start_task) | |
| 632 | + cx.background_spawn(start_task) | |
| 635 | 633 | } |
| 636 | 634 | |
| 637 | 635 | pub fn language_server(&self) -> Option<&Arc<LanguageServer>> { |
| @@ -813,7 +811,7 @@ impl Copilot { · 175 unmodified lines | ||
| 813 | 811 | .request::<request::NotifyAccepted>(request::NotifyAcceptedParams { |
| 814 | 812 | uuid: completion.uuid.clone(), |
| 815 | 813 | }); |
| 816 | − cx.background_executor().spawn(async move { | |
| 814 | + cx.background_spawn(async move { | |
| 817 | 815 | request.await?; |
| 818 | 816 | Ok(()) |
| 819 | 817 | }) |
| @@ -837,7 +835,7 @@ impl Copilot { · 17 unmodified lines | ||
| 837 | 835 | .map(|completion| completion.uuid.clone()) |
| 838 | 836 | .collect(), |
| 839 | 837 | }); |
| 840 | − cx.background_executor().spawn(async move { | |
| 838 | + cx.background_spawn(async move { | |
| 841 | 839 | request.await?; |
| 842 | 840 | Ok(()) |
| 843 | 841 | }) |
| @@ -884,7 +882,7 @@ impl Copilot { · 40 unmodified lines | ||
| 884 | 882 | .map(|file| file.path().to_path_buf()) |
| 885 | 883 | .unwrap_or_default(); |
| 886 | 884 | |
| 887 | − cx.background_executor().spawn(async move { | |
| 885 | + cx.background_spawn(async move { | |
| 888 | 886 | let (version, snapshot) = snapshot.await?; |
| 889 | 887 | let result = lsp |
| 890 | 888 | .request::<R>(request::GetCompletionsParams { |
| @@ -4,7 +4,7 @@ pub mod query; · 3 unmodified lines | ||
| 4 | 4 | // Re-export |
| 5 | 5 | pub use anyhow; |
| 6 | 6 | use anyhow::Context as _; |
| 7 | −use gpui::App; | |
| 7 | +use gpui::{App, AppContext}; | |
| 8 | 8 | pub use indoc::indoc; |
| 9 | 9 | pub use paths::database_dir; |
| 10 | 10 | pub use smol; |
| @@ -192,8 +192,7 @@ pub fn write_and_log<F>(cx: &App, db_write: impl FnOnce() -> F + Send + 'static) · 181 unmodified lines | ||
| 192 | 192 | where |
| 193 | 193 | F: Future<Output = anyhow::Result<()>> + Send, |
| 194 | 194 | { |
| 195 | − cx.background_executor() | |
| 196 | − .spawn(async move { db_write().await.log_err() }) | |
| 195 | + cx.background_spawn(async move { db_write().await.log_err() }) | |
| 197 | 196 | .detach() |
| 198 | 197 | } |
| 199 | 198 | |
| @@ -171,7 +171,7 @@ impl WrapMap { · 170 unmodified lines | ||
| 171 | 171 | |
| 172 | 172 | let text_system = cx.text_system().clone(); |
| 173 | 173 | let (font, font_size) = self.font_with_size.clone(); |
| 174 | − let task = cx.background_executor().spawn(async move { | |
| 174 | + let task = cx.background_spawn(async move { | |
| 175 | 175 | let mut line_wrapper = text_system.line_wrapper(font, font_size); |
| 176 | 176 | let tab_snapshot = new_snapshot.tab_snapshot.clone(); |
| 177 | 177 | let range = TabPoint::zero()..tab_snapshot.max_point(); |
| @@ -255,7 +255,7 @@ impl WrapMap { · 77 unmodified lines | ||
| 255 | 255 | let mut snapshot = self.snapshot.clone(); |
| 256 | 256 | let text_system = cx.text_system().clone(); |
| 257 | 257 | let (font, font_size) = self.font_with_size.clone(); |
| 258 | − let update_task = cx.background_executor().spawn(async move { | |
| 258 | + let update_task = cx.background_spawn(async move { | |
| 259 | 259 | let mut edits = Patch::default(); |
| 260 | 260 | let mut line_wrapper = text_system.line_wrapper(font, font_size); |
| 261 | 261 | for (tab_snapshot, tab_edits) in pending_edits { |
| @@ -4798,7 +4798,7 @@ impl Editor { · 4797 unmodified lines | ||
| 4798 | 4798 | let Some(matches_task) = editor |
| 4799 | 4799 | .read_with(&mut cx, |editor, cx| { |
| 4800 | 4800 | let buffer = editor.buffer().read(cx).snapshot(cx); |
| 4801 | − cx.background_executor().spawn(async move { | |
| 4801 | + cx.background_spawn(async move { | |
| 4802 | 4802 | let mut ranges = Vec::new(); |
| 4803 | 4803 | let buffer_ranges = |
| 4804 | 4804 | vec![buffer.anchor_before(0)..buffer.anchor_after(buffer.len())]; |
| @@ -10221,13 +10221,12 @@ impl Editor { · 5416 unmodified lines | ||
| 10221 | 10221 | return; |
| 10222 | 10222 | } |
| 10223 | 10223 | let new_rows = |
| 10224 | − cx.background_executor() | |
| 10225 | − .spawn({ | |
| 10226 | − let snapshot = display_snapshot.clone(); | |
| 10227 | − async move { | |
| 10228 | − Self::fetch_runnable_ranges(&snapshot, Anchor::min()..Anchor::max()) | |
| 10229 | − } | |
| 10230 | − }) | |
| 10224 | + cx.background_spawn({ | |
| 10225 | + let snapshot = display_snapshot.clone(); | |
| 10226 | + async move { | |
| 10227 | + Self::fetch_runnable_ranges(&snapshot, Anchor::min()..Anchor::max()) | |
| 10228 | + } | |
| 10229 | + }) | |
| 10231 | 10230 | .await; |
| 10232 | 10231 | |
| 10233 | 10232 | let rows = Self::runnable_rows(project, display_snapshot, new_rows, cx.clone()); |
| @@ -10989,7 +10988,7 @@ impl Editor { · 755 unmodified lines | ||
| 10989 | 10988 | HoverLink::InlayHint(lsp_location, server_id) => { |
| 10990 | 10989 | let computation = |
| 10991 | 10990 | self.compute_target_location(lsp_location, server_id, window, cx); |
| 10992 | − cx.background_executor().spawn(async move { | |
| 10991 | + cx.background_spawn(async move { | |
| 10993 | 10992 | let location = computation.await?; |
| 10994 | 10993 | Ok(TargetTaskResult::Location(location)) |
| 10995 | 10994 | }) |
| @@ -15587,7 +15586,7 @@ fn snippet_completions( · 4591 unmodified lines | ||
| 15587 | 15586 | let scope = language.map(|language| language.default_scope()); |
| 15588 | 15587 | let executor = cx.background_executor().clone(); |
| 15589 | 15588 | |
| 15590 | − cx.background_executor().spawn(async move { | |
| 15589 | + cx.background_spawn(async move { | |
| 15591 | 15590 | let classifier = CharClassifier::new(scope).for_completion(true); |
| 15592 | 15591 | let mut last_word = chars |
| 15593 | 15592 | .chars() |
| @@ -15717,7 +15716,7 @@ impl CompletionProvider for Entity<Project> { · 123 unmodified lines | ||
| 15717 | 15716 | self.update(cx, |project, cx| { |
| 15718 | 15717 | let snippets = snippet_completions(project, buffer, buffer_position, cx); |
| 15719 | 15718 | let project_completions = project.completions(buffer, buffer_position, options, cx); |
| 15720 | − cx.background_executor().spawn(async move { | |
| 15719 | + cx.background_spawn(async move { | |
| 15721 | 15720 | let mut completions = project_completions.await?; |
| 15722 | 15721 | let snippets_completions = snippets.await?; |
| 15723 | 15722 | completions.extend(snippets_completions); |
| @@ -5264,8 +5264,7 @@ impl EditorElement { · 5263 unmodified lines | ||
| 5264 | 5264 | Some(cx.spawn_in(window, |editor, mut cx| async move { |
| 5265 | 5265 | let scrollbar_size = scrollbar_layout.hitbox.size; |
| 5266 | 5266 | let scrollbar_markers = cx |
| 5267 | − .background_executor() | |
| 5268 | − .spawn(async move { | |
| 5267 | + .background_spawn(async move { | |
| 5269 | 5268 | let max_point = snapshot.display_snapshot.buffer_snapshot.max_point(); |
| 5270 | 5269 | let mut marker_quads = Vec::new(); |
| 5271 | 5270 | if scrollbar_settings.git_diff { |
| @@ -4,7 +4,7 @@ use git::{ · 3 unmodified lines | ||
| 4 | 4 | blame::{Blame, BlameEntry}, |
| 5 | 5 | parse_git_remote_url, GitHostingProvider, GitHostingProviderRegistry, Oid, |
| 6 | 6 | }; |
| 7 | −use gpui::{App, Context, Entity, Subscription, Task}; | |
| 7 | +use gpui::{App, AppContext as _, Context, Entity, Subscription, Task}; | |
| 8 | 8 | use http_client::HttpClient; |
| 9 | 9 | use language::{markdown, Bias, Buffer, BufferSnapshot, Edit, LanguageRegistry, ParsedMarkdown}; |
| 10 | 10 | use multi_buffer::RowInfo; |
| @@ -360,8 +360,7 @@ impl GitBlame { · 349 unmodified lines | ||
| 360 | 360 | |
| 361 | 361 | self.task = cx.spawn(|this, mut cx| async move { |
| 362 | 362 | let result = cx |
| 363 | − .background_executor() | |
| 364 | − .spawn({ | |
| 363 | + .background_spawn({ | |
| 365 | 364 | let snapshot = snapshot.clone(); |
| 366 | 365 | async move { |
| 367 | 366 | let Some(Blame { |
| @@ -549,7 +548,7 @@ async fn parse_markdown(text: &str, language_registry: &Arc<LanguageRegistry>) - · 181 unmodified lines | ||
| 549 | 548 | #[cfg(test)] |
| 550 | 549 | mod tests { |
| 551 | 550 | use super::*; |
| 552 | − use gpui::{AppContext as _, Context}; | |
| 551 | + use gpui::Context; | |
| 553 | 552 | use language::{Point, Rope}; |
| 554 | 553 | use project::FakeFs; |
| 555 | 554 | use rand::prelude::*; |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use collections::{HashMap, HashSet}; |
| 2 | 2 | use git::diff::DiffHunkStatus; |
| 3 | 3 | use gpui::{ |
| 4 | − Action, AppContext, Corner, CursorStyle, Focusable as _, Hsla, Model, MouseButton, | |
| 4 | + Action, AppContext as _, Corner, CursorStyle, Focusable as _, Hsla, Model, MouseButton, | |
| 5 | 5 | Subscription, Task, |
| 6 | 6 | }; |
| 7 | 7 | use language::{Buffer, BufferId, Point}; |
| @@ -372,7 +372,7 @@ impl Editor { · 364 unmodified lines | ||
| 372 | 372 | |
| 373 | 373 | self.diff_map |
| 374 | 374 | .hunk_update_tasks |
| 375 | − .insert(None, cx.background_executor().spawn(new_toggle_task)); | |
| 375 | + .insert(None, cx.background_spawn(new_toggle_task)); | |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | pub(super) fn expand_diff_hunk( |
| @@ -1089,10 +1089,9 @@ impl Editor { · 710 unmodified lines | ||
| 1089 | 1089 | .ok(); |
| 1090 | 1090 | }); |
| 1091 | 1091 | |
| 1092 | − diff_map.hunk_update_tasks.insert( | |
| 1093 | − Some(buffer_id), | |
| 1094 | − cx.background_executor().spawn(new_sync_task), | |
| 1095 | − ); | |
| 1092 | + diff_map | |
| 1093 | + .hunk_update_tasks | |
| 1094 | + .insert(Some(buffer_id), cx.background_spawn(new_sync_task)); | |
| 1096 | 1095 | } |
| 1097 | 1096 | |
| 1098 | 1097 | fn go_to_subsequent_hunk( |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use std::{ops::Range, time::Duration}; |
| 2 | 2 | |
| 3 | 3 | use collections::HashSet; |
| 4 | −use gpui::{App, Context, Task, Window}; | |
| 4 | +use gpui::{App, AppContext as _, Context, Task, Window}; | |
| 5 | 5 | use language::language_settings::language_settings; |
| 6 | 6 | use multi_buffer::{IndentGuide, MultiBufferRow}; |
| 7 | 7 | use text::{LineIndent, Point}; |
| @@ -102,9 +102,7 @@ impl Editor { · 94 unmodified lines | ||
| 102 | 102 | |
| 103 | 103 | let snapshot = snapshot.clone(); |
| 104 | 104 | |
| 105 | − let task = cx | |
| 106 | − .background_executor() | |
| 107 | − .spawn(resolve_indented_range(snapshot, cursor_row)); | |
| 105 | + let task = cx.background_spawn(resolve_indented_range(snapshot, cursor_row)); | |
| 108 | 106 | |
| 109 | 107 | // Try to resolve the indent in a short amount of time, otherwise move it to a background task. |
| 110 | 108 | match cx |
| @@ -115,7 +113,7 @@ impl Editor { · 4 unmodified lines | ||
| 115 | 113 | Err(future) => { |
| 116 | 114 | state.pending_refresh = |
| 117 | 115 | Some(cx.spawn_in(window, |editor, mut cx| async move { |
| 118 | − let result = cx.background_executor().spawn(future).await; | |
| 116 | + let result = cx.background_spawn(future).await; | |
| 119 | 117 | editor |
| 120 | 118 | .update(&mut cx, |editor, _| { |
| 121 | 119 | editor.active_indent_guides_state.active_indent_range = result; |
| @@ -19,7 +19,7 @@ use crate::{ · 18 unmodified lines | ||
| 19 | 19 | use anyhow::Context as _; |
| 20 | 20 | use clock::Global; |
| 21 | 21 | use futures::future; |
| 22 | −use gpui::{AsyncApp, Context, Entity, Task, Window}; | |
| 22 | +use gpui::{AppContext as _, AsyncApp, Context, Entity, Task, Window}; | |
| 23 | 23 | use language::{language_settings::InlayHintKind, Buffer, BufferSnapshot}; |
| 24 | 24 | use parking_lot::RwLock; |
| 25 | 25 | use project::{InlayHint, ResolveState}; |
| @@ -996,19 +996,17 @@ fn fetch_and_update_hints( · 970 unmodified lines | ||
| 996 | 996 | |
| 997 | 997 | let background_task_buffer_snapshot = buffer_snapshot.clone(); |
| 998 | 998 | let background_fetch_range = fetch_range.clone(); |
| 999 | − let new_update = cx | |
| 1000 | − .background_executor() | |
| 1001 | − .spawn(async move { | |
| 1002 | − calculate_hint_updates( | |
| 1003 | − query.excerpt_id, | |
| 1004 | − invalidate, | |
| 1005 | − background_fetch_range, | |
| 1006 | − new_hints, | |
| 1007 | − &background_task_buffer_snapshot, | |
| 1008 | − cached_excerpt_hints, | |
| 1009 | − &visible_hints, | |
| 1010 | − ) | |
| 1011 | − }) | |
| 999 | + let new_update = cx.background_spawn(async move { | |
| 1000 | + calculate_hint_updates( | |
| 1001 | + query.excerpt_id, | |
| 1002 | + invalidate, | |
| 1003 | + background_fetch_range, | |
| 1004 | + new_hints, | |
| 1005 | + &background_task_buffer_snapshot, | |
| 1006 | + cached_excerpt_hints, | |
| 1007 | + &visible_hints, | |
| 1008 | + ) | |
| 1009 | + }) | |
| 1012 | 1010 | .await; |
| 1013 | 1011 | if let Some(new_update) = new_update { |
| 1014 | 1012 | log::debug!( |
| @@ -1225,28 +1225,27 @@ impl SerializableItem for Editor { · 1224 unmodified lines | ||
| 1225 | 1225 | let snapshot = buffer.read(cx).snapshot(); |
| 1226 | 1226 | |
| 1227 | 1227 | Some(cx.spawn_in(window, |_this, cx| async move { |
| 1228 | − cx.background_executor() | |
| 1229 | − .spawn(async move { | |
| 1230 | − let (contents, language) = if serialize_dirty_buffers && is_dirty { | |
| 1231 | − let contents = snapshot.text(); | |
| 1232 | − let language = snapshot.language().map(|lang| lang.name().to_string()); | |
| 1233 | − (Some(contents), language) | |
| 1234 | − } else { | |
| 1235 | − (None, None) | |
| 1236 | − }; | |
| 1228 | + cx.background_spawn(async move { | |
| 1229 | + let (contents, language) = if serialize_dirty_buffers && is_dirty { | |
| 1230 | + let contents = snapshot.text(); | |
| 1231 | + let language = snapshot.language().map(|lang| lang.name().to_string()); | |
| 1232 | + (Some(contents), language) | |
| 1233 | + } else { | |
| 1234 | + (None, None) | |
| 1235 | + }; | |
| 1237 | 1236 | |
| 1238 | − let editor = SerializedEditor { | |
| 1239 | − abs_path, | |
| 1240 | − contents, | |
| 1241 | − language, | |
| 1242 | − mtime, | |
| 1243 | − }; | |
| 1244 | − DB.save_serialized_editor(item_id, workspace_id, editor) | |
| 1245 | − .await | |
| 1246 | − .context("failed to save serialized editor") | |
| 1247 | − }) | |
| 1248 | − .await | |
| 1249 | − .context("failed to save contents of buffer")?; | |
| 1237 | + let editor = SerializedEditor { | |
| 1238 | + abs_path, | |
| 1239 | + contents, | |
| 1240 | + language, | |
| 1241 | + mtime, | |
| 1242 | + }; | |
| 1243 | + DB.save_serialized_editor(item_id, workspace_id, editor) | |
| 1244 | + .await | |
| 1245 | + .context("failed to save serialized editor") | |
| 1246 | + }) | |
| 1247 | + .await | |
| 1248 | + .context("failed to save contents of buffer")?; | |
| 1250 | 1249 | |
| 1251 | 1250 | Ok(()) |
| 1252 | 1251 | })) |
| @@ -1540,7 +1539,7 @@ impl SearchableItem for Editor { · 287 unmodified lines | ||
| 1540 | 1539 | ranges.iter().cloned().collect::<Vec<_>>() |
| 1541 | 1540 | }); |
| 1542 | 1541 | |
| 1543 | − cx.background_executor().spawn(async move { | |
| 1542 | + cx.background_spawn(async move { | |
| 1544 | 1543 | let mut ranges = Vec::new(); |
| 1545 | 1544 | |
| 1546 | 1545 | let search_within_ranges = if search_within_ranges.is_empty() { |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use crate::Editor; |
| 2 | 2 | |
| 3 | −use gpui::{App, Task as AsyncTask, Window}; | |
| 3 | +use gpui::{App, AppContext as _, Task as AsyncTask, Window}; | |
| 4 | 4 | use project::Location; |
| 5 | 5 | use task::{TaskContext, TaskVariables, VariableName}; |
| 6 | 6 | use text::{ToOffset, ToPoint}; |
| @@ -88,7 +88,6 @@ pub fn task_context( · 81 unmodified lines | ||
| 88 | 88 | }; |
| 89 | 89 | editor.update(cx, |editor, cx| { |
| 90 | 90 | let context_task = task_context_with_editor(editor, window, cx); |
| 91 | − cx.background_executor() | |
| 92 | − .spawn(async move { context_task.await.unwrap_or_default() }) | |
| 91 | + cx.background_spawn(async move { context_task.await.unwrap_or_default() }) | |
| 93 | 92 | }) |
| 94 | 93 | } |
| @@ -324,10 +324,7 @@ impl ExtensionStore { · 323 unmodified lines | ||
| 324 | 324 | load_initial_extensions.await; |
| 325 | 325 | |
| 326 | 326 | let mut index_changed = false; |
| 327 | − let mut debounce_timer = cx | |
| 328 | − .background_executor() | |
| 329 | − .spawn(futures::future::pending()) | |
| 330 | − .fuse(); | |
| 327 | + let mut debounce_timer = cx.background_spawn(futures::future::pending()).fuse(); | |
| 331 | 328 | loop { |
| 332 | 329 | select_biased! { |
| 333 | 330 | _ = debounce_timer => { |
| @@ -370,7 +367,7 @@ impl ExtensionStore { · 36 unmodified lines | ||
| 370 | 367 | // Watch the installed extensions directory for changes. Whenever changes are |
| 371 | 368 | // detected, rebuild the extension index, and load/unload any extensions that |
| 372 | 369 | // have been added, removed, or modified. |
| 373 | − this.tasks.push(cx.background_executor().spawn({ | |
| 370 | + this.tasks.push(cx.background_spawn({ | |
| 374 | 371 | let fs = this.fs.clone(); |
| 375 | 372 | let reload_tx = this.reload_tx.clone(); |
| 376 | 373 | let installed_dir = this.installed_dir.clone(); |
| @@ -886,20 +883,19 @@ impl ExtensionStore { · 509 unmodified lines | ||
| 886 | 883 | } |
| 887 | 884 | }); |
| 888 | 885 | |
| 889 | − cx.background_executor() | |
| 890 | − .spawn({ | |
| 891 | − let extension_source_path = extension_source_path.clone(); | |
| 892 | − async move { | |
| 893 | − builder | |
| 894 | − .compile_extension( | |
| 895 | − &extension_source_path, | |
| 896 | − &mut extension_manifest, | |
| 897 | − CompileExtensionOptions { release: false }, | |
| 898 | − ) | |
| 899 | − .await | |
| 900 | − } | |
| 901 | − }) | |
| 902 | − .await?; | |
| 886 | + cx.background_spawn({ | |
| 887 | + let extension_source_path = extension_source_path.clone(); | |
| 888 | + async move { | |
| 889 | + builder | |
| 890 | + .compile_extension( | |
| 891 | + &extension_source_path, | |
| 892 | + &mut extension_manifest, | |
| 893 | + CompileExtensionOptions { release: false }, | |
| 894 | + ) | |
| 895 | + .await | |
| 896 | + } | |
| 897 | + }) | |
| 898 | + .await?; | |
| 903 | 899 | |
| 904 | 900 | let output_path = &extensions_dir.join(extension_id.as_ref()); |
| 905 | 901 | if let Some(metadata) = fs.metadata(output_path).await? { |
| @@ -937,7 +933,7 @@ impl ExtensionStore { · 31 unmodified lines | ||
| 937 | 933 | }; |
| 938 | 934 | |
| 939 | 935 | cx.notify(); |
| 940 | − let compile = cx.background_executor().spawn(async move { | |
| 936 | + let compile = cx.background_spawn(async move { | |
| 941 | 937 | let mut manifest = ExtensionManifest::load(fs, &path).await?; |
| 942 | 938 | builder |
| 943 | 939 | .compile_extension( |
| @@ -1192,35 +1188,33 @@ impl ExtensionStore { · 248 unmodified lines | ||
| 1192 | 1188 | cx.emit(Event::ExtensionsUpdated); |
| 1193 | 1189 | |
| 1194 | 1190 | cx.spawn(|this, mut cx| async move { |
| 1195 | − cx.background_executor() | |
| 1196 | − .spawn({ | |
| 1197 | − let fs = fs.clone(); | |
| 1198 | − async move { | |
| 1199 | − for theme_path in themes_to_add.into_iter() { | |
| 1200 | − proxy | |
| 1201 | − .load_user_theme(theme_path, fs.clone()) | |
| 1202 | − .await | |
| 1203 | − .log_err(); | |
| 1204 | − } | |
| 1191 | + cx.background_spawn({ | |
| 1192 | + let fs = fs.clone(); | |
| 1193 | + async move { | |
| 1194 | + for theme_path in themes_to_add.into_iter() { | |
| 1195 | + proxy | |
| 1196 | + .load_user_theme(theme_path, fs.clone()) | |
| 1197 | + .await | |
| 1198 | + .log_err(); | |
| 1199 | + } | |
| 1205 | 1200 | |
| 1206 | − for (icon_theme_path, icons_root_path) in icon_themes_to_add.into_iter() { | |
| 1201 | + for (icon_theme_path, icons_root_path) in icon_themes_to_add.into_iter() { | |
| 1202 | + proxy | |
| 1203 | + .load_icon_theme(icon_theme_path, icons_root_path, fs.clone()) | |
| 1204 | + .await | |
| 1205 | + .log_err(); | |
| 1206 | + } | |
| 1207 | + | |
| 1208 | + for snippets_path in &snippets_to_add { | |
| 1209 | + if let Some(snippets_contents) = fs.load(snippets_path).await.log_err() { | |
| 1207 | 1210 | proxy |
| 1208 | − .load_icon_theme(icon_theme_path, icons_root_path, fs.clone()) | |
| 1209 | − .await | |
| 1211 | + .register_snippet(snippets_path, &snippets_contents) | |
| 1210 | 1212 | .log_err(); |
| 1211 | 1213 | } |
| 1212 | − | |
| 1213 | − for snippets_path in &snippets_to_add { | |
| 1214 | − if let Some(snippets_contents) = fs.load(snippets_path).await.log_err() | |
| 1215 | − { | |
| 1216 | − proxy | |
| 1217 | − .register_snippet(snippets_path, &snippets_contents) | |
| 1218 | − .log_err(); | |
| 1219 | − } | |
| 1220 | − } | |
| 1221 | 1214 | } |
| 1222 | − }) | |
| 1223 | − .await; | |
| 1215 | + } | |
| 1216 | + }) | |
| 1217 | + .await; | |
| 1224 | 1218 | |
| 1225 | 1219 | let mut wasm_extensions = Vec::new(); |
| 1226 | 1220 | for extension in extension_entries { |
| @@ -1304,7 +1298,7 @@ impl ExtensionStore { · 77 unmodified lines | ||
| 1304 | 1298 | let extensions_dir = self.installed_dir.clone(); |
| 1305 | 1299 | let index_path = self.index_path.clone(); |
| 1306 | 1300 | let proxy = self.proxy.clone(); |
| 1307 | − cx.background_executor().spawn(async move { | |
| 1301 | + cx.background_spawn(async move { | |
| 1308 | 1302 | let start_time = Instant::now(); |
| 1309 | 1303 | let mut index = ExtensionIndex::default(); |
| 1310 | 1304 | |
| @@ -1494,7 +1488,7 @@ impl ExtensionStore { · 183 unmodified lines | ||
| 1494 | 1488 | return Task::ready(Err(anyhow!("extension no longer installed"))); |
| 1495 | 1489 | }; |
| 1496 | 1490 | let fs = self.fs.clone(); |
| 1497 | − cx.background_executor().spawn(async move { | |
| 1491 | + cx.background_spawn(async move { | |
| 1498 | 1492 | const EXTENSION_TOML: &str = "extension.toml"; |
| 1499 | 1493 | const EXTENSION_WASM: &str = "extension.wasm"; |
| 1500 | 1494 | const CONFIG_TOML: &str = "config.toml"; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use client::telemetry; |
| 2 | −use gpui::{App, Task, Window}; | |
| 2 | +use gpui::{App, AppContext as _, Task, Window}; | |
| 3 | 3 | use human_bytes::human_bytes; |
| 4 | 4 | use release_channel::{AppCommitSha, AppVersion, ReleaseChannel}; |
| 5 | 5 | use serde::Serialize; |
| @@ -44,7 +44,7 @@ impl SystemSpecs { · 38 unmodified lines | ||
| 44 | 44 | None |
| 45 | 45 | }; |
| 46 | 46 | |
| 47 | − cx.background_executor().spawn(async move { | |
| 47 | + cx.background_spawn(async move { | |
| 48 | 48 | let os_version = telemetry::os_version(); |
| 49 | 49 | SystemSpecs { |
| 50 | 50 | app_version, |
| @@ -127,7 +127,7 @@ impl FileFinder { · 126 unmodified lines | ||
| 127 | 127 | let abs_path = abs_path?; |
| 128 | 128 | if project.is_local() { |
| 129 | 129 | let fs = fs.clone(); |
| 130 | − Some(cx.background_executor().spawn(async move { | |
| 130 | + Some(cx.background_spawn(async move { | |
| 131 | 131 | if fs.is_file(&abs_path).await { |
| 132 | 132 | Some(FoundPath::new(project_path, Some(abs_path))) |
| 133 | 133 | } else { |
| @@ -337,7 +337,7 @@ impl GitPanel { · 336 unmodified lines | ||
| 337 | 337 | |
| 338 | 338 | fn serialize(&mut self, cx: &mut Context<Self>) { |
| 339 | 339 | let width = self.width; |
| 340 | − self.pending_serialization = cx.background_executor().spawn( | |
| 340 | + self.pending_serialization = cx.background_spawn( | |
| 341 | 341 | async move { |
| 342 | 342 | KEY_VALUE_STORE |
| 343 | 343 | .write_kvp( |
| @@ -1055,8 +1055,7 @@ impl GitPanel { · 711 unmodified lines | ||
| 1055 | 1055 | let task = if self.has_staged_changes() { |
| 1056 | 1056 | // Repository serializes all git operations, so we can just send a commit immediately |
| 1057 | 1057 | let commit_task = active_repository.read(cx).commit(message.into(), None); |
| 1058 | − cx.background_executor() | |
| 1059 | − .spawn(async move { commit_task.await? }) | |
| 1058 | + cx.background_spawn(async move { commit_task.await? }) | |
| 1060 | 1059 | } else { |
| 1061 | 1060 | let changed_files = self |
| 1062 | 1061 | .entries |
| @@ -7,7 +7,7 @@ use editor::{scroll::Autoscroll, Editor, EditorEvent, ToPoint}; · 6 unmodified lines | ||
| 7 | 7 | use feature_flags::FeatureFlagViewExt; |
| 8 | 8 | use futures::StreamExt; |
| 9 | 9 | use gpui::{ |
| 10 | − actions, AnyElement, AnyView, App, AppContext, AsyncWindowContext, Entity, EventEmitter, | |
| 10 | + actions, AnyElement, AnyView, App, AppContext as _, AsyncWindowContext, Entity, EventEmitter, | |
| 11 | 11 | FocusHandle, Focusable, Render, Subscription, Task, WeakEntity, |
| 12 | 12 | }; |
| 13 | 13 | use language::{Anchor, Buffer, Capability, OffsetRangeExt, Point}; |
| @@ -177,8 +177,7 @@ impl PickerDelegate for RepositorySelectorDelegate { · 176 unmodified lines | ||
| 177 | 177 | |
| 178 | 178 | cx.spawn_in(window, |this, mut cx| async move { |
| 179 | 179 | let filtered_repositories = cx |
| 180 | − .background_executor() | |
| 181 | − .spawn(async move { | |
| 180 | + .background_spawn(async move { | |
| 182 | 181 | if query.is_empty() { |
| 183 | 182 | all_repositories |
| 184 | 183 | } else { |
| @@ -252,7 +252,7 @@ impl SerializableItem for ImageView { · 251 unmodified lines | ||
| 252 | 252 | let workspace_id = workspace.database_id()?; |
| 253 | 253 | let image_path = self.image_item.read(cx).file.as_local()?.abs_path(cx); |
| 254 | 254 | |
| 255 | − Some(cx.background_executor().spawn({ | |
| 255 | + Some(cx.background_spawn({ | |
| 256 | 256 | async move { |
| 257 | 257 | IMAGE_VIEWER |
| 258 | 258 | .save_image_path(item_id, workspace_id, image_path) |
| @@ -2,7 +2,7 @@ use anyhow::Result; · 1 unmodified line | ||
| 2 | 2 | use chrono::{Datelike, Local, NaiveTime, Timelike}; |
| 3 | 3 | use editor::scroll::Autoscroll; |
| 4 | 4 | use editor::Editor; |
| 5 | −use gpui::{actions, App, Context, Window}; | |
| 5 | +use gpui::{actions, App, AppContext as _, Context, Window}; | |
| 6 | 6 | use schemars::JsonSchema; |
| 7 | 7 | use serde::{Deserialize, Serialize}; |
| 8 | 8 | use settings::{Settings, SettingsSources}; |
| @@ -87,7 +87,7 @@ pub fn new_journal_entry(workspace: &Workspace, window: &mut Window, cx: &mut Ap · 78 unmodified lines | ||
| 87 | 87 | let now = now.time(); |
| 88 | 88 | let entry_heading = heading_entry(now, &settings.hour_format); |
| 89 | 89 | |
| 90 | − let create_entry = cx.background_executor().spawn(async move { | |
| 90 | + let create_entry = cx.background_spawn(async move { | |
| 91 | 91 | std::fs::create_dir_all(month_dir)?; |
| 92 | 92 | OpenOptions::new() |
| 93 | 93 | .create(true) |
| @@ -940,7 +940,7 @@ impl Buffer { · 939 unmodified lines | ||
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | let text_operations = self.text.operations().clone(); |
| 943 | − cx.background_executor().spawn(async move { | |
| 943 | + cx.background_spawn(async move { | |
| 944 | 944 | let since = since.unwrap_or_default(); |
| 945 | 945 | operations.extend( |
| 946 | 946 | text_operations |
| @@ -1135,7 +1135,7 @@ impl Buffer { · 188 unmodified lines | ||
| 1135 | 1135 | let old_snapshot = self.text.snapshot(); |
| 1136 | 1136 | let mut branch_buffer = self.text.branch(); |
| 1137 | 1137 | let mut syntax_snapshot = self.syntax_map.lock().snapshot(); |
| 1138 | − cx.background_executor().spawn(async move { | |
| 1138 | + cx.background_spawn(async move { | |
| 1139 | 1139 | if !edits.is_empty() { |
| 1140 | 1140 | if let Some(language) = language.clone() { |
| 1141 | 1141 | syntax_snapshot.reparse(&old_snapshot, registry.clone(), language); |
| @@ -1499,7 +1499,7 @@ impl Buffer { · 357 unmodified lines | ||
| 1499 | 1499 | let mut syntax_snapshot = syntax_map.snapshot(); |
| 1500 | 1500 | drop(syntax_map); |
| 1501 | 1501 | |
| 1502 | − let parse_task = cx.background_executor().spawn({ | |
| 1502 | + let parse_task = cx.background_spawn({ | |
| 1503 | 1503 | let language = language.clone(); |
| 1504 | 1504 | let language_registry = language_registry.clone(); |
| 1505 | 1505 | async move { |
| @@ -1578,7 +1578,7 @@ impl Buffer { · 72 unmodified lines | ||
| 1578 | 1578 | |
| 1579 | 1579 | fn request_autoindent(&mut self, cx: &mut Context<Self>) { |
| 1580 | 1580 | if let Some(indent_sizes) = self.compute_autoindents() { |
| 1581 | − let indent_sizes = cx.background_executor().spawn(indent_sizes); | |
| 1581 | + let indent_sizes = cx.background_spawn(indent_sizes); | |
| 1582 | 1582 | match cx |
| 1583 | 1583 | .background_executor() |
| 1584 | 1584 | .block_with_timeout(Duration::from_micros(500), indent_sizes) |
| @@ -1907,7 +1907,7 @@ impl Buffer { · 322 unmodified lines | ||
| 1907 | 1907 | let old_text = self.as_rope().clone(); |
| 1908 | 1908 | let line_ending = self.line_ending(); |
| 1909 | 1909 | let base_version = self.version(); |
| 1910 | − cx.background_executor().spawn(async move { | |
| 1910 | + cx.background_spawn(async move { | |
| 1911 | 1911 | let ranges = trailing_whitespace_ranges(&old_text); |
| 1912 | 1912 | let empty = Arc::<str>::from(""); |
| 1913 | 1913 | Diff { |
| @@ -940,6 +940,8 @@ impl LanguageRegistry { · 939 unmodified lines | ||
| 940 | 940 | binary: lsp::LanguageServerBinary, |
| 941 | 941 | cx: gpui::AsyncApp, |
| 942 | 942 | ) -> Option<lsp::LanguageServer> { |
| 943 | + use gpui::AppContext as _; | |
| 944 | + | |
| 943 | 945 | let mut state = self.state.write(); |
| 944 | 946 | let fake_entry = state.fake_server_entries.get_mut(&name)?; |
| 945 | 947 | let (server, mut fake_server) = lsp::FakeLanguageServer::new( |
| @@ -956,17 +958,16 @@ impl LanguageRegistry { · 10 unmodified lines | ||
| 956 | 958 | } |
| 957 | 959 | |
| 958 | 960 | let tx = fake_entry.tx.clone(); |
| 959 | − cx.background_executor() | |
| 960 | − .spawn(async move { | |
| 961 | − if fake_server | |
| 962 | − .try_receive_notification::<lsp::notification::Initialized>() | |
| 963 | − .await | |
| 964 | − .is_some() | |
| 965 | − { | |
| 966 | − tx.unbounded_send(fake_server.clone()).ok(); | |
| 967 | − } | |
| 968 | − }) | |
| 969 | − .detach(); | |
| 961 | + cx.background_spawn(async move { | |
| 962 | + if fake_server | |
| 963 | + .try_receive_notification::<lsp::notification::Initialized>() | |
| 964 | + .await | |
| 965 | + .is_some() | |
| 966 | + { | |
| 967 | + tx.unbounded_send(fake_server.clone()).ok(); | |
| 968 | + } | |
| 969 | + }) | |
| 970 | + .detach(); | |
| 970 | 971 | |
| 971 | 972 | Some(server) |
| 972 | 973 | } |
| @@ -3,7 +3,9 @@ use std::io::{Cursor, Write}; · 2 unmodified lines | ||
| 3 | 3 | use crate::role::Role; |
| 4 | 4 | use crate::LanguageModelToolUse; |
| 5 | 5 | use base64::write::EncoderWriter; |
| 6 | −use gpui::{point, size, App, DevicePixels, Image, ObjectFit, RenderImage, Size, Task}; | |
| 6 | +use gpui::{ | |
| 7 | + point, size, App, AppContext as _, DevicePixels, Image, ObjectFit, RenderImage, Size, Task, | |
| 8 | +}; | |
| 7 | 9 | use image::{codecs::png::PngEncoder, imageops::resize, DynamicImage, ImageDecoder}; |
| 8 | 10 | use serde::{Deserialize, Serialize}; |
| 9 | 11 | use ui::{px, SharedString}; |
| @@ -30,7 +32,7 @@ const ANTHROPIC_SIZE_LIMT: f32 = 1568.; · 20 unmodified lines | ||
| 30 | 32 | |
| 31 | 33 | impl LanguageModelImage { |
| 32 | 34 | pub fn from_image(data: Image, cx: &mut App) -> Task<Option<Self>> { |
| 33 | − cx.background_executor().spawn(async move { | |
| 35 | + cx.background_spawn(async move { | |
| 34 | 36 | match data.format() { |
| 35 | 37 | gpui::ImageFormat::Png |
| 36 | 38 | | gpui::ImageFormat::Jpeg |
| @@ -228,8 +228,7 @@ impl PickerDelegate for LanguageModelPickerDelegate { · 227 unmodified lines | ||
| 228 | 228 | |
| 229 | 229 | cx.spawn_in(window, |this, mut cx| async move { |
| 230 | 230 | let filtered_models = cx |
| 231 | − .background_executor() | |
| 232 | − .spawn(async move { | |
| 231 | + .background_spawn(async move { | |
| 233 | 232 | let displayed_models = if configured_providers.is_empty() { |
| 234 | 233 | all_models |
| 235 | 234 | } else { |
| @@ -252,54 +252,53 @@ pub fn count_anthropic_tokens( · 251 unmodified lines | ||
| 252 | 252 | request: LanguageModelRequest, |
| 253 | 253 | cx: &App, |
| 254 | 254 | ) -> BoxFuture<'static, Result<usize>> { |
| 255 | − cx.background_executor() | |
| 256 | − .spawn(async move { | |
| 257 | − let messages = request.messages; | |
| 258 | − let mut tokens_from_images = 0; | |
| 259 | − let mut string_messages = Vec::with_capacity(messages.len()); | |
| 255 | + cx.background_spawn(async move { | |
| 256 | + let messages = request.messages; | |
| 257 | + let mut tokens_from_images = 0; | |
| 258 | + let mut string_messages = Vec::with_capacity(messages.len()); | |
| 260 | 259 | |
| 261 | − for message in messages { | |
| 262 | − use language_model::MessageContent; | |
| 260 | + for message in messages { | |
| 261 | + use language_model::MessageContent; | |
| 263 | 262 | |
| 264 | − let mut string_contents = String::new(); | |
| 263 | + let mut string_contents = String::new(); | |
| 265 | 264 | |
| 266 | − for content in message.content { | |
| 267 | − match content { | |
| 268 | − MessageContent::Text(text) => { | |
| 269 | − string_contents.push_str(&text); | |
| 270 | − } | |
| 271 | − MessageContent::Image(image) => { | |
| 272 | − tokens_from_images += image.estimate_tokens(); | |
| 273 | − } | |
| 274 | − MessageContent::ToolUse(_tool_use) => { | |
| 275 | − // TODO: Estimate token usage from tool uses. | |
| 276 | − } | |
| 277 | − MessageContent::ToolResult(tool_result) => { | |
| 278 | − string_contents.push_str(&tool_result.content); | |
| 279 | − } | |
| 265 | + for content in message.content { | |
| 266 | + match content { | |
| 267 | + MessageContent::Text(text) => { | |
| 268 | + string_contents.push_str(&text); | |
| 269 | + } | |
| 270 | + MessageContent::Image(image) => { | |
| 271 | + tokens_from_images += image.estimate_tokens(); | |
| 272 | + } | |
| 273 | + MessageContent::ToolUse(_tool_use) => { | |
| 274 | + // TODO: Estimate token usage from tool uses. | |
| 275 | + } | |
| 276 | + MessageContent::ToolResult(tool_result) => { | |
| 277 | + string_contents.push_str(&tool_result.content); | |
| 280 | 278 | } |
| 281 | 279 | } |
| 280 | + } | |
| 282 | 281 | |
| 283 | − if !string_contents.is_empty() { | |
| 284 | − string_messages.push(tiktoken_rs::ChatCompletionRequestMessage { | |
| 285 | − role: match message.role { | |
| 286 | − Role::User => "user".into(), | |
| 287 | − Role::Assistant => "assistant".into(), | |
| 288 | − Role::System => "system".into(), | |
| 289 | − }, | |
| 290 | − content: Some(string_contents), | |
| 291 | − name: None, | |
| 292 | − function_call: None, | |
| 293 | − }); | |
| 294 | − } | |
| 282 | + if !string_contents.is_empty() { | |
| 283 | + string_messages.push(tiktoken_rs::ChatCompletionRequestMessage { | |
| 284 | + role: match message.role { | |
| 285 | + Role::User => "user".into(), | |
| 286 | + Role::Assistant => "assistant".into(), | |
| 287 | + Role::System => "system".into(), | |
| 288 | + }, | |
| 289 | + content: Some(string_contents), | |
| 290 | + name: None, | |
| 291 | + function_call: None, | |
| 292 | + }); | |
| 295 | 293 | } |
| 294 | + } | |
| 296 | 295 | |
| 297 | − // Tiktoken doesn't yet support these models, so we manually use the | |
| 298 | − // same tokenizer as GPT-4. | |
| 299 | − tiktoken_rs::num_tokens_from_messages("gpt-4", &string_messages) | |
| 300 | − .map(|tokens| tokens + tokens_from_images) | |
| 301 | − }) | |
| 302 | − .boxed() | |
| 296 | + // Tiktoken doesn't yet support these models, so we manually use the | |
| 297 | + // same tokenizer as GPT-4. | |
| 298 | + tiktoken_rs::num_tokens_from_messages("gpt-4", &string_messages) | |
| 299 | + .map(|tokens| tokens + tokens_from_images) | |
| 300 | + }) | |
| 301 | + .boxed() | |
| 303 | 302 | } |
| 304 | 303 | |
| 305 | 304 | impl AnthropicModel { |
| @@ -3,7 +3,8 @@ use collections::BTreeMap; · 2 unmodified lines | ||
| 3 | 3 | use editor::{Editor, EditorElement, EditorStyle}; |
| 4 | 4 | use futures::{future::BoxFuture, stream::BoxStream, FutureExt, StreamExt}; |
| 5 | 5 | use gpui::{ |
| 6 | − AnyView, AppContext, AsyncApp, Entity, FontStyle, Subscription, Task, TextStyle, WhiteSpace, | |
| 6 | + AnyView, AppContext as _, AsyncApp, Entity, FontStyle, Subscription, Task, TextStyle, | |
| 7 | + WhiteSpace, | |
| 7 | 8 | }; |
| 8 | 9 | use http_client::HttpClient; |
| 9 | 10 | use language_model::{ |
| @@ -269,26 +270,25 @@ impl LanguageModel for DeepSeekLanguageModel { · 259 unmodified lines | ||
| 269 | 270 | request: LanguageModelRequest, |
| 270 | 271 | cx: &App, |
| 271 | 272 | ) -> BoxFuture<'static, Result<usize>> { |
| 272 | − cx.background_executor() | |
| 273 | − .spawn(async move { | |
| 274 | − let messages = request | |
| 275 | − .messages | |
| 276 | − .into_iter() | |
| 277 | − .map(|message| tiktoken_rs::ChatCompletionRequestMessage { | |
| 278 | − role: match message.role { | |
| 279 | − Role::User => "user".into(), | |
| 280 | − Role::Assistant => "assistant".into(), | |
| 281 | − Role::System => "system".into(), | |
| 282 | − }, | |
| 283 | − content: Some(message.string_contents()), | |
| 284 | − name: None, | |
| 285 | − function_call: None, | |
| 286 | − }) | |
| 287 | − .collect::<Vec<_>>(); | |
| 273 | + cx.background_spawn(async move { | |
| 274 | + let messages = request | |
| 275 | + .messages | |
| 276 | + .into_iter() | |
| 277 | + .map(|message| tiktoken_rs::ChatCompletionRequestMessage { | |
| 278 | + role: match message.role { | |
| 279 | + Role::User => "user".into(), | |
| 280 | + Role::Assistant => "assistant".into(), | |
| 281 | + Role::System => "system".into(), | |
| 282 | + }, | |
| 283 | + content: Some(message.string_contents()), | |
| 284 | + name: None, | |
| 285 | + function_call: None, | |
| 286 | + }) | |
| 287 | + .collect::<Vec<_>>(); | |
| 288 | 288 | |
| 289 | − tiktoken_rs::num_tokens_from_messages("gpt-4", &messages) | |
| 290 | − }) | |
| 291 | − .boxed() | |
| 289 | + tiktoken_rs::num_tokens_from_messages("gpt-4", &messages) | |
| 290 | + }) | |
| 291 | + .boxed() | |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | fn stream_completion( |
| @@ -330,28 +330,27 @@ pub fn count_google_tokens( · 329 unmodified lines | ||
| 330 | 330 | ) -> BoxFuture<'static, Result<usize>> { |
| 331 | 331 | // We couldn't use the GoogleLanguageModelProvider to count tokens because the github copilot doesn't have the access to google_ai directly. |
| 332 | 332 | // So we have to use tokenizer from tiktoken_rs to count tokens. |
| 333 | − cx.background_executor() | |
| 334 | − .spawn(async move { | |
| 335 | − let messages = request | |
| 336 | − .messages | |
| 337 | − .into_iter() | |
| 338 | − .map(|message| tiktoken_rs::ChatCompletionRequestMessage { | |
| 339 | − role: match message.role { | |
| 340 | − Role::User => "user".into(), | |
| 341 | − Role::Assistant => "assistant".into(), | |
| 342 | − Role::System => "system".into(), | |
| 343 | − }, | |
| 344 | − content: Some(message.string_contents()), | |
| 345 | − name: None, | |
| 346 | − function_call: None, | |
| 347 | − }) | |
| 348 | − .collect::<Vec<_>>(); | |
| 333 | + cx.background_spawn(async move { | |
| 334 | + let messages = request | |
| 335 | + .messages | |
| 336 | + .into_iter() | |
| 337 | + .map(|message| tiktoken_rs::ChatCompletionRequestMessage { | |
| 338 | + role: match message.role { | |
| 339 | + Role::User => "user".into(), | |
| 340 | + Role::Assistant => "assistant".into(), | |
| 341 | + Role::System => "system".into(), | |
| 342 | + }, | |
| 343 | + content: Some(message.string_contents()), | |
| 344 | + name: None, | |
| 345 | + function_call: None, | |
| 346 | + }) | |
| 347 | + .collect::<Vec<_>>(); | |
| 349 | 348 | |
| 350 | − // Tiktoken doesn't yet support these models, so we manually use the | |
| 351 | − // same tokenizer as GPT-4. | |
| 352 | − tiktoken_rs::num_tokens_from_messages("gpt-4", &messages) | |
| 353 | − }) | |
| 354 | − .boxed() | |
| 349 | + // Tiktoken doesn't yet support these models, so we manually use the | |
| 350 | + // same tokenizer as GPT-4. | |
| 351 | + tiktoken_rs::num_tokens_from_messages("gpt-4", &messages) | |
| 352 | + }) | |
| 353 | + .boxed() | |
| 355 | 354 | } |
| 356 | 355 | |
| 357 | 356 | struct ConfigurationView { |
| @@ -281,26 +281,25 @@ impl LanguageModel for MistralLanguageModel { · 280 unmodified lines | ||
| 281 | 281 | request: LanguageModelRequest, |
| 282 | 282 | cx: &App, |
| 283 | 283 | ) -> BoxFuture<'static, Result<usize>> { |
| 284 | − cx.background_executor() | |
| 285 | − .spawn(async move { | |
| 286 | − let messages = request | |
| 287 | − .messages | |
| 288 | − .into_iter() | |
| 289 | − .map(|message| tiktoken_rs::ChatCompletionRequestMessage { | |
| 290 | − role: match message.role { | |
| 291 | − Role::User => "user".into(), | |
| 292 | − Role::Assistant => "assistant".into(), | |
| 293 | − Role::System => "system".into(), | |
| 294 | − }, | |
| 295 | − content: Some(message.string_contents()), | |
| 296 | − name: None, | |
| 297 | − function_call: None, | |
| 298 | − }) | |
| 299 | − .collect::<Vec<_>>(); | |
| 284 | + cx.background_spawn(async move { | |
| 285 | + let messages = request | |
| 286 | + .messages | |
| 287 | + .into_iter() | |
| 288 | + .map(|message| tiktoken_rs::ChatCompletionRequestMessage { | |
| 289 | + role: match message.role { | |
| 290 | + Role::User => "user".into(), | |
| 291 | + Role::Assistant => "assistant".into(), | |
| 292 | + Role::System => "system".into(), | |
| 293 | + }, | |
| 294 | + content: Some(message.string_contents()), | |
| 295 | + name: None, | |
| 296 | + function_call: None, | |
| 297 | + }) | |
| 298 | + .collect::<Vec<_>>(); | |
| 300 | 299 | |
| 301 | − tiktoken_rs::num_tokens_from_messages("gpt-4", &messages) | |
| 302 | − }) | |
| 303 | − .boxed() | |
| 300 | + tiktoken_rs::num_tokens_from_messages("gpt-4", &messages) | |
| 301 | + }) | |
| 302 | + .boxed() | |
| 304 | 303 | } |
| 305 | 304 | |
| 306 | 305 | fn stream_completion( |
| @@ -343,34 +343,31 @@ pub fn count_open_ai_tokens( · 342 unmodified lines | ||
| 343 | 343 | model: open_ai::Model, |
| 344 | 344 | cx: &App, |
| 345 | 345 | ) -> BoxFuture<'static, Result<usize>> { |
| 346 | − cx.background_executor() | |
| 347 | − .spawn(async move { | |
| 348 | − let messages = request | |
| 349 | − .messages | |
| 350 | − .into_iter() | |
| 351 | − .map(|message| tiktoken_rs::ChatCompletionRequestMessage { | |
| 352 | − role: match message.role { | |
| 353 | − Role::User => "user".into(), | |
| 354 | − Role::Assistant => "assistant".into(), | |
| 355 | − Role::System => "system".into(), | |
| 356 | − }, | |
| 357 | − content: Some(message.string_contents()), | |
| 358 | − name: None, | |
| 359 | − function_call: None, | |
| 360 | − }) | |
| 361 | − .collect::<Vec<_>>(); | |
| 362 | − | |
| 363 | − match model { | |
| 364 | − open_ai::Model::Custom { .. } | |
| 365 | − | open_ai::Model::O1Mini | |
| 366 | − | open_ai::Model::O1 | |
| 367 | − | open_ai::Model::O3Mini => { | |
| 368 | − tiktoken_rs::num_tokens_from_messages("gpt-4", &messages) | |
| 369 | − } | |
| 370 | − _ => tiktoken_rs::num_tokens_from_messages(model.id(), &messages), | |
| 371 | − } | |
| 372 | − }) | |
| 373 | − .boxed() | |
| 346 | + cx.background_spawn(async move { | |
| 347 | + let messages = request | |
| 348 | + .messages | |
| 349 | + .into_iter() | |
| 350 | + .map(|message| tiktoken_rs::ChatCompletionRequestMessage { | |
| 351 | + role: match message.role { | |
| 352 | + Role::User => "user".into(), | |
| 353 | + Role::Assistant => "assistant".into(), | |
| 354 | + Role::System => "system".into(), | |
| 355 | + }, | |
| 356 | + content: Some(message.string_contents()), | |
| 357 | + name: None, | |
| 358 | + function_call: None, | |
| 359 | + }) | |
| 360 | + .collect::<Vec<_>>(); | |
| 361 | + | |
| 362 | + match model { | |
| 363 | + open_ai::Model::Custom { .. } | |
| 364 | + | open_ai::Model::O1Mini | |
| 365 | + | open_ai::Model::O1 | |
| 366 | + | open_ai::Model::O3Mini => tiktoken_rs::num_tokens_from_messages("gpt-4", &messages), | |
| 367 | + _ => tiktoken_rs::num_tokens_from_messages(model.id(), &messages), | |
| 368 | + } | |
| 369 | + }) | |
| 370 | + .boxed() | |
| 374 | 371 | } |
| 375 | 372 | |
| 376 | 373 | struct ConfigurationView { |
| @@ -302,11 +302,10 @@ impl LivekitWindow { · 301 unmodified lines | ||
| 302 | 302 | if let Some(track) = self.screen_share_track.take() { |
| 303 | 303 | self.screen_share_stream.take(); |
| 304 | 304 | let participant = self.room.local_participant(); |
| 305 | − cx.background_executor() | |
| 306 | − .spawn(async move { | |
| 307 | − participant.unpublish_track(&track.sid()).await.unwrap(); | |
| 308 | − }) | |
| 309 | − .detach(); | |
| 305 | + cx.background_spawn(async move { | |
| 306 | + participant.unpublish_track(&track.sid()).await.unwrap(); | |
| 307 | + }) | |
| 308 | + .detach(); | |
| 310 | 309 | cx.notify(); |
| 311 | 310 | } else { |
| 312 | 311 | let participant = self.room.local_participant(); |
| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | use crate::track::RemoteVideoTrack; |
| 2 | 2 | use anyhow::Result; |
| 3 | 3 | use futures::StreamExt as _; |
| 4 | −use gpui::{AppContext, Context, Empty, Entity, EventEmitter, IntoElement, Render, Task, Window}; | |
| 4 | +use gpui::{ | |
| 5 | + AppContext as _, Context, Empty, Entity, EventEmitter, IntoElement, Render, Task, Window, | |
| 6 | +}; | |
| 5 | 7 | |
| 6 | 8 | pub struct RemoteVideoTrackView { |
| 7 | 9 | track: RemoteVideoTrack, |
| @@ -6,7 +6,7 @@ pub use lsp_types::*; · 5 unmodified lines | ||
| 6 | 6 | use anyhow::{anyhow, Context as _, Result}; |
| 7 | 7 | use collections::HashMap; |
| 8 | 8 | use futures::{channel::oneshot, io::BufWriter, select, AsyncRead, AsyncWrite, Future, FutureExt}; |
| 9 | −use gpui::{App, AsyncApp, BackgroundExecutor, SharedString, Task}; | |
| 9 | +use gpui::{App, AppContext as _, AsyncApp, BackgroundExecutor, SharedString, Task}; | |
| 10 | 10 | use notification::DidChangeWorkspaceFolders; |
| 11 | 11 | use parking_lot::{Mutex, RwLock}; |
| 12 | 12 | use postage::{barrier, prelude::Stream}; |
| @@ -448,7 +448,7 @@ impl LanguageServer { · 435 unmodified lines | ||
| 448 | 448 | let (stdout, stderr) = futures::join!(stdout_input_task, stderr_input_task); |
| 449 | 449 | stdout.or(stderr) |
| 450 | 450 | }); |
| 451 | − let output_task = cx.background_executor().spawn({ | |
| 451 | + let output_task = cx.background_spawn({ | |
| 452 | 452 | Self::handle_output( |
| 453 | 453 | stdin, |
| 454 | 454 | outbound_rx, |
| @@ -178,7 +178,7 @@ impl Markdown { · 177 unmodified lines | ||
| 178 | 178 | |
| 179 | 179 | let text = self.source.clone(); |
| 180 | 180 | let parse_text_only = self.options.parse_links_only; |
| 181 | − let parsed = cx.background_executor().spawn(async move { | |
| 181 | + let parsed = cx.background_spawn(async move { | |
| 182 | 182 | let text = SharedString::from(text); |
| 183 | 183 | let events = match parse_text_only { |
| 184 | 184 | true => Arc::from(parse_links_only(text.as_ref())), |
| @@ -383,7 +383,7 @@ impl MarkdownPreviewView { · 382 unmodified lines | ||
| 383 | 383 | (contents, file_location) |
| 384 | 384 | })?; |
| 385 | 385 | |
| 386 | − let parsing_task = cx.background_executor().spawn(async move { | |
| 386 | + let parsing_task = cx.background_spawn(async move { | |
| 387 | 387 | parse_markdown(&contents, file_location, Some(language_registry)).await |
| 388 | 388 | }); |
| 389 | 389 | let contents = parsing_task.await; |
| @@ -13,7 +13,7 @@ use buffer_diff::{ · 12 unmodified lines | ||
| 13 | 13 | use clock::ReplicaId; |
| 14 | 14 | use collections::{BTreeMap, Bound, HashMap, HashSet}; |
| 15 | 15 | use futures::{channel::mpsc, SinkExt}; |
| 16 | −use gpui::{App, Context, Entity, EntityId, EventEmitter, Task}; | |
| 16 | +use gpui::{App, AppContext as _, Context, Entity, EntityId, EventEmitter, Task}; | |
| 17 | 17 | use itertools::Itertools; |
| 18 | 18 | use language::{ |
| 19 | 19 | language_settings::{language_settings, IndentGuideSettings, LanguageSettings}, |
| @@ -51,9 +51,6 @@ use text::{ · 31 unmodified lines | ||
| 51 | 51 | use theme::SyntaxTheme; |
| 52 | 52 | use util::post_inc; |
| 53 | 53 | |
| 54 | −#[cfg(any(test, feature = "test-support"))] | |
| 55 | −use gpui::AppContext as _; | |
| 56 | − | |
| 57 | 54 | const NEWLINES: &[u8] = &[b'\n'; u8::MAX as usize]; |
| 58 | 55 | |
| 59 | 56 | #[derive(Debug, Default, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| @@ -1580,20 +1577,19 @@ impl MultiBuffer { · 1520 unmodified lines | ||
| 1580 | 1577 | |
| 1581 | 1578 | buffer_ids.push(buffer_id); |
| 1582 | 1579 | |
| 1583 | − cx.background_executor() | |
| 1584 | − .spawn({ | |
| 1585 | − let mut excerpt_ranges_tx = excerpt_ranges_tx.clone(); | |
| 1586 | − | |
| 1587 | − async move { | |
| 1588 | − let (excerpt_ranges, counts) = | |
| 1589 | − build_excerpt_ranges(&buffer_snapshot, &ranges, context_line_count); | |
| 1590 | − excerpt_ranges_tx | |
| 1591 | − .send((buffer_id, buffer.clone(), ranges, excerpt_ranges, counts)) | |
| 1592 | − .await | |
| 1593 | − .ok(); | |
| 1594 | − } | |
| 1595 | − }) | |
| 1596 | − .detach() | |
| 1580 | + cx.background_spawn({ | |
| 1581 | + let mut excerpt_ranges_tx = excerpt_ranges_tx.clone(); | |
| 1582 | + | |
| 1583 | + async move { | |
| 1584 | + let (excerpt_ranges, counts) = | |
| 1585 | + build_excerpt_ranges(&buffer_snapshot, &ranges, context_line_count); | |
| 1586 | + excerpt_ranges_tx | |
| 1587 | + .send((buffer_id, buffer.clone(), ranges, excerpt_ranges, counts)) | |
| 1588 | + .await | |
| 1589 | + .ok(); | |
| 1590 | + } | |
| 1591 | + }) | |
| 1592 | + .detach() | |
| 1597 | 1593 | } |
| 1598 | 1594 | |
| 1599 | 1595 | cx.spawn(move |this, mut cx| async move { |
| @@ -171,7 +171,7 @@ impl SearchState { · 170 unmodified lines | ||
| 171 | 171 | }) |
| 172 | 172 | .collect(), |
| 173 | 173 | highlight_search_match_tx, |
| 174 | − _search_match_highlighter: cx.background_executor().spawn(async move { | |
| 174 | + _search_match_highlighter: cx.background_spawn(async move { | |
| 175 | 175 | while let Ok(highlight_arguments) = highlight_search_match_rx.recv().await { |
| 176 | 176 | let needs_init = highlight_arguments.search_data.get().is_none(); |
| 177 | 177 | let search_data = highlight_arguments.search_data.get_or_init(|| { |
| @@ -681,8 +681,7 @@ impl OutlinePanel { · 503 unmodified lines | ||
| 681 | 681 | mut cx: AsyncWindowContext, |
| 682 | 682 | ) -> anyhow::Result<Entity<Self>> { |
| 683 | 683 | let serialized_panel = cx |
| 684 | − .background_executor() | |
| 685 | − .spawn(async move { KEY_VALUE_STORE.read_kvp(OUTLINE_PANEL_KEY) }) | |
| 684 | + .background_spawn(async move { KEY_VALUE_STORE.read_kvp(OUTLINE_PANEL_KEY) }) | |
| 686 | 685 | .await |
| 687 | 686 | .context("loading outline panel") |
| 688 | 687 | .log_err() |
| @@ -849,7 +848,7 @@ impl OutlinePanel { · 160 unmodified lines | ||
| 849 | 848 | fn serialize(&mut self, cx: &mut Context<Self>) { |
| 850 | 849 | let width = self.width; |
| 851 | 850 | let active = Some(self.active); |
| 852 | − self.pending_serialization = cx.background_executor().spawn( | |
| 851 | + self.pending_serialization = cx.background_spawn( | |
| 853 | 852 | async move { |
| 854 | 853 | KEY_VALUE_STORE |
| 855 | 854 | .write_kvp( |
| @@ -2631,8 +2630,7 @@ impl OutlinePanel { · 1775 unmodified lines | ||
| 2631 | 2630 | new_depth_map, |
| 2632 | 2631 | new_children_count, |
| 2633 | 2632 | )) = cx |
| 2634 | − .background_executor() | |
| 2635 | − .spawn(async move { | |
| 2633 | + .background_spawn(async move { | |
| 2636 | 2634 | let mut processed_external_buffers = HashSet::default(); |
| 2637 | 2635 | let mut new_worktree_entries = |
| 2638 | 2636 | BTreeMap::<WorktreeId, HashMap<ProjectEntryId, GitEntry>>::default(); |
| @@ -3224,8 +3222,7 @@ impl OutlinePanel { · 585 unmodified lines | ||
| 3224 | 3222 | (buffer_id, excerpt_id), |
| 3225 | 3223 | cx.spawn_in(window, |outline_panel, mut cx| async move { |
| 3226 | 3224 | let fetched_outlines = cx |
| 3227 | − .background_executor() | |
| 3228 | − .spawn(async move { | |
| 3225 | + .background_spawn(async move { | |
| 3229 | 3226 | buffer_snapshot |
| 3230 | 3227 | .outline_items_containing( |
| 3231 | 3228 | excerpt_range.context, |
| @@ -346,7 +346,7 @@ impl RemoteBufferStore { · 345 unmodified lines | ||
| 346 | 346 | fn open_unstaged_diff(&self, buffer_id: BufferId, cx: &App) -> Task<Result<Option<String>>> { |
| 347 | 347 | let project_id = self.project_id; |
| 348 | 348 | let client = self.upstream_client.clone(); |
| 349 | − cx.background_executor().spawn(async move { | |
| 349 | + cx.background_spawn(async move { | |
| 350 | 350 | let response = client |
| 351 | 351 | .request(proto::OpenUnstagedDiff { |
| 352 | 352 | project_id, |
| @@ -366,7 +366,7 @@ impl RemoteBufferStore { · 13 unmodified lines | ||
| 366 | 366 | |
| 367 | 367 | let project_id = self.project_id; |
| 368 | 368 | let client = self.upstream_client.clone(); |
| 369 | − cx.background_executor().spawn(async move { | |
| 369 | + cx.background_spawn(async move { | |
| 370 | 370 | let response = client |
| 371 | 371 | .request(proto::OpenUncommittedDiff { |
| 372 | 372 | project_id, |
| @@ -402,9 +402,7 @@ impl RemoteBufferStore { · 29 unmodified lines | ||
| 402 | 402 | return Ok(buffer); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | − cx.background_executor() | |
| 406 | − .spawn(async move { rx.await? }) | |
| 407 | − .await | |
| 405 | + cx.background_spawn(async move { rx.await? }).await | |
| 408 | 406 | }) |
| 409 | 407 | } |
| 410 | 408 | |
| @@ -843,8 +841,7 @@ impl LocalBufferStore { · 432 unmodified lines | ||
| 843 | 841 | let snapshot = |
| 844 | 842 | worktree_handle.update(&mut cx, |tree, _| tree.as_local().unwrap().snapshot())?; |
| 845 | 843 | let diff_bases_changes_by_buffer = cx |
| 846 | − .background_executor() | |
| 847 | − .spawn(async move { | |
| 844 | + .background_spawn(async move { | |
| 848 | 845 | diff_state_updates |
| 849 | 846 | .into_iter() |
| 850 | 847 | .filter_map( |
| @@ -1129,8 +1126,7 @@ impl LocalBufferStore { · 278 unmodified lines | ||
| 1129 | 1126 | cx.spawn(move |_, mut cx| async move { |
| 1130 | 1127 | let loaded = load_file.await?; |
| 1131 | 1128 | let text_buffer = cx |
| 1132 | − .background_executor() | |
| 1133 | − .spawn(async move { text::Buffer::new(0, buffer_id, loaded.text) }) | |
| 1129 | + .background_spawn(async move { text::Buffer::new(0, buffer_id, loaded.text) }) | |
| 1134 | 1130 | .await; |
| 1135 | 1131 | cx.insert_entity(reservation, |_| { |
| 1136 | 1132 | Buffer::build(text_buffer, Some(loaded.file), Capability::ReadWrite) |
| @@ -1347,8 +1343,7 @@ impl BufferStore { · 210 unmodified lines | ||
| 1347 | 1343 | } |
| 1348 | 1344 | }; |
| 1349 | 1345 | |
| 1350 | − cx.background_executor() | |
| 1351 | − .spawn(async move { task.await.map_err(|e| anyhow!("{e}")) }) | |
| 1346 | + cx.background_spawn(async move { task.await.map_err(|e| anyhow!("{e}")) }) | |
| 1352 | 1347 | } |
| 1353 | 1348 | |
| 1354 | 1349 | pub fn open_unstaged_diff( |
| @@ -1388,8 +1383,7 @@ impl BufferStore { · 33 unmodified lines | ||
| 1388 | 1383 | } |
| 1389 | 1384 | }; |
| 1390 | 1385 | |
| 1391 | − cx.background_executor() | |
| 1392 | − .spawn(async move { task.await.map_err(|e| anyhow!("{e}")) }) | |
| 1386 | + cx.background_spawn(async move { task.await.map_err(|e| anyhow!("{e}")) }) | |
| 1393 | 1387 | } |
| 1394 | 1388 | |
| 1395 | 1389 | pub fn open_uncommitted_diff( |
| @@ -1409,7 +1403,7 @@ impl BufferStore { · 13 unmodified lines | ||
| 1409 | 1403 | BufferStoreState::Local(this) => { |
| 1410 | 1404 | let committed_text = this.load_committed_text(&buffer, cx); |
| 1411 | 1405 | let staged_text = this.load_staged_text(&buffer, cx); |
| 1412 | − cx.background_executor().spawn(async move { | |
| 1406 | + cx.background_spawn(async move { | |
| 1413 | 1407 | let committed_text = committed_text.await?; |
| 1414 | 1408 | let staged_text = staged_text.await?; |
| 1415 | 1409 | let diff_bases_change = if committed_text == staged_text { |
| @@ -1445,8 +1439,7 @@ impl BufferStore { · 29 unmodified lines | ||
| 1445 | 1439 | } |
| 1446 | 1440 | }; |
| 1447 | 1441 | |
| 1448 | − cx.background_executor() | |
| 1449 | − .spawn(async move { task.await.map_err(|e| anyhow!("{e}")) }) | |
| 1442 | + cx.background_spawn(async move { task.await.map_err(|e| anyhow!("{e}")) }) | |
| 1450 | 1443 | } |
| 1451 | 1444 | |
| 1452 | 1445 | async fn open_diff_internal( |
| @@ -1587,7 +1580,7 @@ impl BufferStore { · 134 unmodified lines | ||
| 1587 | 1580 | anyhow::Ok(Some((repo, relative_path, content))) |
| 1588 | 1581 | }); |
| 1589 | 1582 | |
| 1590 | − cx.background_executor().spawn(async move { | |
| 1583 | + cx.background_spawn(async move { | |
| 1591 | 1584 | let Some((repo, relative_path, content)) = blame_params? else { |
| 1592 | 1585 | return Ok(None); |
| 1593 | 1586 | }; |
| @@ -2106,24 +2099,23 @@ impl BufferStore { · 512 unmodified lines | ||
| 2106 | 2099 | }) |
| 2107 | 2100 | .log_err(); |
| 2108 | 2101 | |
| 2109 | − cx.background_executor() | |
| 2110 | − .spawn( | |
| 2111 | − async move { | |
| 2112 | − let operations = operations.await; | |
| 2113 | − for chunk in split_operations(operations) { | |
| 2114 | − client | |
| 2115 | − .request(proto::UpdateBuffer { | |
| 2116 | − project_id, | |
| 2117 | − buffer_id: buffer_id.into(), | |
| 2118 | − operations: chunk, | |
| 2119 | − }) | |
| 2120 | − .await?; | |
| 2121 | − } | |
| 2122 | − anyhow::Ok(()) | |
| 2102 | + cx.background_spawn( | |
| 2103 | + async move { | |
| 2104 | + let operations = operations.await; | |
| 2105 | + for chunk in split_operations(operations) { | |
| 2106 | + client | |
| 2107 | + .request(proto::UpdateBuffer { | |
| 2108 | + project_id, | |
| 2109 | + buffer_id: buffer_id.into(), | |
| 2110 | + operations: chunk, | |
| 2111 | + }) | |
| 2112 | + .await?; | |
| 2123 | 2113 | } |
| 2124 | − .log_err(), | |
| 2125 | − ) | |
| 2126 | − .detach(); | |
| 2114 | + anyhow::Ok(()) | |
| 2115 | + } | |
| 2116 | + .log_err(), | |
| 2117 | + ) | |
| 2118 | + .detach(); | |
| 2127 | 2119 | } |
| 2128 | 2120 | } |
| 2129 | 2121 | Ok(response) |
| @@ -2558,27 +2550,26 @@ impl BufferStore { · 428 unmodified lines | ||
| 2558 | 2550 | |
| 2559 | 2551 | if client.send(initial_state).log_err().is_some() { |
| 2560 | 2552 | let client = client.clone(); |
| 2561 | − cx.background_executor() | |
| 2562 | − .spawn(async move { | |
| 2563 | − let mut chunks = split_operations(operations).peekable(); | |
| 2564 | − while let Some(chunk) = chunks.next() { | |
| 2565 | − let is_last = chunks.peek().is_none(); | |
| 2566 | − client.send(proto::CreateBufferForPeer { | |
| 2567 | − project_id, | |
| 2568 | − peer_id: Some(peer_id), | |
| 2569 | − variant: Some(proto::create_buffer_for_peer::Variant::Chunk( | |
| 2570 | − proto::BufferChunk { | |
| 2571 | − buffer_id: buffer_id.into(), | |
| 2572 | − operations: chunk, | |
| 2573 | − is_last, | |
| 2574 | − }, | |
| 2575 | − )), | |
| 2576 | − })?; | |
| 2577 | − } | |
| 2578 | − anyhow::Ok(()) | |
| 2579 | − }) | |
| 2580 | − .await | |
| 2581 | − .log_err(); | |
| 2553 | + cx.background_spawn(async move { | |
| 2554 | + let mut chunks = split_operations(operations).peekable(); | |
| 2555 | + while let Some(chunk) = chunks.next() { | |
| 2556 | + let is_last = chunks.peek().is_none(); | |
| 2557 | + client.send(proto::CreateBufferForPeer { | |
| 2558 | + project_id, | |
| 2559 | + peer_id: Some(peer_id), | |
| 2560 | + variant: Some(proto::create_buffer_for_peer::Variant::Chunk( | |
| 2561 | + proto::BufferChunk { | |
| 2562 | + buffer_id: buffer_id.into(), | |
| 2563 | + operations: chunk, | |
| 2564 | + is_last, | |
| 2565 | + }, | |
| 2566 | + )), | |
| 2567 | + })?; | |
| 2568 | + } | |
| 2569 | + anyhow::Ok(()) | |
| 2570 | + }) | |
| 2571 | + .await | |
| 2572 | + .log_err(); | |
| 2582 | 2573 | } |
| 2583 | 2574 | Ok(()) |
| 2584 | 2575 | }) |
| @@ -135,8 +135,7 @@ impl ProjectEnvironment { · 134 unmodified lines | ||
| 135 | 135 | |
| 136 | 136 | cx.spawn(|this, mut cx| async move { |
| 137 | 137 | let (mut shell_env, error_message) = cx |
| 138 | − .background_executor() | |
| 139 | − .spawn({ | |
| 138 | + .background_spawn({ | |
| 140 | 139 | let worktree_abs_path = worktree_abs_path.clone(); |
| 141 | 140 | async move { |
| 142 | 141 | load_worktree_shell_environment(&worktree_abs_path, &load_direnv).await |
| @@ -11,8 +11,8 @@ use git::{ · 10 unmodified lines | ||
| 11 | 11 | status::{GitSummary, TrackedSummary}, |
| 12 | 12 | }; |
| 13 | 13 | use gpui::{ |
| 14 | − App, AppContext, AsyncApp, Context, Entity, EventEmitter, SharedString, Subscription, Task, | |
| 15 | − WeakEntity, | |
| 14 | + App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, SharedString, Subscription, | |
| 15 | + Task, WeakEntity, | |
| 16 | 16 | }; |
| 17 | 17 | use language::{Buffer, LanguageRegistry}; |
| 18 | 18 | use rpc::proto::{git_reset, ToProto}; |
| @@ -242,10 +242,7 @@ impl GitStore { · 223 unmodified lines | ||
| 242 | 242 | mpsc::unbounded::<(Message, oneshot::Sender<Result<()>>)>(); |
| 243 | 243 | cx.spawn(|_, cx| async move { |
| 244 | 244 | while let Some((msg, respond)) = update_receiver.next().await { |
| 245 | − let result = cx | |
| 246 | − .background_executor() | |
| 247 | − .spawn(Self::process_git_msg(msg)) | |
| 248 | − .await; | |
| 245 | + let result = cx.background_spawn(Self::process_git_msg(msg)).await; | |
| 249 | 246 | respond.send(result).ok(); |
| 250 | 247 | } |
| 251 | 248 | }) |
| @@ -841,15 +838,14 @@ impl Repository { · 589 unmodified lines | ||
| 841 | 838 | match self.git_repo.clone() { |
| 842 | 839 | GitRepo::Local(git_repository) => { |
| 843 | 840 | let commit = commit.to_string(); |
| 844 | − cx.background_executor() | |
| 845 | − .spawn(async move { git_repository.show(&commit) }) | |
| 841 | + cx.background_spawn(async move { git_repository.show(&commit) }) | |
| 846 | 842 | } |
| 847 | 843 | GitRepo::Remote { |
| 848 | 844 | project_id, |
| 849 | 845 | client, |
| 850 | 846 | worktree_id, |
| 851 | 847 | work_directory_id, |
| 852 | − } => cx.background_executor().spawn(async move { | |
| 848 | + } => cx.background_spawn(async move { | |
| 853 | 849 | let resp = client |
| 854 | 850 | .request(proto::GitShow { |
| 855 | 851 | project_id: project_id.0, |
| @@ -404,7 +404,7 @@ impl ImageStore { · 403 unmodified lines | ||
| 404 | 404 | } |
| 405 | 405 | }; |
| 406 | 406 | |
| 407 | − cx.background_executor().spawn(async move { | |
| 407 | + cx.background_spawn(async move { | |
| 408 | 408 | Self::wait_for_loading_image(loading_watch) |
| 409 | 409 | .await |
| 410 | 410 | .map_err(|e| e.cloned()) |
| @@ -2144,7 +2144,7 @@ impl LocalLspStore { · 2143 unmodified lines | ||
| 2144 | 2144 | cx: &mut Context<LspStore>, |
| 2145 | 2145 | ) -> Task<Result<Vec<(Range<Anchor>, String)>>> { |
| 2146 | 2146 | let snapshot = self.buffer_snapshot_for_lsp_version(buffer, server_id, version, cx); |
| 2147 | − cx.background_executor().spawn(async move { | |
| 2147 | + cx.background_spawn(async move { | |
| 2148 | 2148 | let snapshot = snapshot?; |
| 2149 | 2149 | let mut lsp_edits = lsp_edits |
| 2150 | 2150 | .into_iter() |
| @@ -3282,16 +3282,15 @@ impl LspStore { · 1131 unmodified lines | ||
| 3282 | 3282 | } |
| 3283 | 3283 | } else if let Some((upstream_client, upstream_project_id)) = self.upstream_client() { |
| 3284 | 3284 | let buffer_id = buffer.read(cx).remote_id().to_proto(); |
| 3285 | − cx.background_executor() | |
| 3286 | − .spawn(async move { | |
| 3287 | − upstream_client | |
| 3288 | − .request(proto::RegisterBufferWithLanguageServers { | |
| 3289 | − project_id: upstream_project_id, | |
| 3290 | − buffer_id, | |
| 3291 | − }) | |
| 3292 | − .await | |
| 3293 | − }) | |
| 3294 | − .detach(); | |
| 3285 | + cx.background_spawn(async move { | |
| 3286 | + upstream_client | |
| 3287 | + .request(proto::RegisterBufferWithLanguageServers { | |
| 3288 | + project_id: upstream_project_id, | |
| 3289 | + buffer_id, | |
| 3290 | + }) | |
| 3291 | + .await | |
| 3292 | + }) | |
| 3293 | + .detach(); | |
| 3295 | 3294 | } else { |
| 3296 | 3295 | panic!("oops!"); |
| 3297 | 3296 | } |
| @@ -6707,7 +6706,7 @@ impl LspStore { · 3409 unmodified lines | ||
| 6707 | 6706 | return Err(anyhow!("No language server {id}")); |
| 6708 | 6707 | }; |
| 6709 | 6708 | |
| 6710 | − Ok(cx.background_executor().spawn(async move { | |
| 6709 | + Ok(cx.background_spawn(async move { | |
| 6711 | 6710 | let can_resolve = server |
| 6712 | 6711 | .capabilities() |
| 6713 | 6712 | .completion_provider |
| @@ -7375,9 +7374,7 @@ impl LspStore { · 661 unmodified lines | ||
| 7375 | 7374 | .map(|b| b.read(cx).remote_id().to_proto()) |
| 7376 | 7375 | .collect(), |
| 7377 | 7376 | }); |
| 7378 | − cx.background_executor() | |
| 7379 | − .spawn(request) | |
| 7380 | − .detach_and_log_err(cx); | |
| 7377 | + cx.background_spawn(request).detach_and_log_err(cx); | |
| 7381 | 7378 | } else { |
| 7382 | 7379 | let Some(local) = self.as_local_mut() else { |
| 7383 | 7380 | return; |
| @@ -7406,9 +7403,7 @@ impl LspStore { · 22 unmodified lines | ||
| 7406 | 7403 | .collect::<Vec<_>>(); |
| 7407 | 7404 | |
| 7408 | 7405 | cx.spawn(|this, mut cx| async move { |
| 7409 | − cx.background_executor() | |
| 7410 | − .spawn(futures::future::join_all(tasks)) | |
| 7411 | − .await; | |
| 7406 | + cx.background_spawn(futures::future::join_all(tasks)).await; | |
| 7412 | 7407 | this.update(&mut cx, |this, cx| { |
| 7413 | 7408 | for buffer in buffers { |
| 7414 | 7409 | this.register_buffer_with_language_servers(&buffer, true, cx); |
| @@ -7737,9 +7732,7 @@ impl LspStore { · 322 unmodified lines | ||
| 7737 | 7732 | }, |
| 7738 | 7733 | )), |
| 7739 | 7734 | }); |
| 7740 | − cx.background_executor() | |
| 7741 | − .spawn(request) | |
| 7742 | − .detach_and_log_err(cx); | |
| 7735 | + cx.background_spawn(request).detach_and_log_err(cx); | |
| 7743 | 7736 | } else if let Some(local) = self.as_local() { |
| 7744 | 7737 | let servers = buffers |
| 7745 | 7738 | .into_iter() |
| @@ -7795,9 +7788,7 @@ impl LspStore { · 49 unmodified lines | ||
| 7795 | 7788 | ), |
| 7796 | 7789 | ), |
| 7797 | 7790 | }); |
| 7798 | − cx.background_executor() | |
| 7799 | − .spawn(request) | |
| 7800 | − .detach_and_log_err(cx); | |
| 7791 | + cx.background_spawn(request).detach_and_log_err(cx); | |
| 7801 | 7792 | } |
| 7802 | 7793 | } |
| 7803 | 7794 | |
| @@ -12,7 +12,7 @@ use futures::{ · 11 unmodified lines | ||
| 12 | 12 | stream::FuturesUnordered, |
| 13 | 13 | FutureExt, |
| 14 | 14 | }; |
| 15 | −use gpui::{AsyncApp, Context, Entity, EventEmitter, Task, WeakEntity}; | |
| 15 | +use gpui::{AppContext as _, AsyncApp, Context, Entity, EventEmitter, Task, WeakEntity}; | |
| 16 | 16 | use language::{ |
| 17 | 17 | language_settings::{Formatter, LanguageSettings, SelectedFormatter}, |
| 18 | 18 | Buffer, LanguageRegistry, LocalFile, |
| @@ -121,8 +121,7 @@ impl PrettierStore { · 102 unmodified lines | ||
| 121 | 121 | let installed_prettiers = self.prettier_instances.keys().cloned().collect(); |
| 122 | 122 | cx.spawn(|lsp_store, mut cx| async move { |
| 123 | 123 | match cx |
| 124 | − .background_executor() | |
| 125 | − .spawn(async move { | |
| 124 | + .background_spawn(async move { | |
| 126 | 125 | Prettier::locate_prettier_installation( |
| 127 | 126 | fs.as_ref(), |
| 128 | 127 | &installed_prettiers, |
| @@ -234,8 +233,7 @@ impl PrettierStore { · 105 unmodified lines | ||
| 234 | 233 | .unwrap_or_default(); |
| 235 | 234 | cx.spawn(|lsp_store, mut cx| async move { |
| 236 | 235 | match cx |
| 237 | − .background_executor() | |
| 238 | − .spawn(async move { | |
| 236 | + .background_spawn(async move { | |
| 239 | 237 | Prettier::locate_prettier_ignore( |
| 240 | 238 | fs.as_ref(), |
| 241 | 239 | &prettier_ignores, |
| @@ -483,31 +481,30 @@ impl PrettierStore { · 241 unmodified lines | ||
| 483 | 481 | })) |
| 484 | 482 | .collect::<Vec<_>>(); |
| 485 | 483 | |
| 486 | − cx.background_executor() | |
| 487 | − .spawn(async move { | |
| 488 | − let _: Vec<()> = future::join_all(prettiers_to_reload.into_iter().map(|(worktree_id, prettier_path, prettier_instance)| { | |
| 489 | − async move { | |
| 490 | − if let Some(instance) = prettier_instance.prettier { | |
| 491 | − match instance.await { | |
| 492 | − Ok(prettier) => { | |
| 493 | − prettier.clear_cache().log_err().await; | |
| 494 | − }, | |
| 495 | − Err(e) => { | |
| 496 | − match prettier_path { | |
| 497 | − Some(prettier_path) => log::error!( | |
| 498 | − "Failed to clear prettier {prettier_path:?} cache for worktree {worktree_id:?} on prettier settings update: {e:#}" | |
| 499 | − ), | |
| 500 | − None => log::error!( | |
| 501 | − "Failed to clear default prettier cache for worktree {worktree_id:?} on prettier settings update: {e:#}" | |
| 502 | − ), | |
| 503 | − } | |
| 504 | − }, | |
| 505 | − } | |
| 484 | + cx.background_spawn(async move { | |
| 485 | + let _: Vec<()> = future::join_all(prettiers_to_reload.into_iter().map(|(worktree_id, prettier_path, prettier_instance)| { | |
| 486 | + async move { | |
| 487 | + if let Some(instance) = prettier_instance.prettier { | |
| 488 | + match instance.await { | |
| 489 | + Ok(prettier) => { | |
| 490 | + prettier.clear_cache().log_err().await; | |
| 491 | + }, | |
| 492 | + Err(e) => { | |
| 493 | + match prettier_path { | |
| 494 | + Some(prettier_path) => log::error!( | |
| 495 | + "Failed to clear prettier {prettier_path:?} cache for worktree {worktree_id:?} on prettier settings update: {e:#}" | |
| 496 | + ), | |
| 497 | + None => log::error!( | |
| 498 | + "Failed to clear default prettier cache for worktree {worktree_id:?} on prettier settings update: {e:#}" | |
| 499 | + ), | |
| 500 | + } | |
| 501 | + }, | |
| 506 | 502 | } |
| 507 | 503 | } |
| 508 | − })) | |
| 509 | − .await; | |
| 510 | − }) | |
| 504 | + } | |
| 505 | + })) | |
| 506 | + .await; | |
| 507 | + }) | |
| 511 | 508 | .detach(); |
| 512 | 509 | } |
| 513 | 510 | } |
| @@ -539,7 +536,7 @@ impl PrettierStore { · 25 unmodified lines | ||
| 539 | 536 | }) { |
| 540 | 537 | Some(locate_from) => { |
| 541 | 538 | let installed_prettiers = self.prettier_instances.keys().cloned().collect(); |
| 542 | − cx.background_executor().spawn(async move { | |
| 539 | + cx.background_spawn(async move { | |
| 543 | 540 | Prettier::locate_prettier_installation( |
| 544 | 541 | fs.as_ref(), |
| 545 | 542 | &installed_prettiers, |
| @@ -631,13 +628,12 @@ impl PrettierStore { · 85 unmodified lines | ||
| 631 | 628 | })?; |
| 632 | 629 | if needs_install { |
| 633 | 630 | let installed_plugins = new_plugins.clone(); |
| 634 | − cx.background_executor() | |
| 635 | − .spawn(async move { | |
| 636 | − install_prettier_packages(fs.as_ref(), new_plugins, node).await?; | |
| 637 | − // Save the server file last, so the reinstall need could be determined by the absence of the file. | |
| 638 | − save_prettier_server_file(fs.as_ref()).await?; | |
| 639 | − anyhow::Ok(()) | |
| 640 | − }) | |
| 631 | + cx.background_spawn(async move { | |
| 632 | + install_prettier_packages(fs.as_ref(), new_plugins, node).await?; | |
| 633 | + // Save the server file last, so the reinstall need could be determined by the absence of the file. | |
| 634 | + save_prettier_server_file(fs.as_ref()).await?; | |
| 635 | + anyhow::Ok(()) | |
| 636 | + }) | |
| 641 | 637 | .await |
| 642 | 638 | .context("prettier & plugins install") |
| 643 | 639 | .map_err(Arc::new)?; |
| @@ -562,7 +562,7 @@ impl DirectoryLister { · 561 unmodified lines | ||
| 562 | 562 | } |
| 563 | 563 | DirectoryLister::Local(fs) => { |
| 564 | 564 | let fs = fs.clone(); |
| 565 | − cx.background_executor().spawn(async move { | |
| 565 | + cx.background_spawn(async move { | |
| 566 | 566 | let mut results = vec![]; |
| 567 | 567 | let expanded = shellexpand::tilde(&path); |
| 568 | 568 | let query = Path::new(expanded.as_ref()); |
| @@ -1163,13 +1163,12 @@ impl Project { · 594 unmodified lines | ||
| 1163 | 1163 | .read(cx) |
| 1164 | 1164 | .shutdown_processes(Some(proto::ShutdownRemoteServer {})); |
| 1165 | 1165 | |
| 1166 | − cx.background_executor() | |
| 1167 | − .spawn(async move { | |
| 1168 | − if let Some(shutdown) = shutdown { | |
| 1169 | − shutdown.await; | |
| 1170 | − } | |
| 1171 | − }) | |
| 1172 | − .detach() | |
| 1166 | + cx.background_spawn(async move { | |
| 1167 | + if let Some(shutdown) = shutdown { | |
| 1168 | + shutdown.await; | |
| 1169 | + } | |
| 1170 | + }) | |
| 1171 | + .detach() | |
| 1173 | 1172 | } |
| 1174 | 1173 | |
| 1175 | 1174 | match &self.client_state { |
| @@ -3138,7 +3137,7 @@ impl Project { · 1962 unmodified lines | ||
| 3138 | 3137 | let buffer = buffer.clone(); |
| 3139 | 3138 | let query = query.clone(); |
| 3140 | 3139 | let snapshot = buffer.read_with(&cx, |buffer, _| buffer.snapshot())?; |
| 3141 | − chunk_results.push(cx.background_executor().spawn(async move { | |
| 3140 | + chunk_results.push(cx.background_spawn(async move { | |
| 3142 | 3141 | let ranges = query |
| 3143 | 3142 | .search(&snapshot, None) |
| 3144 | 3143 | .await |
| @@ -3377,7 +3376,7 @@ impl Project { · 232 unmodified lines | ||
| 3377 | 3376 | cx: &mut Context<Self>, |
| 3378 | 3377 | ) -> Task<Option<ResolvedPath>> { |
| 3379 | 3378 | let resolve_task = self.resolve_abs_path(path, cx); |
| 3380 | − cx.background_executor().spawn(async move { | |
| 3379 | + cx.background_spawn(async move { | |
| 3381 | 3380 | let resolved_path = resolve_task.await; |
| 3382 | 3381 | resolved_path.filter(|path| path.is_file()) |
| 3383 | 3382 | }) |
| @@ -3391,7 +3390,7 @@ impl Project { · 7 unmodified lines | ||
| 3391 | 3390 | if self.is_local() { |
| 3392 | 3391 | let expanded = PathBuf::from(shellexpand::tilde(&path).into_owned()); |
| 3393 | 3392 | let fs = self.fs.clone(); |
| 3394 | − cx.background_executor().spawn(async move { | |
| 3393 | + cx.background_spawn(async move { | |
| 3395 | 3394 | let path = expanded.as_path(); |
| 3396 | 3395 | let metadata = fs.metadata(path).await.ok().flatten(); |
| 3397 | 3396 | |
| @@ -3409,7 +3408,7 @@ impl Project { · 11 unmodified lines | ||
| 3409 | 3408 | project_id: SSH_PROJECT_ID, |
| 3410 | 3409 | path: request_path.to_proto(), |
| 3411 | 3410 | }); |
| 3412 | − cx.background_executor().spawn(async move { | |
| 3411 | + cx.background_spawn(async move { | |
| 3413 | 3412 | let response = request.await.log_err()?; |
| 3414 | 3413 | if response.exists { |
| 3415 | 3414 | Some(ResolvedPath::AbsPath { |
| @@ -3490,7 +3489,7 @@ impl Project { · 74 unmodified lines | ||
| 3490 | 3489 | }; |
| 3491 | 3490 | |
| 3492 | 3491 | let response = session.read(cx).proto_client().request(request); |
| 3493 | − cx.background_executor().spawn(async move { | |
| 3492 | + cx.background_spawn(async move { | |
| 3494 | 3493 | let response = response.await?; |
| 3495 | 3494 | Ok(response.entries.into_iter().map(PathBuf::from).collect()) |
| 3496 | 3495 | }) |
| @@ -3906,8 +3905,7 @@ impl Project { · 409 unmodified lines | ||
| 3906 | 3905 | if let Some(remote_id) = this.remote_id() { |
| 3907 | 3906 | let mut payload = envelope.payload.clone(); |
| 3908 | 3907 | payload.project_id = remote_id; |
| 3909 | − cx.background_executor() | |
| 3910 | − .spawn(this.client.request(payload)) | |
| 3908 | + cx.background_spawn(this.client.request(payload)) | |
| 3911 | 3909 | .detach_and_log_err(cx); |
| 3912 | 3910 | } |
| 3913 | 3911 | this.buffer_store.clone() |
| @@ -3924,8 +3922,7 @@ impl Project { · 10 unmodified lines | ||
| 3924 | 3922 | if let Some(ssh) = &this.ssh_client { |
| 3925 | 3923 | let mut payload = envelope.payload.clone(); |
| 3926 | 3924 | payload.project_id = SSH_PROJECT_ID; |
| 3927 | − cx.background_executor() | |
| 3928 | − .spawn(ssh.read(cx).proto_client().request(payload)) | |
| 3925 | + cx.background_spawn(ssh.read(cx).proto_client().request(payload)) | |
| 3929 | 3926 | .detach_and_log_err(cx); |
| 3930 | 3927 | } |
| 3931 | 3928 | this.buffer_store.clone() |
| @@ -4146,7 +4143,7 @@ impl Project { · 214 unmodified lines | ||
| 4146 | 4143 | if let Some(buffer) = this.buffer_for_id(buffer_id, cx) { |
| 4147 | 4144 | let operations = |
| 4148 | 4145 | buffer.read(cx).serialize_ops(Some(remote_version), cx); |
| 4149 | − cx.background_executor().spawn(async move { | |
| 4146 | + cx.background_spawn(async move { | |
| 4150 | 4147 | let operations = operations.await; |
| 4151 | 4148 | for chunk in split_operations(operations) { |
| 4152 | 4149 | client |
| @@ -4169,12 +4166,11 @@ impl Project { · 16 unmodified lines | ||
| 4169 | 4166 | // Any incomplete buffers have open requests waiting. Request that the host sends |
| 4170 | 4167 | // creates these buffers for us again to unblock any waiting futures. |
| 4171 | 4168 | for id in incomplete_buffer_ids { |
| 4172 | − cx.background_executor() | |
| 4173 | − .spawn(client.request(proto::OpenBufferById { | |
| 4174 | − project_id, | |
| 4175 | − id: id.into(), | |
| 4176 | − })) | |
| 4177 | − .detach(); | |
| 4169 | + cx.background_spawn(client.request(proto::OpenBufferById { | |
| 4170 | + project_id, | |
| 4171 | + id: id.into(), | |
| 4172 | + })) | |
| 4173 | + .detach(); | |
| 4178 | 4174 | } |
| 4179 | 4175 | |
| 4180 | 4176 | futures::future::join_all(send_updates_for_buffers) |
| @@ -13,7 +13,7 @@ use std::{ · 12 unmodified lines | ||
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | 15 | use collections::HashMap; |
| 16 | −use gpui::{App, AppContext, Context, Entity, EventEmitter, Subscription}; | |
| 16 | +use gpui::{App, AppContext as _, Context, Entity, EventEmitter, Subscription}; | |
| 17 | 17 | use language::{CachedLspAdapter, LspAdapterDelegate}; |
| 18 | 18 | use lsp::LanguageServerName; |
| 19 | 19 | use path_trie::{LabelPresence, RootPathTrie, TriePath}; |
| @@ -15,7 +15,7 @@ use std::{ · 14 unmodified lines | ||
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | use collections::{HashMap, IndexMap}; |
| 18 | −use gpui::{App, AppContext, Entity, Subscription}; | |
| 18 | +use gpui::{App, AppContext as _, Entity, Subscription}; | |
| 19 | 19 | use itertools::Itertools; |
| 20 | 20 | use language::{ |
| 21 | 21 | language_settings::AllLanguageSettings, Attach, LanguageName, LanguageRegistry, |
| @@ -325,16 +325,15 @@ impl LocalToolchainStore { · 324 unmodified lines | ||
| 325 | 325 | .ok()? |
| 326 | 326 | .await; |
| 327 | 327 | |
| 328 | − cx.background_executor() | |
| 329 | − .spawn(async move { | |
| 330 | − let language = registry | |
| 331 | − .language_for_name(language_name.as_ref()) | |
| 332 | − .await | |
| 333 | − .ok()?; | |
| 334 | − let toolchains = language.toolchain_lister()?; | |
| 335 | − Some(toolchains.list(root.to_path_buf(), project_env).await) | |
| 336 | − }) | |
| 337 | − .await | |
| 328 | + cx.background_spawn(async move { | |
| 329 | + let language = registry | |
| 330 | + .language_for_name(language_name.as_ref()) | |
| 331 | + .await | |
| 332 | + .ok()?; | |
| 333 | + let toolchains = language.toolchain_lister()?; | |
| 334 | + Some(toolchains.list(root.to_path_buf(), project_env).await) | |
| 335 | + }) | |
| 336 | + .await | |
| 338 | 337 | }) |
| 339 | 338 | } |
| 340 | 339 | pub(crate) fn active_toolchain( |
| @@ -13,7 +13,9 @@ use futures::{ · 12 unmodified lines | ||
| 13 | 13 | FutureExt, SinkExt, |
| 14 | 14 | }; |
| 15 | 15 | use git::repository::Branch; |
| 16 | −use gpui::{App, AsyncApp, Context, Entity, EntityId, EventEmitter, Task, WeakEntity}; | |
| 16 | +use gpui::{ | |
| 17 | + App, AppContext as _, AsyncApp, Context, Entity, EntityId, EventEmitter, Task, WeakEntity, | |
| 18 | +}; | |
| 17 | 19 | use postage::oneshot; |
| 18 | 20 | use rpc::{ |
| 19 | 21 | proto::{self, FromProto, ToProto, SSH_PROJECT_ID}, |
| @@ -179,8 +181,7 @@ impl WorktreeStore { · 159 unmodified lines | ||
| 179 | 181 | Task::ready(Ok((tree, relative_path))) |
| 180 | 182 | } else { |
| 181 | 183 | let worktree = self.create_worktree(abs_path, visible, cx); |
| 182 | − cx.background_executor() | |
| 183 | − .spawn(async move { Ok((worktree.await?, PathBuf::new())) }) | |
| 184 | + cx.background_spawn(async move { Ok((worktree.await?, PathBuf::new())) }) | |
| 184 | 185 | } |
| 185 | 186 | } |
| 186 | 187 | |
| @@ -679,7 +680,7 @@ impl WorktreeStore { · 492 unmodified lines | ||
| 679 | 680 | let (output_tx, output_rx) = smol::channel::bounded(64); |
| 680 | 681 | let (matching_paths_tx, matching_paths_rx) = smol::channel::unbounded(); |
| 681 | 682 | |
| 682 | − let input = cx.background_executor().spawn({ | |
| 683 | + let input = cx.background_spawn({ | |
| 683 | 684 | let fs = fs.clone(); |
| 684 | 685 | let query = query.clone(); |
| 685 | 686 | async move { |
| @@ -696,7 +697,7 @@ impl WorktreeStore { · 10 unmodified lines | ||
| 696 | 697 | } |
| 697 | 698 | }); |
| 698 | 699 | const MAX_CONCURRENT_FILE_SCANS: usize = 64; |
| 699 | − let filters = cx.background_executor().spawn(async move { | |
| 700 | + let filters = cx.background_spawn(async move { | |
| 700 | 701 | let fs = &fs; |
| 701 | 702 | let query = &query; |
| 702 | 703 | executor |
| @@ -712,25 +713,24 @@ impl WorktreeStore { · 9 unmodified lines | ||
| 712 | 713 | }) |
| 713 | 714 | .await; |
| 714 | 715 | }); |
| 715 | − cx.background_executor() | |
| 716 | − .spawn(async move { | |
| 717 | − let mut matched = 0; | |
| 718 | − while let Ok(mut receiver) = output_rx.recv().await { | |
| 719 | − let Some(path) = receiver.next().await else { | |
| 720 | − continue; | |
| 721 | − }; | |
| 722 | − let Ok(_) = matching_paths_tx.send(path).await else { | |
| 723 | − break; | |
| 724 | − }; | |
| 725 | − matched += 1; | |
| 726 | − if matched == limit { | |
| 727 | − break; | |
| 728 | − } | |
| 716 | + cx.background_spawn(async move { | |
| 717 | + let mut matched = 0; | |
| 718 | + while let Ok(mut receiver) = output_rx.recv().await { | |
| 719 | + let Some(path) = receiver.next().await else { | |
| 720 | + continue; | |
| 721 | + }; | |
| 722 | + let Ok(_) = matching_paths_tx.send(path).await else { | |
| 723 | + break; | |
| 724 | + }; | |
| 725 | + matched += 1; | |
| 726 | + if matched == limit { | |
| 727 | + break; | |
| 729 | 728 | } |
| 730 | − drop(input); | |
| 731 | − drop(filters); | |
| 732 | − }) | |
| 733 | − .detach(); | |
| 729 | + } | |
| 730 | + drop(input); | |
| 731 | + drop(filters); | |
| 732 | + }) | |
| 733 | + .detach(); | |
| 734 | 734 | matching_paths_rx |
| 735 | 735 | } |
| 736 | 736 | |
| @@ -934,7 +934,7 @@ impl WorktreeStore { · 197 unmodified lines | ||
| 934 | 934 | }), |
| 935 | 935 | }); |
| 936 | 936 | |
| 937 | − cx.background_executor().spawn(async move { | |
| 937 | + cx.background_spawn(async move { | |
| 938 | 938 | let response = request.await?; |
| 939 | 939 | |
| 940 | 940 | let branches = response |
| @@ -1021,7 +1021,7 @@ impl WorktreeStore { · 80 unmodified lines | ||
| 1021 | 1021 | branch_name: new_branch, |
| 1022 | 1022 | }); |
| 1023 | 1023 | |
| 1024 | − cx.background_executor().spawn(async move { | |
| 1024 | + cx.background_spawn(async move { | |
| 1025 | 1025 | request.await?; |
| 1026 | 1026 | Ok(()) |
| 1027 | 1027 | }) |
| @@ -544,8 +544,7 @@ impl ProjectPanel { · 543 unmodified lines | ||
| 544 | 544 | mut cx: AsyncWindowContext, |
| 545 | 545 | ) -> Result<Entity<Self>> { |
| 546 | 546 | let serialized_panel = cx |
| 547 | − .background_executor() | |
| 548 | − .spawn(async move { KEY_VALUE_STORE.read_kvp(PROJECT_PANEL_KEY) }) | |
| 547 | + .background_spawn(async move { KEY_VALUE_STORE.read_kvp(PROJECT_PANEL_KEY) }) | |
| 549 | 548 | .await |
| 550 | 549 | .map_err(|e| anyhow!("Failed to load project panel: {}", e)) |
| 551 | 550 | .log_err() |
| @@ -627,7 +626,7 @@ impl ProjectPanel { · 75 unmodified lines | ||
| 627 | 626 | |
| 628 | 627 | fn serialize(&mut self, cx: &mut Context<Self>) { |
| 629 | 628 | let width = self.width; |
| 630 | − self.pending_serialization = cx.background_executor().spawn( | |
| 629 | + self.pending_serialization = cx.background_spawn( | |
| 631 | 630 | async move { |
| 632 | 631 | KEY_VALUE_STORE |
| 633 | 632 | .write_kvp( |
| @@ -218,8 +218,7 @@ impl PickerDelegate for PromptPickerDelegate { · 217 unmodified lines | ||
| 218 | 218 | let prev_prompt_id = self.matches.get(self.selected_index).map(|mat| mat.id); |
| 219 | 219 | cx.spawn_in(window, |this, mut cx| async move { |
| 220 | 220 | let (matches, selected_index) = cx |
| 221 | − .background_executor() | |
| 222 | − .spawn(async move { | |
| 221 | + .background_spawn(async move { | |
| 223 | 222 | let matches = search.await; |
| 224 | 223 | |
| 225 | 224 | let selected_index = prev_prompt_id |
| @@ -2,7 +2,7 @@ use anyhow::Result; · 1 unmodified line | ||
| 2 | 2 | use assets::Assets; |
| 3 | 3 | use fs::Fs; |
| 4 | 4 | use futures::StreamExt; |
| 5 | −use gpui::{App, AssetSource}; | |
| 5 | +use gpui::{App, AppContext as _, AssetSource}; | |
| 6 | 6 | use handlebars::{Handlebars, RenderError}; |
| 7 | 7 | use language::{BufferSnapshot, LanguageName, Point}; |
| 8 | 8 | use parking_lot::Mutex; |
| @@ -103,103 +103,102 @@ impl PromptBuilder { · 94 unmodified lines | ||
| 103 | 103 | handlebars: Arc<Mutex<Handlebars<'static>>>, |
| 104 | 104 | ) { |
| 105 | 105 | let templates_dir = paths::prompt_overrides_dir(params.repo_path.as_deref()); |
| 106 | − params.cx.background_executor() | |
| 107 | − .spawn(async move { | |
| 108 | − let Some(parent_dir) = templates_dir.parent() else { | |
| 109 | − return; | |
| 110 | − }; | |
| 111 | − | |
| 112 | − let mut found_dir_once = false; | |
| 113 | − loop { | |
| 114 | − // Check if the templates directory exists and handle its status | |
| 115 | − // If it exists, log its presence and check if it's a symlink | |
| 116 | − // If it doesn't exist: | |
| 117 | − // - Log that we're using built-in prompts | |
| 118 | − // - Check if it's a broken symlink and log if so | |
| 119 | − // - Set up a watcher to detect when it's created | |
| 120 | − // After the first check, set the `found_dir_once` flag | |
| 121 | − // This allows us to avoid logging when looping back around after deleting the prompt overrides directory. | |
| 122 | − let dir_status = params.fs.is_dir(&templates_dir).await; | |
| 123 | − let symlink_status = params.fs.read_link(&templates_dir).await.ok(); | |
| 124 | − if dir_status { | |
| 125 | − let mut log_message = format!("Prompt template overrides directory found at {}", templates_dir.display()); | |
| 106 | + params.cx.background_spawn(async move { | |
| 107 | + let Some(parent_dir) = templates_dir.parent() else { | |
| 108 | + return; | |
| 109 | + }; | |
| 110 | + | |
| 111 | + let mut found_dir_once = false; | |
| 112 | + loop { | |
| 113 | + // Check if the templates directory exists and handle its status | |
| 114 | + // If it exists, log its presence and check if it's a symlink | |
| 115 | + // If it doesn't exist: | |
| 116 | + // - Log that we're using built-in prompts | |
| 117 | + // - Check if it's a broken symlink and log if so | |
| 118 | + // - Set up a watcher to detect when it's created | |
| 119 | + // After the first check, set the `found_dir_once` flag | |
| 120 | + // This allows us to avoid logging when looping back around after deleting the prompt overrides directory. | |
| 121 | + let dir_status = params.fs.is_dir(&templates_dir).await; | |
| 122 | + let symlink_status = params.fs.read_link(&templates_dir).await.ok(); | |
| 123 | + if dir_status { | |
| 124 | + let mut log_message = format!("Prompt template overrides directory found at {}", templates_dir.display()); | |
| 125 | + if let Some(target) = symlink_status { | |
| 126 | + log_message.push_str(" -> "); | |
| 127 | + log_message.push_str(&target.display().to_string()); | |
| 128 | + } | |
| 129 | + log::info!("{}.", log_message); | |
| 130 | + } else { | |
| 131 | + if !found_dir_once { | |
| 132 | + log::info!("No prompt template overrides directory found at {}. Using built-in prompts.", templates_dir.display()); | |
| 126 | 133 | if let Some(target) = symlink_status { |
| 127 | − log_message.push_str(" -> "); | |
| 128 | − log_message.push_str(&target.display().to_string()); | |
| 129 | − } | |
| 130 | − log::info!("{}.", log_message); | |
| 131 | − } else { | |
| 132 | − if !found_dir_once { | |
| 133 | − log::info!("No prompt template overrides directory found at {}. Using built-in prompts.", templates_dir.display()); | |
| 134 | − if let Some(target) = symlink_status { | |
| 135 | − log::info!("Symlink found pointing to {}, but target is invalid.", target.display()); | |
| 136 | − } | |
| 134 | + log::info!("Symlink found pointing to {}, but target is invalid.", target.display()); | |
| 137 | 135 | } |
| 136 | + } | |
| 138 | 137 | |
| 139 | − if params.fs.is_dir(parent_dir).await { | |
| 140 | − let (mut changes, _watcher) = params.fs.watch(parent_dir, Duration::from_secs(1)).await; | |
| 141 | − while let Some(changed_paths) = changes.next().await { | |
| 142 | − if changed_paths.iter().any(|p| &p.path == &templates_dir) { | |
| 143 | − let mut log_message = format!("Prompt template overrides directory detected at {}", templates_dir.display()); | |
| 144 | − if let Ok(target) = params.fs.read_link(&templates_dir).await { | |
| 145 | − log_message.push_str(" -> "); | |
| 146 | − log_message.push_str(&target.display().to_string()); | |
| 147 | − } | |
| 148 | − log::info!("{}.", log_message); | |
| 149 | − break; | |
| 138 | + if params.fs.is_dir(parent_dir).await { | |
| 139 | + let (mut changes, _watcher) = params.fs.watch(parent_dir, Duration::from_secs(1)).await; | |
| 140 | + while let Some(changed_paths) = changes.next().await { | |
| 141 | + if changed_paths.iter().any(|p| &p.path == &templates_dir) { | |
| 142 | + let mut log_message = format!("Prompt template overrides directory detected at {}", templates_dir.display()); | |
| 143 | + if let Ok(target) = params.fs.read_link(&templates_dir).await { | |
| 144 | + log_message.push_str(" -> "); | |
| 145 | + log_message.push_str(&target.display().to_string()); | |
| 150 | 146 | } |
| 147 | + log::info!("{}.", log_message); | |
| 148 | + break; | |
| 151 | 149 | } |
| 152 | − } else { | |
| 153 | − return; | |
| 154 | 150 | } |
| 151 | + } else { | |
| 152 | + return; | |
| 155 | 153 | } |
| 154 | + } | |
| 156 | 155 | |
| 157 | − found_dir_once = true; | |
| 156 | + found_dir_once = true; | |
| 158 | 157 | |
| 159 | − // Initial scan of the prompt overrides directory | |
| 160 | − if let Ok(mut entries) = params.fs.read_dir(&templates_dir).await { | |
| 161 | − while let Some(Ok(file_path)) = entries.next().await { | |
| 162 | − if file_path.to_string_lossy().ends_with(".hbs") { | |
| 163 | − if let Ok(content) = params.fs.load(&file_path).await { | |
| 164 | − let file_name = file_path.file_stem().unwrap().to_string_lossy(); | |
| 165 | − log::debug!("Registering prompt template override: {}", file_name); | |
| 166 | − handlebars.lock().register_template_string(&file_name, content).log_err(); | |
| 167 | − } | |
| 158 | + // Initial scan of the prompt overrides directory | |
| 159 | + if let Ok(mut entries) = params.fs.read_dir(&templates_dir).await { | |
| 160 | + while let Some(Ok(file_path)) = entries.next().await { | |
| 161 | + if file_path.to_string_lossy().ends_with(".hbs") { | |
| 162 | + if let Ok(content) = params.fs.load(&file_path).await { | |
| 163 | + let file_name = file_path.file_stem().unwrap().to_string_lossy(); | |
| 164 | + log::debug!("Registering prompt template override: {}", file_name); | |
| 165 | + handlebars.lock().register_template_string(&file_name, content).log_err(); | |
| 168 | 166 | } |
| 169 | 167 | } |
| 170 | 168 | } |
| 169 | + } | |
| 171 | 170 | |
| 172 | − // Watch both the parent directory and the template overrides directory: | |
| 173 | − // - Monitor the parent directory to detect if the template overrides directory is deleted. | |
| 174 | − // - Monitor the template overrides directory to re-register templates when they change. | |
| 175 | − // Combine both watch streams into a single stream. | |
| 176 | − let (parent_changes, parent_watcher) = params.fs.watch(parent_dir, Duration::from_secs(1)).await; | |
| 177 | − let (changes, watcher) = params.fs.watch(&templates_dir, Duration::from_secs(1)).await; | |
| 178 | − let mut combined_changes = futures::stream::select(changes, parent_changes); | |
| 179 | − | |
| 180 | − while let Some(changed_paths) = combined_changes.next().await { | |
| 181 | − if changed_paths.iter().any(|p| &p.path == &templates_dir) { | |
| 182 | − if !params.fs.is_dir(&templates_dir).await { | |
| 183 | − log::info!("Prompt template overrides directory removed. Restoring built-in prompt templates."); | |
| 184 | − Self::register_built_in_templates(&mut handlebars.lock()).log_err(); | |
| 185 | − break; | |
| 186 | − } | |
| 171 | + // Watch both the parent directory and the template overrides directory: | |
| 172 | + // - Monitor the parent directory to detect if the template overrides directory is deleted. | |
| 173 | + // - Monitor the template overrides directory to re-register templates when they change. | |
| 174 | + // Combine both watch streams into a single stream. | |
| 175 | + let (parent_changes, parent_watcher) = params.fs.watch(parent_dir, Duration::from_secs(1)).await; | |
| 176 | + let (changes, watcher) = params.fs.watch(&templates_dir, Duration::from_secs(1)).await; | |
| 177 | + let mut combined_changes = futures::stream::select(changes, parent_changes); | |
| 178 | + | |
| 179 | + while let Some(changed_paths) = combined_changes.next().await { | |
| 180 | + if changed_paths.iter().any(|p| &p.path == &templates_dir) { | |
| 181 | + if !params.fs.is_dir(&templates_dir).await { | |
| 182 | + log::info!("Prompt template overrides directory removed. Restoring built-in prompt templates."); | |
| 183 | + Self::register_built_in_templates(&mut handlebars.lock()).log_err(); | |
| 184 | + break; | |
| 187 | 185 | } |
| 188 | − for event in changed_paths { | |
| 189 | − if event.path.starts_with(&templates_dir) && event.path.extension().map_or(false, |ext| ext == "hbs") { | |
| 190 | − log::info!("Reloading prompt template override: {}", event.path.display()); | |
| 191 | − if let Some(content) = params.fs.load(&event.path).await.log_err() { | |
| 192 | − let file_name = event.path.file_stem().unwrap().to_string_lossy(); | |
| 193 | − handlebars.lock().register_template_string(&file_name, content).log_err(); | |
| 194 | − } | |
| 186 | + } | |
| 187 | + for event in changed_paths { | |
| 188 | + if event.path.starts_with(&templates_dir) && event.path.extension().map_or(false, |ext| ext == "hbs") { | |
| 189 | + log::info!("Reloading prompt template override: {}", event.path.display()); | |
| 190 | + if let Some(content) = params.fs.load(&event.path).await.log_err() { | |
| 191 | + let file_name = event.path.file_stem().unwrap().to_string_lossy(); | |
| 192 | + handlebars.lock().register_template_string(&file_name, content).log_err(); | |
| 195 | 193 | } |
| 196 | 194 | } |
| 197 | 195 | } |
| 198 | − | |
| 199 | − drop(watcher); | |
| 200 | − drop(parent_watcher); | |
| 201 | 196 | } |
| 202 | − }) | |
| 197 | + | |
| 198 | + drop(watcher); | |
| 199 | + drop(parent_watcher); | |
| 200 | + } | |
| 201 | + }) | |
| 203 | 202 | .detach(); |
| 204 | 203 | } |
| 205 | 204 | |
| @@ -17,7 +17,7 @@ use futures::{ · 16 unmodified lines | ||
| 17 | 17 | select, select_biased, AsyncReadExt as _, Future, FutureExt as _, StreamExt as _, |
| 18 | 18 | }; |
| 19 | 19 | use gpui::{ |
| 20 | − App, AppContext, AsyncApp, BorrowAppContext, Context, Entity, EventEmitter, Global, | |
| 20 | + App, AppContext as _, AsyncApp, BorrowAppContext, Context, Entity, EventEmitter, Global, | |
| 21 | 21 | SemanticVersion, Task, WeakEntity, |
| 22 | 22 | }; |
| 23 | 23 | use itertools::Itertools; |
| @@ -1158,12 +1158,11 @@ impl SshRemoteClient { · 1134 unmodified lines | ||
| 1158 | 1158 | c.connections.insert( |
| 1159 | 1159 | opts.clone(), |
| 1160 | 1160 | ConnectionPoolEntry::Connecting( |
| 1161 | − cx.background_executor() | |
| 1162 | − .spawn({ | |
| 1163 | − let connection = connection.clone(); | |
| 1164 | − async move { Ok(connection.clone()) } | |
| 1165 | − }) | |
| 1166 | − .shared(), | |
| 1161 | + cx.background_spawn({ | |
| 1162 | + let connection = connection.clone(); | |
| 1163 | + async move { Ok(connection.clone()) } | |
| 1164 | + }) | |
| 1165 | + .shared(), | |
| 1167 | 1166 | ), |
| 1168 | 1167 | ); |
| 1169 | 1168 | }) |
| @@ -1358,7 +1357,7 @@ impl RemoteConnection for SshRemoteConnection { · 188 unmodified lines | ||
| 1358 | 1357 | )) |
| 1359 | 1358 | .output(); |
| 1360 | 1359 | |
| 1361 | − cx.background_executor().spawn(async move { | |
| 1360 | + cx.background_spawn(async move { | |
| 1362 | 1361 | let output = output.await?; |
| 1363 | 1362 | |
| 1364 | 1363 | if !output.status.success() { |
| @@ -1679,14 +1678,14 @@ impl SshRemoteConnection { · 314 unmodified lines | ||
| 1679 | 1678 | let mut stderr_buffer = Vec::new(); |
| 1680 | 1679 | let mut stderr_offset = 0; |
| 1681 | 1680 | |
| 1682 | − let stdin_task = cx.background_executor().spawn(async move { | |
| 1681 | + let stdin_task = cx.background_spawn(async move { | |
| 1683 | 1682 | while let Some(outgoing) = outgoing_rx.next().await { |
| 1684 | 1683 | write_message(&mut child_stdin, &mut stdin_buffer, outgoing).await?; |
| 1685 | 1684 | } |
| 1686 | 1685 | anyhow::Ok(()) |
| 1687 | 1686 | }); |
| 1688 | 1687 | |
| 1689 | − let stdout_task = cx.background_executor().spawn({ | |
| 1688 | + let stdout_task = cx.background_spawn({ | |
| 1690 | 1689 | let mut connection_activity_tx = connection_activity_tx.clone(); |
| 1691 | 1690 | async move { |
| 1692 | 1691 | loop { |
| @@ -1711,7 +1710,7 @@ impl SshRemoteConnection { · 18 unmodified lines | ||
| 1711 | 1710 | } |
| 1712 | 1711 | }); |
| 1713 | 1712 | |
| 1714 | − let stderr_task: Task<anyhow::Result<()>> = cx.background_executor().spawn(async move { | |
| 1713 | + let stderr_task: Task<anyhow::Result<()>> = cx.background_spawn(async move { | |
| 1715 | 1714 | loop { |
| 1716 | 1715 | stderr_buffer.resize(stderr_offset + 1024, 0); |
| 1717 | 1716 | |
| @@ -2449,7 +2448,7 @@ mod fake { · 731 unmodified lines | ||
| 2449 | 2448 | }, |
| 2450 | 2449 | select_biased, FutureExt, SinkExt, StreamExt, |
| 2451 | 2450 | }; |
| 2452 | − use gpui::{App, AsyncApp, SemanticVersion, Task, TestAppContext}; | |
| 2451 | + use gpui::{App, AppContext as _, AsyncApp, SemanticVersion, Task, TestAppContext}; | |
| 2453 | 2452 | use release_channel::ReleaseChannel; |
| 2454 | 2453 | use rpc::proto::Envelope; |
| 2455 | 2454 | |
| @@ -2533,7 +2532,7 @@ mod fake { · 77 unmodified lines | ||
| 2533 | 2532 | &self.server_cx.get(cx), |
| 2534 | 2533 | ); |
| 2535 | 2534 | |
| 2536 | − cx.background_executor().spawn(async move { | |
| 2535 | + cx.background_spawn(async move { | |
| 2537 | 2536 | loop { |
| 2538 | 2537 | select_biased! { |
| 2539 | 2538 | server_to_client = server_outgoing_rx.next().fuse() => { |
| @@ -240,8 +240,7 @@ impl HeadlessProject { · 239 unmodified lines | ||
| 240 | 240 | operation, |
| 241 | 241 | is_local: true, |
| 242 | 242 | } => cx |
| 243 | − .background_executor() | |
| 244 | − .spawn(self.session.request(proto::UpdateBuffer { | |
| 243 | + .background_spawn(self.session.request(proto::UpdateBuffer { | |
| 245 | 244 | project_id: SSH_PROJECT_ID, |
| 246 | 245 | buffer_id: buffer.read(cx).remote_id().to_proto(), |
| 247 | 246 | operations: vec![serialize_operation(operation)], |
| @@ -302,15 +301,14 @@ impl HeadlessProject { · 54 unmodified lines | ||
| 302 | 301 | message: prompt.message.clone(), |
| 303 | 302 | }); |
| 304 | 303 | let prompt = prompt.clone(); |
| 305 | − cx.background_executor() | |
| 306 | − .spawn(async move { | |
| 307 | − let response = request.await?; | |
| 308 | − if let Some(action_response) = response.action_response { | |
| 309 | − prompt.respond(action_response as usize).await; | |
| 310 | − } | |
| 311 | − anyhow::Ok(()) | |
| 312 | − }) | |
| 313 | − .detach(); | |
| 304 | + cx.background_spawn(async move { | |
| 305 | + let response = request.await?; | |
| 306 | + if let Some(action_response) = response.action_response { | |
| 307 | + prompt.respond(action_response as usize).await; | |
| 308 | + } | |
| 309 | + anyhow::Ok(()) | |
| 310 | + }) | |
| 311 | + .detach(); | |
| 314 | 312 | } |
| 315 | 313 | _ => {} |
| 316 | 314 | } |
| @@ -311,7 +311,7 @@ fn start_server( · 310 unmodified lines | ||
| 311 | 311 | let mut output_buffer = Vec::new(); |
| 312 | 312 | |
| 313 | 313 | let (mut stdin_msg_tx, mut stdin_msg_rx) = mpsc::unbounded::<Envelope>(); |
| 314 | − cx.background_executor().spawn(async move { | |
| 314 | + cx.background_spawn(async move { | |
| 315 | 315 | while let Ok(msg) = read_message(&mut stdin_stream, &mut input_buffer).await { |
| 316 | 316 | if let Err(_) = stdin_msg_tx.send(msg).await { |
| 317 | 317 | break; |
| @@ -487,8 +487,7 @@ pub fn execute_run( · 169 unmodified lines | ||
| 487 | 487 | |
| 488 | 488 | handle_panic_requests(&project, &session); |
| 489 | 489 | |
| 490 | − cx.background_executor() | |
| 491 | − .spawn(async move { cleanup_old_binaries() }) | |
| 490 | + cx.background_spawn(async move { cleanup_old_binaries() }) | |
| 492 | 491 | .detach(); |
| 493 | 492 | |
| 494 | 493 | mem::forget(project); |
| @@ -5,7 +5,7 @@ use futures::{ · 4 unmodified lines | ||
| 5 | 5 | stream::{SelectAll, StreamExt}, |
| 6 | 6 | AsyncBufReadExt as _, SinkExt as _, |
| 7 | 7 | }; |
| 8 | −use gpui::{App, Entity, EntityId, Task, Window}; | |
| 8 | +use gpui::{App, AppContext as _, Entity, EntityId, Task, Window}; | |
| 9 | 9 | use jupyter_protocol::{ |
| 10 | 10 | connection_info::{ConnectionInfo, Transport}, |
| 11 | 11 | ExecutionState, JupyterKernelspec, JupyterMessage, JupyterMessageContent, KernelInfoReply, |
| @@ -211,7 +211,7 @@ impl NativeRunningKernel { · 199 unmodified lines | ||
| 211 | 211 | futures::channel::mpsc::channel(100); |
| 212 | 212 | let (mut shell_request_tx, mut shell_request_rx) = futures::channel::mpsc::channel(100); |
| 213 | 213 | |
| 214 | − let routing_task = cx.background_executor().spawn({ | |
| 214 | + let routing_task = cx.background_spawn({ | |
| 215 | 215 | async move { |
| 216 | 216 | while let Some(message) = request_rx.next().await { |
| 217 | 217 | match message.content { |
| @@ -229,7 +229,7 @@ impl NativeRunningKernel { · 11 unmodified lines | ||
| 229 | 229 | } |
| 230 | 230 | }); |
| 231 | 231 | |
| 232 | − let shell_task = cx.background_executor().spawn({ | |
| 232 | + let shell_task = cx.background_spawn({ | |
| 233 | 233 | async move { |
| 234 | 234 | while let Some(message) = shell_request_rx.next().await { |
| 235 | 235 | shell_socket.send(message).await.ok(); |
| @@ -240,7 +240,7 @@ impl NativeRunningKernel { · 4 unmodified lines | ||
| 240 | 240 | } |
| 241 | 241 | }); |
| 242 | 242 | |
| 243 | − let control_task = cx.background_executor().spawn({ | |
| 243 | + let control_task = cx.background_spawn({ | |
| 244 | 244 | async move { |
| 245 | 245 | while let Some(message) = control_request_rx.next().await { |
| 246 | 246 | control_socket.send(message).await.ok(); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use futures::{channel::mpsc, SinkExt as _}; |
| 2 | −use gpui::{App, Entity, Task, Window}; | |
| 2 | +use gpui::{App, AppContext as _, Entity, Task, Window}; | |
| 3 | 3 | use http_client::{AsyncBody, HttpClient, Request}; |
| 4 | 4 | use jupyter_protocol::{ExecutionState, JupyterKernelspec, JupyterMessage, KernelInfoReply}; |
| 5 | 5 | |
| @@ -189,7 +189,7 @@ impl RemoteRunningKernel { · 183 unmodified lines | ||
| 189 | 189 | let (request_tx, mut request_rx) = |
| 190 | 190 | futures::channel::mpsc::channel::<JupyterMessage>(100); |
| 191 | 191 | |
| 192 | − let routing_task = cx.background_executor().spawn({ | |
| 192 | + let routing_task = cx.background_spawn({ | |
| 193 | 193 | async move { |
| 194 | 194 | while let Some(message) = request_rx.next().await { |
| 195 | 195 | w.send(message).await.ok(); |
| @@ -134,8 +134,7 @@ impl Cell { · 133 unmodified lines | ||
| 134 | 134 | |
| 135 | 135 | cx.spawn_in(window, |this, mut cx| async move { |
| 136 | 136 | let parsed_markdown = cx |
| 137 | − .background_executor() | |
| 138 | − .spawn(async move { | |
| 137 | + .background_spawn(async move { | |
| 139 | 138 | parse_markdown(&source, None, Some(languages)).await |
| 140 | 139 | }) |
| 141 | 140 | .await; |
| @@ -19,9 +19,8 @@ impl MarkdownView { · 18 unmodified lines | ||
| 19 | 19 | pub fn from(text: String, cx: &mut Context<Self>) -> Self { |
| 20 | 20 | let task = cx.spawn(|markdown_view, mut cx| { |
| 21 | 21 | let text = text.clone(); |
| 22 | − let parsed = cx | |
| 23 | − .background_executor() | |
| 24 | − .spawn(async move { parse_markdown(&text, None, None).await }); | |
| 22 | + let parsed = | |
| 23 | + cx.background_spawn(async move { parse_markdown(&text, None, None).await }); | |
| 25 | 24 | |
| 26 | 25 | async move { |
| 27 | 26 | let content = parsed.await; |
| @@ -164,7 +164,7 @@ impl ReplStore { · 163 unmodified lines | ||
| 164 | 164 | |
| 165 | 165 | let remote_kernel_specifications = self.get_remote_kernel_specifications(cx); |
| 166 | 166 | |
| 167 | − let all_specs = cx.background_executor().spawn(async move { | |
| 167 | + let all_specs = cx.background_spawn(async move { | |
| 168 | 168 | let mut all_specs = local_kernel_specifications |
| 169 | 169 | .await? |
| 170 | 170 | .into_iter() |
| @@ -10,7 +10,7 @@ use fs::Fs; · 9 unmodified lines | ||
| 10 | 10 | use fs::MTime; |
| 11 | 11 | use futures::{stream::StreamExt, FutureExt as _}; |
| 12 | 12 | use futures_batch::ChunksTimeoutStreamExt; |
| 13 | −use gpui::{App, Entity, Task}; | |
| 13 | +use gpui::{App, AppContext as _, Entity, Task}; | |
| 14 | 14 | use heed::types::{SerdeBincode, Str}; |
| 15 | 15 | use language::LanguageRegistry; |
| 16 | 16 | use log; |
| @@ -102,7 +102,7 @@ impl EmbeddingIndex { · 85 unmodified lines | ||
| 102 | 102 | let db_connection = self.db_connection.clone(); |
| 103 | 103 | let db = self.db; |
| 104 | 104 | let entries_being_indexed = self.entry_ids_being_indexed.clone(); |
| 105 | − let task = cx.background_executor().spawn(async move { | |
| 105 | + let task = cx.background_spawn(async move { | |
| 106 | 106 | let txn = db_connection |
| 107 | 107 | .read_txn() |
| 108 | 108 | .context("failed to create read transaction")?; |
| @@ -185,7 +185,7 @@ impl EmbeddingIndex { · 76 unmodified lines | ||
| 185 | 185 | let (updated_entries_tx, updated_entries_rx) = channel::bounded(512); |
| 186 | 186 | let (deleted_entry_ranges_tx, deleted_entry_ranges_rx) = channel::bounded(128); |
| 187 | 187 | let entries_being_indexed = self.entry_ids_being_indexed.clone(); |
| 188 | − let task = cx.background_executor().spawn(async move { | |
| 188 | + let task = cx.background_spawn(async move { | |
| 189 | 189 | for (path, entry_id, status) in updated_entries.iter() { |
| 190 | 190 | match status { |
| 191 | 191 | project::PathChange::Added |
| @@ -278,7 +278,7 @@ impl EmbeddingIndex { · 86 unmodified lines | ||
| 278 | 278 | ) -> EmbedFiles { |
| 279 | 279 | let embedding_provider = embedding_provider.clone(); |
| 280 | 280 | let (embedded_files_tx, embedded_files_rx) = channel::bounded(512); |
| 281 | − let task = cx.background_executor().spawn(async move { | |
| 281 | + let task = cx.background_spawn(async move { | |
| 282 | 282 | let mut chunked_file_batches = |
| 283 | 283 | pin!(chunked_files.chunks_timeout(512, Duration::from_secs(2))); |
| 284 | 284 | while let Some(chunked_files) = chunked_file_batches.next().await { |
| @@ -361,7 +361,7 @@ impl EmbeddingIndex { · 76 unmodified lines | ||
| 361 | 361 | let db_connection = self.db_connection.clone(); |
| 362 | 362 | let db = self.db; |
| 363 | 363 | |
| 364 | − cx.background_executor().spawn(async move { | |
| 364 | + cx.background_spawn(async move { | |
| 365 | 365 | let mut deleted_entry_ranges = pin!(deleted_entry_ranges); |
| 366 | 366 | let mut embedded_files = pin!(embedded_files); |
| 367 | 367 | loop { |
| @@ -397,7 +397,7 @@ impl EmbeddingIndex { · 29 unmodified lines | ||
| 397 | 397 | pub fn paths(&self, cx: &App) -> Task<Result<Vec<Arc<Path>>>> { |
| 398 | 398 | let connection = self.db_connection.clone(); |
| 399 | 399 | let db = self.db; |
| 400 | − cx.background_executor().spawn(async move { | |
| 400 | + cx.background_spawn(async move { | |
| 401 | 401 | let tx = connection |
| 402 | 402 | .read_txn() |
| 403 | 403 | .context("failed to create read transaction")?; |
| @@ -413,7 +413,7 @@ impl EmbeddingIndex { · 9 unmodified lines | ||
| 413 | 413 | pub fn chunks_for_path(&self, path: Arc<Path>, cx: &App) -> Task<Result<Vec<EmbeddedChunk>>> { |
| 414 | 414 | let connection = self.db_connection.clone(); |
| 415 | 415 | let db = self.db; |
| 416 | − cx.background_executor().spawn(async move { | |
| 416 | + cx.background_spawn(async move { | |
| 417 | 417 | let tx = connection |
| 418 | 418 | .read_txn() |
| 419 | 419 | .context("failed to create read transaction")?; |
| @@ -7,7 +7,9 @@ use anyhow::{anyhow, Context as _, Result}; · 6 unmodified lines | ||
| 7 | 7 | use collections::HashMap; |
| 8 | 8 | use fs::Fs; |
| 9 | 9 | use futures::FutureExt; |
| 10 | −use gpui::{App, Context, Entity, EntityId, EventEmitter, Subscription, Task, WeakEntity}; | |
| 10 | +use gpui::{ | |
| 11 | + App, AppContext as _, Context, Entity, EntityId, EventEmitter, Subscription, Task, WeakEntity, | |
| 12 | +}; | |
| 11 | 13 | use language::LanguageRegistry; |
| 12 | 14 | use log; |
| 13 | 15 | use project::{Project, Worktree, WorktreeId}; |
| @@ -250,7 +252,7 @@ impl ProjectIndex { · 236 unmodified lines | ||
| 250 | 252 | let worktree_id = index.worktree().read(cx).id(); |
| 251 | 253 | let db_connection = index.db_connection().clone(); |
| 252 | 254 | let db = *index.embedding_index().db(); |
| 253 | − cx.background_executor().spawn(async move { | |
| 255 | + cx.background_spawn(async move { | |
| 254 | 256 | let txn = db_connection |
| 255 | 257 | .read_txn() |
| 256 | 258 | .context("failed to create read transaction")?; |
| @@ -432,7 +434,7 @@ impl ProjectIndex { · 175 unmodified lines | ||
| 432 | 434 | let file_digest_db = summary_index.file_digest_db(); |
| 433 | 435 | let summary_db = summary_index.summary_db(); |
| 434 | 436 | |
| 435 | − cx.background_executor().spawn(async move { | |
| 437 | + cx.background_spawn(async move { | |
| 436 | 438 | let txn = db_connection |
| 437 | 439 | .read_txn() |
| 438 | 440 | .context("failed to create db read transaction")?; |
| @@ -519,8 +521,9 @@ impl ProjectIndex { · 80 unmodified lines | ||
| 519 | 521 | |
| 520 | 522 | index |
| 521 | 523 | .read_with(&cx, |index, cx| { |
| 522 | − cx.background_executor() | |
| 523 | − .spawn(index.summary_index().flush_backlog(worktree_abs_path, cx)) | |
| 524 | + cx.background_spawn( | |
| 525 | + index.summary_index().flush_backlog(worktree_abs_path, cx), | |
| 526 | + ) | |
| 524 | 527 | })? |
| 525 | 528 | .await |
| 526 | 529 | }) |
| @@ -42,8 +42,7 @@ impl SemanticDb { · 41 unmodified lines | ||
| 42 | 42 | cx: &mut AsyncApp, |
| 43 | 43 | ) -> Result<Self> { |
| 44 | 44 | let db_connection = cx |
| 45 | − .background_executor() | |
| 46 | − .spawn(async move { | |
| 45 | + .background_spawn(async move { | |
| 47 | 46 | std::fs::create_dir_all(&db_path)?; |
| 48 | 47 | unsafe { |
| 49 | 48 | heed::EnvOpenOptions::new() |
| @@ -432,8 +431,7 @@ mod tests { · 382 unmodified lines | ||
| 432 | 431 | let worktree = search_result.worktree.read(cx); |
| 433 | 432 | let entry_abs_path = worktree.abs_path().join(&search_result.path); |
| 434 | 433 | let fs = project.read(cx).fs().clone(); |
| 435 | − cx.background_executor() | |
| 436 | − .spawn(async move { fs.load(&entry_abs_path).await.unwrap() }) | |
| 434 | + cx.background_spawn(async move { fs.load(&entry_abs_path).await.unwrap() }) | |
| 437 | 435 | }) |
| 438 | 436 | .await; |
| 439 | 437 | |
| @@ -3,7 +3,7 @@ use arrayvec::ArrayString; · 2 unmodified lines | ||
| 3 | 3 | use fs::{Fs, MTime}; |
| 4 | 4 | use futures::{stream::StreamExt, TryFutureExt}; |
| 5 | 5 | use futures_batch::ChunksTimeoutStreamExt; |
| 6 | −use gpui::{App, Entity, Task}; | |
| 6 | +use gpui::{App, AppContext as _, Entity, Task}; | |
| 7 | 7 | use heed::{ |
| 8 | 8 | types::{SerdeBincode, Str}, |
| 9 | 9 | RoTxn, |
| @@ -254,7 +254,7 @@ impl SummaryIndex { · 244 unmodified lines | ||
| 254 | 254 | let db_connection = self.db_connection.clone(); |
| 255 | 255 | let db = self.summary_db; |
| 256 | 256 | let (needs_summary_tx, needs_summary_rx) = channel::bounded(512); |
| 257 | − let task = cx.background_executor().spawn(async move { | |
| 257 | + let task = cx.background_spawn(async move { | |
| 258 | 258 | let mut might_need_summary = pin!(might_need_summary); |
| 259 | 259 | while let Some(file) = might_need_summary.next().await { |
| 260 | 260 | let tx = db_connection |
| @@ -291,7 +291,7 @@ impl SummaryIndex { · 30 unmodified lines | ||
| 291 | 291 | let db_connection = self.db_connection.clone(); |
| 292 | 292 | let digest_db = self.file_digest_db; |
| 293 | 293 | let backlog = Arc::clone(&self.backlog); |
| 294 | − let task = cx.background_executor().spawn(async move { | |
| 294 | + let task = cx.background_spawn(async move { | |
| 295 | 295 | let txn = db_connection |
| 296 | 296 | .read_txn() |
| 297 | 297 | .context("failed to create read transaction")?; |
| @@ -368,7 +368,7 @@ impl SummaryIndex { · 70 unmodified lines | ||
| 368 | 368 | let db_connection = self.db_connection.clone(); |
| 369 | 369 | let digest_db = self.file_digest_db; |
| 370 | 370 | let backlog = Arc::clone(&self.backlog); |
| 371 | − let task = cx.background_executor().spawn(async move { | |
| 371 | + let task = cx.background_spawn(async move { | |
| 372 | 372 | let txn = db_connection |
| 373 | 373 | .read_txn() |
| 374 | 374 | .context("failed to create read transaction")?; |
| @@ -538,7 +538,7 @@ impl SummaryIndex { · 163 unmodified lines | ||
| 538 | 538 | .available_models(cx) |
| 539 | 539 | .find(|model| &model.id() == &summary_model_id) |
| 540 | 540 | else { |
| 541 | − return cx.background_executor().spawn(async move { | |
| 541 | + return cx.background_spawn(async move { | |
| 542 | 542 | Err(anyhow!("Couldn't find the preferred summarization model ({:?}) in the language registry's available models", summary_model_id)) |
| 543 | 543 | }); |
| 544 | 544 | }; |
| @@ -566,31 +566,30 @@ impl SummaryIndex { · 21 unmodified lines | ||
| 566 | 566 | let code_len = code.len(); |
| 567 | 567 | cx.spawn(|cx| async move { |
| 568 | 568 | let stream = model.stream_completion(request, &cx); |
| 569 | − cx.background_executor() | |
| 570 | − .spawn(async move { | |
| 571 | − let answer: String = stream | |
| 572 | − .await? | |
| 573 | − .filter_map(|event| async { | |
| 574 | − if let Ok(LanguageModelCompletionEvent::Text(text)) = event { | |
| 575 | − Some(text) | |
| 576 | − } else { | |
| 577 | − None | |
| 578 | − } | |
| 579 | − }) | |
| 580 | − .collect() | |
| 581 | − .await; | |
| 569 | + cx.background_spawn(async move { | |
| 570 | + let answer: String = stream | |
| 571 | + .await? | |
| 572 | + .filter_map(|event| async { | |
| 573 | + if let Ok(LanguageModelCompletionEvent::Text(text)) = event { | |
| 574 | + Some(text) | |
| 575 | + } else { | |
| 576 | + None | |
| 577 | + } | |
| 578 | + }) | |
| 579 | + .collect() | |
| 580 | + .await; | |
| 582 | 581 | |
| 583 | − log::info!( | |
| 584 | − "It took {:?} to summarize {:?} bytes of code.", | |
| 585 | − start.elapsed(), | |
| 586 | − code_len | |
| 587 | − ); | |
| 582 | + log::info!( | |
| 583 | + "It took {:?} to summarize {:?} bytes of code.", | |
| 584 | + start.elapsed(), | |
| 585 | + code_len | |
| 586 | + ); | |
| 588 | 587 | |
| 589 | − log::debug!("Summary was: {:?}", &answer); | |
| 588 | + log::debug!("Summary was: {:?}", &answer); | |
| 590 | 589 | |
| 591 | − Ok(answer) | |
| 592 | − }) | |
| 593 | − .await | |
| 590 | + Ok(answer) | |
| 591 | + }) | |
| 592 | + .await | |
| 594 | 593 | |
| 595 | 594 | // TODO if summarization failed, put it back in the backlog! |
| 596 | 595 | }) |
| @@ -604,7 +603,7 @@ impl SummaryIndex { · 7 unmodified lines | ||
| 604 | 603 | let db_connection = self.db_connection.clone(); |
| 605 | 604 | let digest_db = self.file_digest_db; |
| 606 | 605 | let summary_db = self.summary_db; |
| 607 | − cx.background_executor().spawn(async move { | |
| 606 | + cx.background_spawn(async move { | |
| 608 | 607 | let mut summaries = pin!(summaries.chunks_timeout(4096, Duration::from_secs(2))); |
| 609 | 608 | while let Some(summaries) = summaries.next().await { |
| 610 | 609 | let mut txn = db_connection.write_txn()?; |
| @@ -650,7 +649,7 @@ impl SummaryIndex { · 39 unmodified lines | ||
| 650 | 649 | backlog.drain().collect() |
| 651 | 650 | }; |
| 652 | 651 | |
| 653 | − let task = cx.background_executor().spawn(async move { | |
| 652 | + let task = cx.background_spawn(async move { | |
| 654 | 653 | tx.send(needs_summary).await?; |
| 655 | 654 | Ok(()) |
| 656 | 655 | }); |
| @@ -52,8 +52,7 @@ impl WorktreeIndex { · 51 unmodified lines | ||
| 52 | 52 | cx.spawn(|mut cx| async move { |
| 53 | 53 | let entries_being_indexed = Arc::new(IndexingEntrySet::new(status_tx)); |
| 54 | 54 | let (embedding_index, summary_index) = cx |
| 55 | − .background_executor() | |
| 56 | − .spawn({ | |
| 55 | + .background_spawn({ | |
| 57 | 56 | let entries_being_indexed = Arc::clone(&entries_being_indexed); |
| 58 | 57 | let db_connection = db_connection.clone(); |
| 59 | 58 | async move { |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use std::time::Duration; |
| 2 | 2 | |
| 3 | 3 | use db::kvp::KEY_VALUE_STORE; |
| 4 | −use gpui::{AnyWindowHandle, Context, Subscription, Task, WindowId}; | |
| 4 | +use gpui::{AnyWindowHandle, AppContext as _, Context, Subscription, Task, WindowId}; | |
| 5 | 5 | use util::ResultExt; |
| 6 | 6 | use uuid::Uuid; |
| 7 | 7 | |
| @@ -88,7 +88,7 @@ impl AppSession { · 80 unmodified lines | ||
| 88 | 88 | |
| 89 | 89 | fn app_will_quit(&mut self, cx: &mut Context<Self>) -> Task<()> { |
| 90 | 90 | if let Some(windows) = cx.window_stack() { |
| 91 | − cx.background_executor().spawn(store_window_stack(windows)) | |
| 91 | + cx.background_spawn(store_window_stack(windows)) | |
| 92 | 92 | } else { |
| 93 | 93 | Task::ready(()) |
| 94 | 94 | } |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | use std::sync::Arc; |
| 4 | 4 | |
| 5 | 5 | use futures::{channel::mpsc::UnboundedSender, StreamExt}; |
| 6 | −use gpui::App; | |
| 6 | +use gpui::{App, AppContext}; | |
| 7 | 7 | use parking_lot::RwLock; |
| 8 | 8 | use serde::Deserialize; |
| 9 | 9 | use util::ResultExt; |
| @@ -33,35 +33,34 @@ impl<T: PartialEq + 'static + Sync> TrackedFile<T> { · 23 unmodified lines | ||
| 33 | 33 | T: for<'a> Deserialize<'a> + Default + Send, |
| 34 | 34 | { |
| 35 | 35 | let parsed_contents: Arc<RwLock<T>> = Arc::default(); |
| 36 | − cx.background_executor() | |
| 37 | − .spawn({ | |
| 38 | − let parsed_contents = parsed_contents.clone(); | |
| 39 | − async move { | |
| 40 | − while let Some(new_contents) = tracker.next().await { | |
| 41 | − if Arc::strong_count(&parsed_contents) == 1 { | |
| 42 | − // We're no longer being observed. Stop polling. | |
| 43 | − break; | |
| 44 | − } | |
| 45 | − if !new_contents.trim().is_empty() { | |
| 46 | − let Some(new_contents) = | |
| 47 | − serde_json_lenient::from_str::<T>(&new_contents).log_err() | |
| 48 | − else { | |
| 49 | − continue; | |
| 50 | − }; | |
| 51 | − let mut contents = parsed_contents.write(); | |
| 52 | − if *contents != new_contents { | |
| 53 | − *contents = new_contents; | |
| 54 | − if notification_outlet.unbounded_send(()).is_err() { | |
| 55 | − // Whoever cared about contents is not around anymore. | |
| 56 | − break; | |
| 57 | − } | |
| 36 | + cx.background_spawn({ | |
| 37 | + let parsed_contents = parsed_contents.clone(); | |
| 38 | + async move { | |
| 39 | + while let Some(new_contents) = tracker.next().await { | |
| 40 | + if Arc::strong_count(&parsed_contents) == 1 { | |
| 41 | + // We're no longer being observed. Stop polling. | |
| 42 | + break; | |
| 43 | + } | |
| 44 | + if !new_contents.trim().is_empty() { | |
| 45 | + let Some(new_contents) = | |
| 46 | + serde_json_lenient::from_str::<T>(&new_contents).log_err() | |
| 47 | + else { | |
| 48 | + continue; | |
| 49 | + }; | |
| 50 | + let mut contents = parsed_contents.write(); | |
| 51 | + if *contents != new_contents { | |
| 52 | + *contents = new_contents; | |
| 53 | + if notification_outlet.unbounded_send(()).is_err() { | |
| 54 | + // Whoever cared about contents is not around anymore. | |
| 55 | + break; | |
| 58 | 56 | } |
| 59 | 57 | } |
| 60 | 58 | } |
| 61 | − anyhow::Ok(()) | |
| 62 | 59 | } |
| 63 | − }) | |
| 64 | − .detach_and_log_err(cx); | |
| 60 | + anyhow::Ok(()) | |
| 61 | + } | |
| 62 | + }) | |
| 63 | + .detach_and_log_err(cx); | |
| 65 | 64 | Self { parsed_contents } |
| 66 | 65 | } |
| 67 | 66 | |
| @@ -75,39 +74,38 @@ impl<T: PartialEq + 'static + Sync> TrackedFile<T> { · 7 unmodified lines | ||
| 75 | 74 | T: Default + Send, |
| 76 | 75 | { |
| 77 | 76 | let parsed_contents: Arc<RwLock<T>> = Arc::default(); |
| 78 | − cx.background_executor() | |
| 79 | − .spawn({ | |
| 80 | − let parsed_contents = parsed_contents.clone(); | |
| 81 | − async move { | |
| 82 | − while let Some(new_contents) = tracker.next().await { | |
| 83 | − if Arc::strong_count(&parsed_contents) == 1 { | |
| 84 | − // We're no longer being observed. Stop polling. | |
| 85 | − break; | |
| 86 | − } | |
| 77 | + cx.background_spawn({ | |
| 78 | + let parsed_contents = parsed_contents.clone(); | |
| 79 | + async move { | |
| 80 | + while let Some(new_contents) = tracker.next().await { | |
| 81 | + if Arc::strong_count(&parsed_contents) == 1 { | |
| 82 | + // We're no longer being observed. Stop polling. | |
| 83 | + break; | |
| 84 | + } | |
| 87 | 85 | |
| 88 | − if !new_contents.trim().is_empty() { | |
| 89 | − let Some(new_contents) = | |
| 90 | − serde_json_lenient::from_str::<U>(&new_contents).log_err() | |
| 91 | − else { | |
| 92 | − continue; | |
| 93 | − }; | |
| 94 | − let Some(new_contents) = new_contents.try_into().log_err() else { | |
| 95 | − continue; | |
| 96 | − }; | |
| 97 | − let mut contents = parsed_contents.write(); | |
| 98 | − if *contents != new_contents { | |
| 99 | − *contents = new_contents; | |
| 100 | − if notification_outlet.unbounded_send(()).is_err() { | |
| 101 | − // Whoever cared about contents is not around anymore. | |
| 102 | − break; | |
| 103 | − } | |
| 86 | + if !new_contents.trim().is_empty() { | |
| 87 | + let Some(new_contents) = | |
| 88 | + serde_json_lenient::from_str::<U>(&new_contents).log_err() | |
| 89 | + else { | |
| 90 | + continue; | |
| 91 | + }; | |
| 92 | + let Some(new_contents) = new_contents.try_into().log_err() else { | |
| 93 | + continue; | |
| 94 | + }; | |
| 95 | + let mut contents = parsed_contents.write(); | |
| 96 | + if *contents != new_contents { | |
| 97 | + *contents = new_contents; | |
| 98 | + if notification_outlet.unbounded_send(()).is_err() { | |
| 99 | + // Whoever cared about contents is not around anymore. | |
| 100 | + break; | |
| 104 | 101 | } |
| 105 | 102 | } |
| 106 | 103 | } |
| 107 | − anyhow::Ok(()) | |
| 108 | 104 | } |
| 109 | − }) | |
| 110 | − .detach_and_log_err(cx); | |
| 105 | + anyhow::Ok(()) | |
| 106 | + } | |
| 107 | + }) | |
| 108 | + .detach_and_log_err(cx); | |
| 111 | 109 | Self { |
| 112 | 110 | parsed_contents: Default::default(), |
| 113 | 111 | } |
| @@ -58,9 +58,9 @@ use std::{ · 57 unmodified lines | ||
| 58 | 58 | use thiserror::Error; |
| 59 | 59 | |
| 60 | 60 | use gpui::{ |
| 61 | − actions, black, px, AnyWindowHandle, App, Bounds, ClipboardItem, Context, EventEmitter, Hsla, | |
| 62 | − Keystroke, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels, Point, | |
| 63 | − Rgba, ScrollWheelEvent, SharedString, Size, Task, TouchPhase, | |
| 61 | + actions, black, px, AnyWindowHandle, App, AppContext as _, Bounds, ClipboardItem, Context, | |
| 62 | + EventEmitter, Hsla, Keystroke, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, | |
| 63 | + MouseUpEvent, Pixels, Point, Rgba, ScrollWheelEvent, SharedString, Size, Task, TouchPhase, | |
| 64 | 64 | }; |
| 65 | 65 | |
| 66 | 66 | use crate::mappings::{colors::to_alac_rgb, keys::to_esc_str}; |
| @@ -1633,7 +1633,7 @@ impl Terminal { · 1566 unmodified lines | ||
| 1633 | 1633 | cx: &Context<Self>, |
| 1634 | 1634 | ) -> Task<Vec<RangeInclusive<AlacPoint>>> { |
| 1635 | 1635 | let term = self.term.clone(); |
| 1636 | − cx.background_executor().spawn(async move { | |
| 1636 | + cx.background_spawn(async move { | |
| 1637 | 1637 | let term = term.lock(); |
| 1638 | 1638 | |
| 1639 | 1639 | all_search_matches(&term, &mut searcher).collect() |
| @@ -222,8 +222,7 @@ impl TerminalPanel { · 221 unmodified lines | ||
| 222 | 222 | mut cx: AsyncWindowContext, |
| 223 | 223 | ) -> Result<Entity<Self>> { |
| 224 | 224 | let serialized_panel = cx |
| 225 | − .background_executor() | |
| 226 | − .spawn(async move { KEY_VALUE_STORE.read_kvp(TERMINAL_PANEL_KEY) }) | |
| 225 | + .background_spawn(async move { KEY_VALUE_STORE.read_kvp(TERMINAL_PANEL_KEY) }) | |
| 227 | 226 | .await |
| 228 | 227 | .log_err() |
| 229 | 228 | .flatten() |
| @@ -742,25 +741,24 @@ impl TerminalPanel { · 512 unmodified lines | ||
| 742 | 741 | )) |
| 743 | 742 | }) |
| 744 | 743 | .ok()?; |
| 745 | − cx.background_executor() | |
| 746 | − .spawn( | |
| 747 | − async move { | |
| 748 | − KEY_VALUE_STORE | |
| 749 | − .write_kvp( | |
| 750 | − TERMINAL_PANEL_KEY.into(), | |
| 751 | − serde_json::to_string(&SerializedTerminalPanel { | |
| 752 | − items, | |
| 753 | − active_item_id: None, | |
| 754 | − height, | |
| 755 | − width, | |
| 756 | − })?, | |
| 757 | − ) | |
| 758 | − .await?; | |
| 759 | − anyhow::Ok(()) | |
| 760 | − } | |
| 761 | − .log_err(), | |
| 762 | − ) | |
| 763 | − .await; | |
| 744 | + cx.background_spawn( | |
| 745 | + async move { | |
| 746 | + KEY_VALUE_STORE | |
| 747 | + .write_kvp( | |
| 748 | + TERMINAL_PANEL_KEY.into(), | |
| 749 | + serde_json::to_string(&SerializedTerminalPanel { | |
| 750 | + items, | |
| 751 | + active_item_id: None, | |
| 752 | + height, | |
| 753 | + width, | |
| 754 | + })?, | |
| 755 | + ) | |
| 756 | + .await?; | |
| 757 | + anyhow::Ok(()) | |
| 758 | + } | |
| 759 | + .log_err(), | |
| 760 | + ) | |
| 761 | + .await; | |
| 764 | 762 | Some(()) |
| 765 | 763 | }); |
| 766 | 764 | } |
| @@ -976,7 +976,7 @@ fn possible_open_paths_metadata( · 975 unmodified lines | ||
| 976 | 976 | potential_paths: HashSet<PathBuf>, |
| 977 | 977 | cx: &mut Context<TerminalView>, |
| 978 | 978 | ) -> Task<Vec<(PathWithPosition, Metadata)>> { |
| 979 | − cx.background_executor().spawn(async move { | |
| 979 | + cx.background_spawn(async move { | |
| 980 | 980 | let mut canonical_paths = HashSet::default(); |
| 981 | 981 | for path in potential_paths { |
| 982 | 982 | if let Ok(canonical) = fs.canonicalize(&path).await { |
| @@ -1378,9 +1378,12 @@ impl Item for TerminalView { · 395 unmodified lines | ||
| 1378 | 1378 | ) { |
| 1379 | 1379 | if self.terminal().read(cx).task().is_none() { |
| 1380 | 1380 | if let Some((new_id, old_id)) = workspace.database_id().zip(self.workspace_id) { |
| 1381 | − cx.background_executor() | |
| 1382 | − .spawn(TERMINAL_DB.update_workspace_id(new_id, old_id, cx.entity_id().as_u64())) | |
| 1383 | − .detach(); | |
| 1381 | + cx.background_spawn(TERMINAL_DB.update_workspace_id( | |
| 1382 | + new_id, | |
| 1383 | + old_id, | |
| 1384 | + cx.entity_id().as_u64(), | |
| 1385 | + )) | |
| 1386 | + .detach(); | |
| 1384 | 1387 | } |
| 1385 | 1388 | self.workspace_id = workspace.database_id(); |
| 1386 | 1389 | } |
| @@ -1421,7 +1424,7 @@ impl SerializableItem for TerminalView { · 34 unmodified lines | ||
| 1421 | 1424 | } |
| 1422 | 1425 | |
| 1423 | 1426 | if let Some((cwd, workspace_id)) = terminal.working_directory().zip(self.workspace_id) { |
| 1424 | − Some(cx.background_executor().spawn(async move { | |
| 1427 | + Some(cx.background_spawn(async move { | |
| 1425 | 1428 | TERMINAL_DB |
| 1426 | 1429 | .save_working_directory(item_id, workspace_id, cwd) |
| 1427 | 1430 | .await |
| @@ -7,7 +7,7 @@ use editor::{ · 6 unmodified lines | ||
| 7 | 7 | scroll::Autoscroll, |
| 8 | 8 | Bias, Editor, ToPoint, |
| 9 | 9 | }; |
| 10 | −use gpui::{actions, impl_internal_actions, Action, App, Context, Global, Window}; | |
| 10 | +use gpui::{actions, impl_internal_actions, Action, App, AppContext as _, Context, Global, Window}; | |
| 11 | 11 | use itertools::Itertools; |
| 12 | 12 | use language::Point; |
| 13 | 13 | use multi_buffer::MultiBufferRow; |
| @@ -1185,8 +1185,7 @@ impl OnMatchingLines { · 1171 unmodified lines | ||
| 1185 | 1185 | .clip_point(Point::new(range.end.0 + 1, 0), Bias::Left); |
| 1186 | 1186 | cx.spawn_in(window, |editor, mut cx| async move { |
| 1187 | 1187 | let new_selections = cx |
| 1188 | − .background_executor() | |
| 1189 | − .spawn(async move { | |
| 1188 | + .background_spawn(async move { | |
| 1190 | 1189 | let mut line = String::new(); |
| 1191 | 1190 | let mut new_selections = Vec::new(); |
| 1192 | 1191 | let chunks = snapshot |
| @@ -1513,22 +1512,20 @@ impl ShellExec { · 320 unmodified lines | ||
| 1513 | 1512 | if let Some(mut stdin) = running.stdin.take() { |
| 1514 | 1513 | if let Some(snapshot) = input_snapshot { |
| 1515 | 1514 | let range = range.clone(); |
| 1516 | − cx.background_executor() | |
| 1517 | − .spawn(async move { | |
| 1518 | − for chunk in snapshot.text_for_range(range) { | |
| 1519 | − if stdin.write_all(chunk.as_bytes()).log_err().is_none() { | |
| 1520 | − return; | |
| 1521 | − } | |
| 1515 | + cx.background_spawn(async move { | |
| 1516 | + for chunk in snapshot.text_for_range(range) { | |
| 1517 | + if stdin.write_all(chunk.as_bytes()).log_err().is_none() { | |
| 1518 | + return; | |
| 1522 | 1519 | } |
| 1523 | − stdin.flush().log_err(); | |
| 1524 | − }) | |
| 1525 | − .detach(); | |
| 1520 | + } | |
| 1521 | + stdin.flush().log_err(); | |
| 1522 | + }) | |
| 1523 | + .detach(); | |
| 1526 | 1524 | } |
| 1527 | 1525 | }; |
| 1528 | 1526 | |
| 1529 | 1527 | let output = cx |
| 1530 | − .background_executor() | |
| 1531 | − .spawn(async move { running.wait_with_output() }) | |
| 1528 | + .background_spawn(async move { running.wait_with_output() }) | |
| 1532 | 1529 | .await; |
| 1533 | 1530 | |
| 1534 | 1531 | let Some(output) = output.log_err() else { |
| @@ -5,7 +5,7 @@ use crate::{ · 4 unmodified lines | ||
| 5 | 5 | use call::{RemoteVideoTrack, RemoteVideoTrackView}; |
| 6 | 6 | use client::{proto::PeerId, User}; |
| 7 | 7 | use gpui::{ |
| 8 | − div, AppContext, Entity, EventEmitter, FocusHandle, Focusable, InteractiveElement, | |
| 8 | + div, AppContext as _, Entity, EventEmitter, FocusHandle, Focusable, InteractiveElement, | |
| 9 | 9 | ParentElement, Render, SharedString, Styled, |
| 10 | 10 | }; |
| 11 | 11 | use std::sync::Arc; |
| @@ -4337,8 +4337,7 @@ impl Workspace { · 4336 unmodified lines | ||
| 4337 | 4337 | self.update_active_view_for_followers(window, cx); |
| 4338 | 4338 | |
| 4339 | 4339 | if let Some(database_id) = self.database_id { |
| 4340 | − cx.background_executor() | |
| 4341 | − .spawn(persistence::DB.update_timestamp(database_id)) | |
| 4340 | + cx.background_spawn(persistence::DB.update_timestamp(database_id)) | |
| 4342 | 4341 | .detach(); |
| 4343 | 4342 | } |
| 4344 | 4343 | } else { |
| @@ -4626,8 +4625,7 @@ impl Workspace { · 281 unmodified lines | ||
| 4626 | 4625 | if let Ok(Some(task)) = this.update_in(cx, |workspace, window, cx| { |
| 4627 | 4626 | item.serialize(workspace, false, window, cx) |
| 4628 | 4627 | }) { |
| 4629 | − cx.background_executor() | |
| 4630 | − .spawn(async move { task.await.log_err() }) | |
| 4628 | + cx.background_spawn(async move { task.await.log_err() }) | |
| 4631 | 4629 | .detach(); |
| 4632 | 4630 | } |
| 4633 | 4631 | } |
| @@ -4965,8 +4963,7 @@ impl Workspace { · 331 unmodified lines | ||
| 4965 | 4963 | ) { |
| 4966 | 4964 | self.centered_layout = !self.centered_layout; |
| 4967 | 4965 | if let Some(database_id) = self.database_id() { |
| 4968 | − cx.background_executor() | |
| 4969 | − .spawn(DB.set_centered_layout(database_id, self.centered_layout)) | |
| 4966 | + cx.background_spawn(DB.set_centered_layout(database_id, self.centered_layout)) | |
| 4970 | 4967 | .detach_and_log_err(cx); |
| 4971 | 4968 | } |
| 4972 | 4969 | cx.notify(); |
| @@ -6223,7 +6220,7 @@ fn serialize_ssh_project( · 1250 unmodified lines | ||
| 6223 | 6220 | Option<SerializedWorkspace>, |
| 6224 | 6221 | )>, |
| 6225 | 6222 | > { |
| 6226 | − cx.background_executor().spawn(async move { | |
| 6223 | + cx.background_spawn(async move { | |
| 6227 | 6224 | let serialized_ssh_project = persistence::DB |
| 6228 | 6225 | .get_or_create_ssh_project( |
| 6229 | 6226 | connection_options.host.clone(), |
| @@ -791,23 +791,22 @@ impl Worktree { · 790 unmodified lines | ||
| 791 | 791 | |
| 792 | 792 | // Apply updates to a separate snapshot in a background task, then |
| 793 | 793 | // send them to a foreground task which updates the model. |
| 794 | − cx.background_executor() | |
| 795 | − .spawn(async move { | |
| 796 | − while let Some(update) = background_updates_rx.next().await { | |
| 794 | + cx.background_spawn(async move { | |
| 795 | + while let Some(update) = background_updates_rx.next().await { | |
| 796 | + { | |
| 797 | + let mut lock = background_snapshot.lock(); | |
| 798 | + if let Err(error) = lock | |
| 799 | + .0 | |
| 800 | + .apply_remote_update(update.clone(), &settings.file_scan_inclusions) | |
| 797 | 801 | { |
| 798 | − let mut lock = background_snapshot.lock(); | |
| 799 | − if let Err(error) = lock | |
| 800 | − .0 | |
| 801 | − .apply_remote_update(update.clone(), &settings.file_scan_inclusions) | |
| 802 | − { | |
| 803 | − log::error!("error applying worktree update: {}", error); | |
| 804 | − } | |
| 805 | − lock.1.push(update); | |
| 802 | + log::error!("error applying worktree update: {}", error); | |
| 806 | 803 | } |
| 807 | − snapshot_updated_tx.send(()).await.ok(); | |
| 804 | + lock.1.push(update); | |
| 808 | 805 | } |
| 809 | − }) | |
| 810 | − .detach(); | |
| 806 | + snapshot_updated_tx.send(()).await.ok(); | |
| 807 | + } | |
| 808 | + }) | |
| 809 | + .detach(); | |
| 811 | 810 | |
| 812 | 811 | // On the foreground task, update to the latest snapshot and notify |
| 813 | 812 | // any update observer of all updates that led to that snapshot. |
| @@ -991,7 +990,7 @@ impl Worktree { · 177 unmodified lines | ||
| 991 | 990 | Worktree::Local(this) => { |
| 992 | 991 | let path = Arc::from(path); |
| 993 | 992 | let snapshot = this.snapshot(); |
| 994 | − cx.background_executor().spawn(async move { | |
| 993 | + cx.background_spawn(async move { | |
| 995 | 994 | if let Some(repo) = snapshot.repository_for_path(&path) { |
| 996 | 995 | if let Some(repo_path) = repo.relativize(&path).log_err() { |
| 997 | 996 | if let Some(git_repo) = |
| @@ -1015,7 +1014,7 @@ impl Worktree { · 17 unmodified lines | ||
| 1015 | 1014 | Worktree::Local(this) => { |
| 1016 | 1015 | let path = Arc::from(path); |
| 1017 | 1016 | let snapshot = this.snapshot(); |
| 1018 | − cx.background_executor().spawn(async move { | |
| 1017 | + cx.background_spawn(async move { | |
| 1019 | 1018 | if let Some(repo) = snapshot.repository_for_path(&path) { |
| 1020 | 1019 | if let Some(repo_path) = repo.relativize(&path).log_err() { |
| 1021 | 1020 | if let Some(git_repo) = |
| @@ -1431,7 +1430,7 @@ impl LocalWorktree { · 409 unmodified lines | ||
| 1431 | 1430 | let git_hosting_provider_registry = GitHostingProviderRegistry::try_global(cx); |
| 1432 | 1431 | let settings = self.settings.clone(); |
| 1433 | 1432 | let (scan_states_tx, mut scan_states_rx) = mpsc::unbounded(); |
| 1434 | − let background_scanner = cx.background_executor().spawn({ | |
| 1433 | + let background_scanner = cx.background_spawn({ | |
| 1435 | 1434 | let abs_path = snapshot.abs_path.as_path().to_path_buf(); |
| 1436 | 1435 | let background = cx.background_executor().clone(); |
| 1437 | 1436 | async move { |
| @@ -1668,7 +1667,7 @@ impl LocalWorktree { · 230 unmodified lines | ||
| 1668 | 1667 | let is_private = self.is_path_private(path.as_ref()); |
| 1669 | 1668 | |
| 1670 | 1669 | let worktree = cx.weak_entity(); |
| 1671 | − cx.background_executor().spawn(async move { | |
| 1670 | + cx.background_spawn(async move { | |
| 1672 | 1671 | let abs_path = abs_path?; |
| 1673 | 1672 | let content = fs.load_bytes(&abs_path).await?; |
| 1674 | 1673 | |
| @@ -1774,7 +1773,7 @@ impl LocalWorktree { · 99 unmodified lines | ||
| 1774 | 1773 | let path_excluded = self.settings.is_path_excluded(&abs_path); |
| 1775 | 1774 | let fs = self.fs.clone(); |
| 1776 | 1775 | let task_abs_path = abs_path.clone(); |
| 1777 | − let write = cx.background_executor().spawn(async move { | |
| 1776 | + let write = cx.background_spawn(async move { | |
| 1778 | 1777 | if is_dir { |
| 1779 | 1778 | fs.create_dir(&task_abs_path) |
| 1780 | 1779 | .await |
| @@ -1838,7 +1837,7 @@ impl LocalWorktree { · 57 unmodified lines | ||
| 1838 | 1837 | return Task::ready(Err(anyhow!("invalid path {path:?}"))); |
| 1839 | 1838 | }; |
| 1840 | 1839 | |
| 1841 | − let write = cx.background_executor().spawn({ | |
| 1840 | + let write = cx.background_spawn({ | |
| 1842 | 1841 | let fs = fs.clone(); |
| 1843 | 1842 | let abs_path = abs_path.clone(); |
| 1844 | 1843 | async move { fs.save(&abs_path, &text, line_ending).await } |
| @@ -1890,7 +1889,7 @@ impl LocalWorktree { · 45 unmodified lines | ||
| 1890 | 1889 | let abs_path = self.absolutize(&entry.path); |
| 1891 | 1890 | let fs = self.fs.clone(); |
| 1892 | 1891 | |
| 1893 | − let delete = cx.background_executor().spawn(async move { | |
| 1892 | + let delete = cx.background_spawn(async move { | |
| 1894 | 1893 | if entry.is_file() { |
| 1895 | 1894 | if trash { |
| 1896 | 1895 | fs.trash_file(&abs_path?, Default::default()).await?; |
| @@ -1964,7 +1963,7 @@ impl LocalWorktree { · 67 unmodified lines | ||
| 1964 | 1963 | let abs_path = abs_new_path.clone(); |
| 1965 | 1964 | let fs = self.fs.clone(); |
| 1966 | 1965 | let case_sensitive = self.fs_case_sensitive; |
| 1967 | − let rename = cx.background_executor().spawn(async move { | |
| 1966 | + let rename = cx.background_spawn(async move { | |
| 1968 | 1967 | let abs_old_path = abs_old_path?; |
| 1969 | 1968 | let abs_new_path = abs_new_path; |
| 1970 | 1969 | |
| @@ -2033,7 +2032,7 @@ impl LocalWorktree { · 62 unmodified lines | ||
| 2033 | 2032 | }; |
| 2034 | 2033 | let abs_new_path = self.absolutize(&new_path); |
| 2035 | 2034 | let fs = self.fs.clone(); |
| 2036 | − let copy = cx.background_executor().spawn(async move { | |
| 2035 | + let copy = cx.background_spawn(async move { | |
| 2037 | 2036 | copy_recursive( |
| 2038 | 2037 | fs.as_ref(), |
| 2039 | 2038 | &abs_old_path?, |
| @@ -2085,27 +2084,26 @@ impl LocalWorktree { · 45 unmodified lines | ||
| 2085 | 2084 | .collect::<Vec<_>>(); |
| 2086 | 2085 | |
| 2087 | 2086 | cx.spawn(|this, cx| async move { |
| 2088 | − cx.background_executor() | |
| 2089 | − .spawn(async move { | |
| 2090 | − for (source, target) in paths { | |
| 2091 | − copy_recursive( | |
| 2092 | − fs.as_ref(), | |
| 2093 | − &source, | |
| 2094 | − &target, | |
| 2095 | − fs::CopyOptions { | |
| 2096 | − overwrite: overwrite_existing_files, | |
| 2097 | − ..Default::default() | |
| 2098 | − }, | |
| 2099 | − ) | |
| 2100 | − .await | |
| 2101 | − .with_context(|| { | |
| 2102 | − anyhow!("Failed to copy file from {source:?} to {target:?}") | |
| 2103 | − })?; | |
| 2104 | − } | |
| 2105 | − Ok::<(), anyhow::Error>(()) | |
| 2106 | − }) | |
| 2107 | − .await | |
| 2108 | − .log_err(); | |
| 2087 | + cx.background_spawn(async move { | |
| 2088 | + for (source, target) in paths { | |
| 2089 | + copy_recursive( | |
| 2090 | + fs.as_ref(), | |
| 2091 | + &source, | |
| 2092 | + &target, | |
| 2093 | + fs::CopyOptions { | |
| 2094 | + overwrite: overwrite_existing_files, | |
| 2095 | + ..Default::default() | |
| 2096 | + }, | |
| 2097 | + ) | |
| 2098 | + .await | |
| 2099 | + .with_context(|| { | |
| 2100 | + anyhow!("Failed to copy file from {source:?} to {target:?}") | |
| 2101 | + })?; | |
| 2102 | + } | |
| 2103 | + Ok::<(), anyhow::Error>(()) | |
| 2104 | + }) | |
| 2105 | + .await | |
| 2106 | + .log_err(); | |
| 2109 | 2107 | let mut refresh = cx.read_entity( |
| 2110 | 2108 | &this.upgrade().with_context(|| "Dropped worktree")?, |
| 2111 | 2109 | |this, _| { |
| @@ -2117,13 +2115,12 @@ impl LocalWorktree { · 5 unmodified lines | ||
| 2117 | 2115 | }, |
| 2118 | 2116 | )??; |
| 2119 | 2117 | |
| 2120 | − cx.background_executor() | |
| 2121 | − .spawn(async move { | |
| 2122 | − refresh.next().await; | |
| 2123 | − Ok::<(), anyhow::Error>(()) | |
| 2124 | − }) | |
| 2125 | − .await | |
| 2126 | − .log_err(); | |
| 2118 | + cx.background_spawn(async move { | |
| 2119 | + refresh.next().await; | |
| 2120 | + Ok::<(), anyhow::Error>(()) | |
| 2121 | + }) | |
| 2122 | + .await | |
| 2123 | + .log_err(); | |
| 2127 | 2124 | |
| 2128 | 2125 | let this = this.upgrade().with_context(|| "Dropped worktree")?; |
| 2129 | 2126 | cx.read_entity(&this, |this, _| { |
| @@ -2142,7 +2139,7 @@ impl LocalWorktree { · 12 unmodified lines | ||
| 2142 | 2139 | ) -> Option<Task<Result<()>>> { |
| 2143 | 2140 | let path = self.entry_for_id(entry_id)?.path.clone(); |
| 2144 | 2141 | let mut refresh = self.refresh_entries_for_paths(vec![path]); |
| 2145 | − Some(cx.background_executor().spawn(async move { | |
| 2142 | + Some(cx.background_spawn(async move { | |
| 2146 | 2143 | refresh.next().await; |
| 2147 | 2144 | Ok(()) |
| 2148 | 2145 | })) |
| @@ -2155,7 +2152,7 @@ impl LocalWorktree { · 6 unmodified lines | ||
| 2155 | 2152 | ) -> Option<Task<Result<()>>> { |
| 2156 | 2153 | let path = self.entry_for_id(entry_id).unwrap().path.clone(); |
| 2157 | 2154 | let mut rx = self.add_path_prefix_to_scan(path.clone()); |
| 2158 | − Some(cx.background_executor().spawn(async move { | |
| 2155 | + Some(cx.background_spawn(async move { | |
| 2159 | 2156 | rx.next().await; |
| 2160 | 2157 | Ok(()) |
| 2161 | 2158 | })) |
| @@ -2229,7 +2226,7 @@ impl LocalWorktree { · 67 unmodified lines | ||
| 2229 | 2226 | .ok(); |
| 2230 | 2227 | |
| 2231 | 2228 | let worktree_id = cx.entity_id().as_u64(); |
| 2232 | − let _maintain_remote_snapshot = cx.background_executor().spawn(async move { | |
| 2229 | + let _maintain_remote_snapshot = cx.background_spawn(async move { | |
| 2233 | 2230 | let mut is_first = true; |
| 2234 | 2231 | while let Some((snapshot, entry_changes, repo_changes)) = snapshots_rx.next().await { |
| 2235 | 2232 | let update = if is_first { |
| @@ -3719,16 +3716,14 @@ impl language::LocalFile for File { · 1483 unmodified lines | ||
| 3719 | 3716 | let worktree = self.worktree.read(cx).as_local().unwrap(); |
| 3720 | 3717 | let abs_path = worktree.absolutize(&self.path); |
| 3721 | 3718 | let fs = worktree.fs.clone(); |
| 3722 | − cx.background_executor() | |
| 3723 | − .spawn(async move { fs.load(&abs_path?).await }) | |
| 3719 | + cx.background_spawn(async move { fs.load(&abs_path?).await }) | |
| 3724 | 3720 | } |
| 3725 | 3721 | |
| 3726 | 3722 | fn load_bytes(&self, cx: &App) -> Task<Result<Vec<u8>>> { |
| 3727 | 3723 | let worktree = self.worktree.read(cx).as_local().unwrap(); |
| 3728 | 3724 | let abs_path = worktree.absolutize(&self.path); |
| 3729 | 3725 | let fs = worktree.fs.clone(); |
| 3730 | − cx.background_executor() | |
| 3731 | − .spawn(async move { fs.load_bytes(&abs_path?).await }) | |
| 3726 | + cx.background_spawn(async move { fs.load_bytes(&abs_path?).await }) | |
| 3732 | 3727 | } |
| 3733 | 3728 | } |
| 3734 | 3729 | |
| @@ -11,7 +11,7 @@ use git::{ · 10 unmodified lines | ||
| 11 | 11 | }, |
| 12 | 12 | GITIGNORE, |
| 13 | 13 | }; |
| 14 | −use gpui::{BorrowAppContext, Context, Task, TestAppContext}; | |
| 14 | +use gpui::{AppContext as _, BorrowAppContext, Context, Task, TestAppContext}; | |
| 15 | 15 | use parking_lot::Mutex; |
| 16 | 16 | use postage::stream::Stream; |
| 17 | 17 | use pretty_assertions::assert_eq; |
| @@ -1954,7 +1954,7 @@ fn randomly_mutate_worktree( · 1936 unmodified lines | ||
| 1954 | 1954 | new_path |
| 1955 | 1955 | ); |
| 1956 | 1956 | let task = worktree.rename_entry(entry.id, new_path, cx); |
| 1957 | − cx.background_executor().spawn(async move { | |
| 1957 | + cx.background_spawn(async move { | |
| 1958 | 1958 | task.await?.to_included().unwrap(); |
| 1959 | 1959 | Ok(()) |
| 1960 | 1960 | }) |
| @@ -1969,7 +1969,7 @@ fn randomly_mutate_worktree( · 8 unmodified lines | ||
| 1969 | 1969 | child_path, |
| 1970 | 1970 | ); |
| 1971 | 1971 | let task = worktree.create_entry(child_path, is_dir, cx); |
| 1972 | − cx.background_executor().spawn(async move { | |
| 1972 | + cx.background_spawn(async move { | |
| 1973 | 1973 | task.await?; |
| 1974 | 1974 | Ok(()) |
| 1975 | 1975 | }) |
| @@ -1977,7 +1977,7 @@ fn randomly_mutate_worktree( · 1 unmodified line | ||
| 1977 | 1977 | log::info!("overwriting file {:?} ({})", entry.path, entry.id.0); |
| 1978 | 1978 | let task = |
| 1979 | 1979 | worktree.write_file(entry.path.clone(), "".into(), Default::default(), cx); |
| 1980 | − cx.background_executor().spawn(async move { | |
| 1980 | + cx.background_spawn(async move { | |
| 1981 | 1981 | task.await?; |
| 1982 | 1982 | Ok(()) |
| 1983 | 1983 | }) |
| @@ -4,7 +4,7 @@ use backtrace::{self, Backtrace}; · 3 unmodified lines | ||
| 4 | 4 | use chrono::Utc; |
| 5 | 5 | use client::{telemetry, TelemetrySettings}; |
| 6 | 6 | use db::kvp::KEY_VALUE_STORE; |
| 7 | −use gpui::{App, SemanticVersion}; | |
| 7 | +use gpui::{App, AppContext as _, SemanticVersion}; | |
| 8 | 8 | use http_client::{self, HttpClient, HttpClientWithUrl, HttpRequestExt, Method}; |
| 9 | 9 | use paths::{crashes_dir, crashes_retired_dir}; |
| 10 | 10 | use project::Project; |
| @@ -205,35 +205,34 @@ pub fn init( · 194 unmodified lines | ||
| 205 | 205 | ssh_client.update(cx, |client, cx| { |
| 206 | 206 | if TelemetrySettings::get_global(cx).diagnostics { |
| 207 | 207 | let request = client.proto_client().request(proto::GetPanicFiles {}); |
| 208 | − cx.background_executor() | |
| 209 | − .spawn(async move { | |
| 210 | − let panic_files = request.await?; | |
| 211 | − for file in panic_files.file_contents { | |
| 212 | − let panic: Option<Panic> = serde_json::from_str(&file) | |
| 213 | − .log_err() | |
| 214 | − .or_else(|| { | |
| 215 | − file.lines() | |
| 216 | − .next() | |
| 217 | − .and_then(|line| serde_json::from_str(line).ok()) | |
| 218 | − }) | |
| 219 | − .unwrap_or_else(|| { | |
| 220 | − log::error!("failed to deserialize panic file {:?}", file); | |
| 221 | − None | |
| 222 | − }); | |
| 223 | − | |
| 224 | − if let Some(mut panic) = panic { | |
| 225 | − panic.session_id = session_id.clone(); | |
| 226 | − panic.system_id = system_id.clone(); | |
| 227 | − panic.installation_id = installation_id.clone(); | |
| 228 | − | |
| 229 | − upload_panic(&http_client, &panic_report_url, panic, &mut None) | |
| 230 | − .await?; | |
| 231 | − } | |
| 208 | + cx.background_spawn(async move { | |
| 209 | + let panic_files = request.await?; | |
| 210 | + for file in panic_files.file_contents { | |
| 211 | + let panic: Option<Panic> = serde_json::from_str(&file) | |
| 212 | + .log_err() | |
| 213 | + .or_else(|| { | |
| 214 | + file.lines() | |
| 215 | + .next() | |
| 216 | + .and_then(|line| serde_json::from_str(line).ok()) | |
| 217 | + }) | |
| 218 | + .unwrap_or_else(|| { | |
| 219 | + log::error!("failed to deserialize panic file {:?}", file); | |
| 220 | + None | |
| 221 | + }); | |
| 222 | + | |
| 223 | + if let Some(mut panic) = panic { | |
| 224 | + panic.session_id = session_id.clone(); | |
| 225 | + panic.system_id = system_id.clone(); | |
| 226 | + panic.installation_id = installation_id.clone(); | |
| 227 | + | |
| 228 | + upload_panic(&http_client, &panic_report_url, panic, &mut None) | |
| 229 | + .await?; | |
| 232 | 230 | } |
| 231 | + } | |
| 233 | 232 | |
| 234 | − anyhow::Ok(()) | |
| 235 | − }) | |
| 236 | − .detach_and_log_err(cx); | |
| 233 | + anyhow::Ok(()) | |
| 234 | + }) | |
| 235 | + .detach_and_log_err(cx); | |
| 237 | 236 | } |
| 238 | 237 | }) |
| 239 | 238 | } |
| @@ -450,18 +449,17 @@ fn upload_panics_and_crashes( · 210 unmodified lines | ||
| 450 | 449 | cx: &App, |
| 451 | 450 | ) { |
| 452 | 451 | let telemetry_settings = *client::TelemetrySettings::get_global(cx); |
| 453 | − cx.background_executor() | |
| 454 | − .spawn(async move { | |
| 455 | − let most_recent_panic = | |
| 456 | − upload_previous_panics(http.clone(), &panic_report_url, telemetry_settings) | |
| 457 | − .await | |
| 458 | − .log_err() | |
| 459 | − .flatten(); | |
| 460 | − upload_previous_crashes(http, most_recent_panic, installation_id, telemetry_settings) | |
| 452 | + cx.background_spawn(async move { | |
| 453 | + let most_recent_panic = | |
| 454 | + upload_previous_panics(http.clone(), &panic_report_url, telemetry_settings) | |
| 461 | 455 | .await |
| 462 | 456 | .log_err() |
| 463 | − }) | |
| 464 | − .detach() | |
| 457 | + .flatten(); | |
| 458 | + upload_previous_crashes(http, most_recent_panic, installation_id, telemetry_settings) | |
| 459 | + .await | |
| 460 | + .log_err() | |
| 461 | + }) | |
| 462 | + .detach() | |
| 465 | 463 | } |
| 466 | 464 | |
| 467 | 465 | /// Uploads panics via `zed.dev`. |
| @@ -956,7 +956,7 @@ fn install_cli( · 955 unmodified lines | ||
| 956 | 956 | Some(LINUX_PROMPT_DETAIL), |
| 957 | 957 | &["Ok"], |
| 958 | 958 | ); |
| 959 | − cx.background_executor().spawn(prompt).detach(); | |
| 959 | + cx.background_spawn(prompt).detach(); | |
| 960 | 960 | return Ok(()); |
| 961 | 961 | } |
| 962 | 962 | let path = install_cli::install_cli(cx.deref()) |
| @@ -1335,7 +1335,7 @@ fn show_markdown_app_notification<F>( · 372 unmodified lines | ||
| 1335 | 1335 | ) where |
| 1336 | 1336 | F: 'static + Send + Sync + Fn(&mut Window, &mut Context<MessageNotification>), |
| 1337 | 1337 | { |
| 1338 | − let parsed_markdown = cx.background_executor().spawn(async move { | |
| 1338 | + let parsed_markdown = cx.background_spawn(async move { | |
| 1339 | 1339 | let file_location_directory = None; |
| 1340 | 1340 | let language_registry = None; |
| 1341 | 1341 | markdown_preview::markdown_parser::parse_markdown( |
| @@ -3,7 +3,7 @@ use collections::HashMap; · 2 unmodified lines | ||
| 3 | 3 | use copilot::{Copilot, CopilotCompletionProvider}; |
| 4 | 4 | use editor::{Editor, EditorMode}; |
| 5 | 5 | use feature_flags::{FeatureFlagAppExt, PredictEditsFeatureFlag}; |
| 6 | −use gpui::{AnyWindowHandle, App, AppContext, Context, Entity, WeakEntity}; | |
| 6 | +use gpui::{AnyWindowHandle, App, AppContext as _, Context, Entity, WeakEntity}; | |
| 7 | 7 | use language::language_settings::{all_language_settings, EditPredictionProvider}; |
| 8 | 8 | use settings::SettingsStore; |
| 9 | 9 | use std::{cell::RefCell, rc::Rc, sync::Arc}; |
| @@ -419,8 +419,7 @@ impl Zeta { · 418 unmodified lines | ||
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | let values = cx |
| 422 | − .background_executor() | |
| 423 | − .spawn({ | |
| 422 | + .background_spawn({ | |
| 424 | 423 | let snapshot = snapshot.clone(); |
| 425 | 424 | let path = path.clone(); |
| 426 | 425 | async move { |
| @@ -813,8 +812,7 @@ and then another · 386 unmodified lines | ||
| 813 | 812 | let output_excerpt: Arc<str> = output_excerpt.into(); |
| 814 | 813 | |
| 815 | 814 | let edits: Arc<[(Range<Anchor>, String)]> = cx |
| 816 | − .background_executor() | |
| 817 | − .spawn({ | |
| 815 | + .background_spawn({ | |
| 818 | 816 | let output_excerpt = output_excerpt.clone(); |
| 819 | 817 | let editable_range = editable_range.clone(); |
| 820 | 818 | let snapshot = snapshot.clone(); |
| @@ -1127,7 +1125,7 @@ impl LicenseDetectionWatcher { · 306 unmodified lines | ||
| 1127 | 1125 | .map(|file| worktree.load_file(file, cx)) |
| 1128 | 1126 | .collect::<ArrayVec<_, { LICENSE_FILES_TO_CHECK.len() }>>(); |
| 1129 | 1127 | |
| 1130 | − cx.background_executor().spawn(async move { | |
| 1128 | + cx.background_spawn(async move { | |
| 1131 | 1129 | for loaded_file in loaded_files.into_iter() { |
| 1132 | 1130 | let Ok(loaded_file) = loaded_file.await else { |
| 1133 | 1131 | continue; |