diff --git a/core/src/palette.rs b/core/src/palette.rs index 5d547b83..7ea5c639 100644 --- a/core/src/palette.rs +++ b/core/src/palette.rs @@ -1241,10 +1241,11 @@ pub fn select( &PaletteType::Workspace => { let state = LAPCE_APP_STATE.get_tab_state(&self.window_id, &self.tab_id); + state.stop(); + *state.workspace.lock() = self.workspace.clone().unwrap(); *state.ssh_session.lock() = None; - state.stop(); - state.start_plugin(); + state.start_proxy(); ctx.request_paint(); } &PaletteType::Command => { diff --git a/core/src/proxy.rs b/core/src/proxy.rs index 6f90a8c6..b3a0e9ed 100644 --- a/core/src/proxy.rs +++ b/core/src/proxy.rs @@ -22,6 +22,8 @@ use crate::buffer::BufferId; use crate::command::LapceUICommand; +use crate::state::LapceWorkspace; +use crate::state::LapceWorkspaceType; use crate::state::LAPCE_APP_STATE; #[derive(Clone)] @@ -81,6 +83,10 @@ pub fn get_completion( f, ); } + + pub fn stop(&self) { + self.process.lock().kill(); + } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -161,13 +167,29 @@ fn handle_request( pub fn start_proxy_process( window_id: WindowId, tab_id: WidgetId, - workspace: PathBuf, + workspace: LapceWorkspace, ) { thread::spawn(move || { - let child = Command::new("/Users/Lulu/lapce/target/debug/lapce-proxy") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn(); + let workspace_type = LAPCE_APP_STATE + .get_tab_state(&window_id, &tab_id) + .workspace + .lock() + .kind + .clone(); + let mut child = match workspace_type { + LapceWorkspaceType::Local => { + Command::new("/Users/Lulu/lapce/target/debug/lapce-proxy") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + } + LapceWorkspaceType::RemoteSSH(user, host) => Command::new("ssh") + .arg(format!("{}@{}", user, host)) + .arg("./lapce/lapce-proxy") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn(), + }; if child.is_err() { println!("can't start proxy {:?}", child); return; @@ -181,7 +203,7 @@ pub fn start_proxy_process( peer, process: Arc::new(Mutex::new(child)), }; - proxy.initialize(workspace); + proxy.initialize(workspace.path.clone()); { let state = LAPCE_APP_STATE.get_tab_state(&window_id, &tab_id); *state.proxy.lock() = Some(proxy); diff --git a/core/src/state.rs b/core/src/state.rs index dfb6fe84..8e765105 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -293,6 +293,7 @@ pub fn get_state(&self, tab_id: &WidgetId) -> LapceTabState { #[derive(Clone)] pub struct LapceTabState { + pub window_id: WindowId, pub tab_id: WidgetId, pub status_id: WidgetId, pub workspace: Arc>, @@ -321,6 +322,7 @@ pub fn new(window_id: WindowId) -> LapceTabState { let tab_id = WidgetId::next(); let status_id = WidgetId::next(); let state = LapceTabState { + window_id, tab_id: tab_id.clone(), status_id, workspace: Arc::new(Mutex::new(workspace.clone())), @@ -350,7 +352,7 @@ pub fn new(window_id: WindowId) -> LapceTabState { ssh_session: Arc::new(Mutex::new(None)), proxy: Arc::new(Mutex::new(None)), }; - start_proxy_process(window_id, tab_id, workspace.path.clone()); + start_proxy_process(window_id, tab_id, workspace.clone()); let local_state = state.clone(); thread::spawn(move || { local_state.start_plugin(); @@ -358,9 +360,16 @@ pub fn new(window_id: WindowId) -> LapceTabState { state } + pub fn start_proxy(&self) { + start_proxy_process( + self.window_id, + self.tab_id, + self.workspace.lock().clone(), + ); + } + pub fn stop(&self) { - self.plugins.lock().stop(); - self.lsp.lock().stop(); + self.proxy.lock().as_ref().unwrap().stop(); } pub fn start_plugin(&self) {