Start removing the Send impl for App

Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-11-01 11:31:23 -07:00 committed by Nathan Sobo
parent ea7fdef417
commit 57ffa8201e
38 changed files with 506 additions and 932 deletions

View file

@ -5,7 +5,7 @@ pub use lsp_types::*;
use anyhow::{anyhow, Context, Result};
use collections::HashMap;
use futures::{channel::oneshot, io::BufWriter, AsyncRead, AsyncWrite, FutureExt};
use gpui2::{AsyncAppContext, Executor, Task};
use gpui2::{AsyncAppContext, BackgroundExecutor, Task};
use parking_lot::Mutex;
use postage::{barrier, prelude::Stream};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
@ -62,7 +62,7 @@ pub struct LanguageServer {
notification_handlers: Arc<Mutex<HashMap<&'static str, NotificationHandler>>>,
response_handlers: Arc<Mutex<Option<HashMap<usize, ResponseHandler>>>>,
io_handlers: Arc<Mutex<HashMap<usize, IoHandler>>>,
executor: Executor,
executor: BackgroundExecutor,
#[allow(clippy::type_complexity)]
io_tasks: Mutex<Option<(Task<Option<()>>, Task<Option<()>>)>>,
output_done_rx: Mutex<Option<barrier::Receiver>>,
@ -248,7 +248,7 @@ impl LanguageServer {
let (stdout, stderr) = futures::join!(stdout_input_task, stderr_input_task);
stdout.or(stderr)
});
let output_task = cx.executor().spawn({
let output_task = cx.background_executor().spawn({
Self::handle_output(
stdin,
outbound_rx,
@ -269,7 +269,7 @@ impl LanguageServer {
code_action_kinds,
next_id: Default::default(),
outbound_tx,
executor: cx.executor().clone(),
executor: cx.background_executor().clone(),
io_tasks: Mutex::new(Some((input_task, output_task))),
output_done_rx: Mutex::new(Some(output_done_rx)),
root_path: root_path.to_path_buf(),
@ -670,10 +670,10 @@ impl LanguageServer {
match serde_json::from_str(params) {
Ok(params) => {
let response = f(params, cx.clone());
cx.executor()
.spawn_on_main({
cx.foreground_executor()
.spawn({
let outbound_tx = outbound_tx.clone();
move || async move {
async move {
let response = match response.await {
Ok(result) => Response {
jsonrpc: JSON_RPC_VERSION,
@ -769,7 +769,7 @@ impl LanguageServer {
next_id: &AtomicUsize,
response_handlers: &Mutex<Option<HashMap<usize, ResponseHandler>>>,
outbound_tx: &channel::Sender<String>,
executor: &Executor,
executor: &BackgroundExecutor,
params: T::Params,
) -> impl 'static + Future<Output = anyhow::Result<T::Result>>
where
@ -1048,7 +1048,7 @@ impl FakeLanguageServer {
let result = handler(params, cx.clone());
let responded_tx = responded_tx.clone();
async move {
cx.executor().simulate_random_delay().await;
cx.background_executor().simulate_random_delay().await;
let result = result.await;
responded_tx.unbounded_send(()).ok();
result