diff --git a/packages/cli/src/cli/run.rs b/packages/cli/src/cli/run.rs index b9cd100275..daab053df8 100644 --- a/packages/cli/src/cli/run.rs +++ b/packages/cli/src/cli/run.rs @@ -60,6 +60,7 @@ impl RunArgs { ServeUpdate::Redraw => {} ServeUpdate::OpenApp => {} ServeUpdate::ToggleShouldRebuild => {} + ServeUpdate::OpenDebugger => {} } } diff --git a/packages/cli/src/serve/handle.rs b/packages/cli/src/serve/handle.rs index 8cad0fb170..b25fa62336 100644 --- a/packages/cli/src/serve/handle.rs +++ b/packages/cli/src/serve/handle.rs @@ -46,6 +46,9 @@ pub(crate) struct AppHandle { /// The virtual directory that assets will be served from /// Used mostly for apk/ipa builds since they live in simulator pub(crate) runtime_asst_dir: Option, + + /// The debugger for the app - must be enabled with the `d` key + pub(crate) app_debugger: Option, } impl AppHandle { @@ -61,6 +64,7 @@ impl AppHandle { server_stderr: None, entropy_app_exe: None, entropy_server_exe: None, + app_debugger: None, }) } diff --git a/packages/cli/src/serve/mod.rs b/packages/cli/src/serve/mod.rs index f19eff965d..ca4166d88f 100644 --- a/packages/cli/src/serve/mod.rs +++ b/packages/cli/src/serve/mod.rs @@ -242,6 +242,10 @@ pub(crate) async fn serve_all(mut args: ServeArgs) -> Result<()> { ) } + ServeUpdate::OpenDebugger => { + runner.open_debugger().await; + } + ServeUpdate::Exit { error } => match error { Some(err) => break Err(anyhow::anyhow!("{}", err).into()), None => break Ok(()), diff --git a/packages/cli/src/serve/output.rs b/packages/cli/src/serve/output.rs index b400cdf8d9..1edb38f46b 100644 --- a/packages/cli/src/serve/output.rs +++ b/packages/cli/src/serve/output.rs @@ -263,6 +263,12 @@ impl Output { self.trace = !self.trace; tracing::info!("Tracing is now {}", if self.trace { "on" } else { "off" }); } + KeyCode::Char('d') => { + // if key.modifiers.contains(KeyModifiers::SHIFT) { + tracing::info!("Opening debugger"); + return Ok(Some(ServeUpdate::OpenDebugger)); + // } + } KeyCode::Char('c') => { stdout() diff --git a/packages/cli/src/serve/runner.rs b/packages/cli/src/serve/runner.rs index 597c47753f..4eed170c45 100644 --- a/packages/cli/src/serve/runner.rs +++ b/packages/cli/src/serve/runner.rs @@ -70,7 +70,10 @@ impl AppRunner { handle.app_child = None; ProcessExited { status, platform } }, - Err(_err) => todo!("handle error in process joining?"), + Err(_err) => { + futures_util::future::pending().await + // ProcessExited { status, platform } + }, } } Some(Ok(Some(msg))) = OptionFuture::from(handle.server_stdout.as_mut().map(|f| f.next_line())) => { @@ -340,4 +343,32 @@ impl AppRunner { _ = std::fs::remove_dir_all(&cache_dir); _ = std::fs::create_dir_all(&cache_dir); } + + // todo: add a way to open the server's debugger too + pub(crate) async fn open_debugger(&self) { + let Some(handle) = self.running.as_ref() else { + return; + }; + + let Some(app) = handle.app_child.as_ref() else { + return; + }; + + let Some(id) = app.id() else { + return; + }; + + let url = format!( + "vscode://vadimcn.vscode-lldb/launch/config?{{'request':'attach','pid':{}}}", + id + ); + + tracing::info!("Opening debugger: {url}"); + + tokio::process::Command::new("code") + .arg("--open-url") + .arg(url) + .spawn() + .unwrap(); + } } diff --git a/packages/cli/src/serve/update.rs b/packages/cli/src/serve/update.rs index 49e094adc7..b047467f48 100644 --- a/packages/cli/src/serve/update.rs +++ b/packages/cli/src/serve/update.rs @@ -10,6 +10,8 @@ pub(crate) enum ServeUpdate { NewConnection, WsMessage(WsMessage), + OpenDebugger, + /// A build update from the build engine BuildUpdate(BuildUpdate),