aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src/handlers')
-rw-r--r--helix-view/src/handlers/dap.rs63
1 files changed, 62 insertions, 1 deletions
diff --git a/helix-view/src/handlers/dap.rs b/helix-view/src/handlers/dap.rs
index 2e86871b..107c29be 100644
--- a/helix-view/src/handlers/dap.rs
+++ b/helix-view/src/handlers/dap.rs
@@ -1,7 +1,8 @@
use crate::editor::{Action, Breakpoint};
use crate::{align_view, Align, Editor};
+use dap::requests::DisconnectArguments;
use helix_core::Selection;
-use helix_dap::{self as dap, Client, Payload, Request, ThreadId};
+use helix_dap::{self as dap, Client, ConnectionType, Payload, Request, ThreadId};
use helix_lsp::block_on;
use log::warn;
use std::fmt::Write;
@@ -274,6 +275,66 @@ impl Editor {
self.set_status("Debugged application started");
}; // TODO: do we need to handle error?
}
+ Event::Terminated(terminated) => {
+ let restart_args = if let Some(terminated) = terminated {
+ terminated.restart
+ } else {
+ None
+ };
+
+ let disconnect_args = Some(DisconnectArguments {
+ restart: Some(restart_args.is_some()),
+ terminate_debuggee: None,
+ suspend_debuggee: None,
+ });
+
+ if let Err(err) = debugger.disconnect(disconnect_args).await {
+ self.set_error(format!(
+ "Cannot disconnect debugger upon terminated event receival {:?}",
+ err
+ ));
+ return false;
+ }
+
+ match restart_args {
+ Some(restart_args) => {
+ log::info!("Attempting to restart debug session.");
+ let connection_type = match debugger.connection_type() {
+ Some(connection_type) => connection_type,
+ None => {
+ self.set_error("No starting request found, to be used in restarting the debugging session.");
+ return false;
+ }
+ };
+
+ let relaunch_resp = if let ConnectionType::Launch = connection_type {
+ debugger.launch(restart_args).await
+ } else {
+ debugger.attach(restart_args).await
+ };
+
+ if let Err(err) = relaunch_resp {
+ self.set_error(format!(
+ "Failed to restart debugging session: {:?}",
+ err
+ ));
+ }
+ }
+ None => {
+ self.set_status(
+ "Terminated debugging session and disconnected debugger.",
+ );
+ }
+ }
+ }
+ Event::Exited(resp) => {
+ let exit_code = resp.exit_code;
+ if exit_code != 0 {
+ self.set_error(format!(
+ "Debuggee failed to exit successfully (exit code: {exit_code})."
+ ));
+ }
+ }
ev => {
log::warn!("Unhandled event {:?}", ev);
return false; // return early to skip render