Skip to content

Commit 1e4b2cb

Browse files
committed
Make dap_handler optional
1 parent 40aa750 commit 1e4b2cb

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

crates/ark/src/control.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use crate::request::RRequest;
2828
pub struct Control {
2929
r_request_tx: Sender<RRequest>,
3030
dap: Arc<Mutex<Dap>>,
31-
session_mode: SessionMode,
32-
dap_handler: DapJupyterHandler,
31+
dap_handler: Option<DapJupyterHandler>,
3332
}
3433

3534
impl Control {
@@ -39,17 +38,20 @@ impl Control {
3938
iopub_tx: Sender<IOPubMessage>,
4039
session_mode: SessionMode,
4140
) -> Self {
42-
if matches!(session_mode, SessionMode::Notebook) {
41+
let dap_handler = if matches!(session_mode, SessionMode::Notebook) {
4342
dap.lock().unwrap().set_iopub_tx(iopub_tx.clone());
44-
}
43+
Some(DapJupyterHandler::new(
44+
dap.clone(),
45+
r_request_tx.clone(),
46+
iopub_tx,
47+
))
48+
} else {
49+
None
50+
};
4551

46-
// Currently unused for Console, but it would be nice to get
47-
// `SetBreakpoints` requests via Jupyter in the future
48-
let dap_handler = DapJupyterHandler::new(dap.clone(), r_request_tx.clone(), iopub_tx);
4952
Self {
5053
r_request_tx,
5154
dap,
52-
session_mode,
5355
dap_handler,
5456
}
5557
}
@@ -90,7 +92,7 @@ impl ControlHandler for Control {
9092
// the debugger. The difference is justified by how the Console stays
9193
// busy while debugging, showing a spinning wheel to the user. Quitting
9294
// debugging on interrupt is natural UX in that context.
93-
if matches!(self.session_mode, SessionMode::Notebook) {
95+
if self.dap_handler.is_some() {
9496
let dap = self.dap.lock().unwrap();
9597
if dap.is_debugging || dap.is_debugging_stdin {
9698
drop(dap);
@@ -105,7 +107,16 @@ impl ControlHandler for Control {
105107
}
106108

107109
fn handle_debug_request(&self, msg: &DebugRequest) -> Result<DebugReply, Exception> {
108-
let response = self.dap_handler.handle(&msg.content);
110+
let Some(handler) = &self.dap_handler else {
111+
let response = serde_json::json!({
112+
"seq": 0,
113+
"type": "response",
114+
"success": false,
115+
"message": "Debug requests are not supported in console mode",
116+
});
117+
return Ok(DebugReply { content: response });
118+
};
119+
let response = handler.handle(&msg.content);
109120
Ok(DebugReply { content: response })
110121
}
111122
}

0 commit comments

Comments
 (0)