Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugger support for dx #3814

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl RunArgs {
ServeUpdate::Redraw => {}
ServeUpdate::OpenApp => {}
ServeUpdate::ToggleShouldRebuild => {}
ServeUpdate::OpenDebugger => {}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/serve/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// The debugger for the app - must be enabled with the `d` key
pub(crate) app_debugger: Option<Child>,
}

impl AppHandle {
Expand All @@ -61,6 +64,7 @@ impl AppHandle {
server_stderr: None,
entropy_app_exe: None,
entropy_server_exe: None,
app_debugger: None,
})
}

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()),
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/serve/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 32 additions & 1 deletion packages/cli/src/serve/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())) => {
Expand Down Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/serve/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub(crate) enum ServeUpdate {
NewConnection,
WsMessage(WsMessage),

OpenDebugger,

/// A build update from the build engine
BuildUpdate(BuildUpdate),

Expand Down