wip
This commit is contained in:
parent
5550e80c4e
commit
68a1c7ce4c
5 changed files with 110 additions and 111 deletions
|
@ -4,9 +4,8 @@ mod only_instance;
|
|||
mod open_listener;
|
||||
|
||||
pub use assets::*;
|
||||
use client2::{Client, UserStore};
|
||||
use collections::HashMap;
|
||||
use gpui2::{AsyncAppContext, Model};
|
||||
use gpui2::{AsyncAppContext, Point};
|
||||
pub use only_instance::*;
|
||||
pub use open_listener::*;
|
||||
|
||||
|
@ -21,6 +20,7 @@ use futures::{
|
|||
};
|
||||
use std::{path::Path, sync::Arc, thread, time::Duration};
|
||||
use util::{paths::PathLikeWithPosition, ResultExt};
|
||||
use workspace2::AppState;
|
||||
|
||||
pub fn connect_to_cli(
|
||||
server_name: &str,
|
||||
|
@ -51,11 +51,6 @@ pub fn connect_to_cli(
|
|||
Ok((async_request_rx, response_tx))
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
pub client: Arc<Client>,
|
||||
pub user_store: Model<UserStore>,
|
||||
}
|
||||
|
||||
pub async fn handle_cli_connection(
|
||||
(mut requests, responses): (mpsc::Receiver<CliRequest>, IpcSender<CliResponse>),
|
||||
app_state: Arc<AppState>,
|
||||
|
@ -96,118 +91,122 @@ pub async fn handle_cli_connection(
|
|||
}
|
||||
Some(path)
|
||||
})
|
||||
.collect()
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
let mut errored = false;
|
||||
|
||||
match cx
|
||||
if let Some(open_paths_task) = cx
|
||||
.update(|cx| workspace2::open_paths(&paths, &app_state, None, cx))
|
||||
.await
|
||||
.log_err()
|
||||
{
|
||||
Ok((workspace, items)) => {
|
||||
let mut item_release_futures = Vec::new();
|
||||
match open_paths_task.await {
|
||||
Ok((workspace, items)) => {
|
||||
let mut item_release_futures = Vec::new();
|
||||
|
||||
for (item, path) in items.into_iter().zip(&paths) {
|
||||
match item {
|
||||
Some(Ok(item)) => {
|
||||
if let Some(point) = caret_positions.remove(path) {
|
||||
todo!()
|
||||
// if let Some(active_editor) = item.downcast::<Editor>() {
|
||||
// active_editor
|
||||
// .downgrade()
|
||||
// .update(&mut cx, |editor, cx| {
|
||||
// let snapshot =
|
||||
// editor.snapshot(cx).display_snapshot;
|
||||
// let point = snapshot
|
||||
// .buffer_snapshot
|
||||
// .clip_point(point, Bias::Left);
|
||||
// editor.change_selections(
|
||||
// Some(Autoscroll::center()),
|
||||
// cx,
|
||||
// |s| s.select_ranges([point..point]),
|
||||
// );
|
||||
// })
|
||||
// .log_err();
|
||||
// }
|
||||
}
|
||||
for (item, path) in items.into_iter().zip(&paths) {
|
||||
match item {
|
||||
Some(Ok(mut item)) => {
|
||||
if let Some(point) = caret_positions.remove(path) {
|
||||
todo!()
|
||||
// if let Some(active_editor) = item.downcast::<Editor>() {
|
||||
// active_editor
|
||||
// .downgrade()
|
||||
// .update(&mut cx, |editor, cx| {
|
||||
// let snapshot =
|
||||
// editor.snapshot(cx).display_snapshot;
|
||||
// let point = snapshot
|
||||
// .buffer_snapshot
|
||||
// .clip_point(point, Bias::Left);
|
||||
// editor.change_selections(
|
||||
// Some(Autoscroll::center()),
|
||||
// cx,
|
||||
// |s| s.select_ranges([point..point]),
|
||||
// );
|
||||
// })
|
||||
// .log_err();
|
||||
// }
|
||||
}
|
||||
|
||||
let released = oneshot::channel();
|
||||
cx.update(|cx| {
|
||||
item.on_release(
|
||||
cx,
|
||||
Box::new(move |_| {
|
||||
let _ = released.0.send(());
|
||||
}),
|
||||
)
|
||||
.detach();
|
||||
});
|
||||
item_release_futures.push(released.1);
|
||||
}
|
||||
Some(Err(err)) => {
|
||||
responses
|
||||
.send(CliResponse::Stderr {
|
||||
message: format!("error opening {:?}: {}", path, err),
|
||||
})
|
||||
.log_err();
|
||||
errored = true;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
if wait {
|
||||
let executor = cx.executor();
|
||||
let wait = async move {
|
||||
if paths.is_empty() {
|
||||
let (done_tx, done_rx) = oneshot::channel();
|
||||
if let Some(workspace) = workspace.upgrade(&cx) {
|
||||
let _subscription = cx.update(|cx| {
|
||||
cx.observe_release(&workspace, move |_, _| {
|
||||
let _ = done_tx.send(());
|
||||
})
|
||||
let released = oneshot::channel();
|
||||
cx.update(move |cx| {
|
||||
item.on_release(
|
||||
cx,
|
||||
Box::new(move |_| {
|
||||
let _ = released.0.send(());
|
||||
}),
|
||||
)
|
||||
.detach();
|
||||
});
|
||||
item_release_futures.push(released.1);
|
||||
}
|
||||
Some(Err(err)) => {
|
||||
responses
|
||||
.send(CliResponse::Stderr {
|
||||
message: format!(
|
||||
"error opening {:?}: {}",
|
||||
path, err
|
||||
),
|
||||
})
|
||||
.log_err();
|
||||
errored = true;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
if wait {
|
||||
let executor = cx.executor().clone();
|
||||
let wait = async move {
|
||||
if paths.is_empty() {
|
||||
let (done_tx, done_rx) = oneshot::channel();
|
||||
let _subscription =
|
||||
cx.update_window_root(&workspace, move |_, cx| {
|
||||
cx.on_release(|_, _| {
|
||||
let _ = done_tx.send(());
|
||||
})
|
||||
});
|
||||
drop(workspace);
|
||||
let _ = done_rx.await;
|
||||
}
|
||||
} else {
|
||||
let _ =
|
||||
futures::future::try_join_all(item_release_futures).await;
|
||||
};
|
||||
}
|
||||
.fuse();
|
||||
futures::pin_mut!(wait);
|
||||
} else {
|
||||
let _ = futures::future::try_join_all(item_release_futures)
|
||||
.await;
|
||||
};
|
||||
}
|
||||
.fuse();
|
||||
futures::pin_mut!(wait);
|
||||
|
||||
loop {
|
||||
// Repeatedly check if CLI is still open to avoid wasting resources
|
||||
// waiting for files or workspaces to close.
|
||||
let mut timer = executor.timer(Duration::from_secs(1)).fuse();
|
||||
futures::select_biased! {
|
||||
_ = wait => break,
|
||||
_ = timer => {
|
||||
if responses.send(CliResponse::Ping).is_err() {
|
||||
break;
|
||||
loop {
|
||||
// Repeatedly check if CLI is still open to avoid wasting resources
|
||||
// waiting for files or workspaces to close.
|
||||
let mut timer = executor.timer(Duration::from_secs(1)).fuse();
|
||||
futures::select_biased! {
|
||||
_ = wait => break,
|
||||
_ = timer => {
|
||||
if responses.send(CliResponse::Ping).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
errored = true;
|
||||
responses
|
||||
.send(CliResponse::Stderr {
|
||||
message: format!("error opening {:?}: {}", paths, error),
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
errored = true;
|
||||
responses
|
||||
.send(CliResponse::Stderr {
|
||||
message: format!("error opening {:?}: {}", paths, error),
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
}
|
||||
|
||||
responses
|
||||
.send(CliResponse::Exit {
|
||||
status: i32::from(errored),
|
||||
})
|
||||
.log_err();
|
||||
responses
|
||||
.send(CliResponse::Exit {
|
||||
status: i32::from(errored),
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue