Skip to content

Commit 413eaf0

Browse files
committed
Address code review
1 parent d0d8015 commit 413eaf0

3 files changed

Lines changed: 40 additions & 25 deletions

File tree

crates/amalthea/src/fixtures/dummy_frontend.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,20 @@ impl DummyFrontend {
260260
options: ExecuteRequestOptions,
261261
metadata: serde_json::Value,
262262
) -> String {
263-
let content = ExecuteRequest {
264-
code: String::from(code),
265-
silent: false,
266-
store_history: true,
267-
user_expressions: serde_json::Value::Null,
268-
allow_stdin: options.allow_stdin,
269-
stop_on_error: false,
270-
positron: options.positron,
271-
};
272-
let mut message = JupyterMessage::create(content, None, &self.session);
273-
message.metadata = metadata;
274-
let id = message.header.msg_id.clone();
275-
message.send(&self.shell_socket).unwrap();
276-
id
263+
Self::send_with_metadata(
264+
&self.shell_socket,
265+
&self.session,
266+
ExecuteRequest {
267+
code: String::from(code),
268+
silent: false,
269+
store_history: true,
270+
user_expressions: serde_json::Value::Null,
271+
allow_stdin: options.allow_stdin,
272+
stop_on_error: false,
273+
positron: options.positron,
274+
},
275+
metadata,
276+
)
277277
}
278278

279279
/// Send a DAP request wrapped in a Jupyter `debug_request` on the control channel.
@@ -315,6 +315,19 @@ impl DummyFrontend {
315315
id
316316
}
317317

318+
fn send_with_metadata<T: ProtocolMessage>(
319+
socket: &Socket,
320+
session: &Session,
321+
msg: T,
322+
metadata: serde_json::Value,
323+
) -> String {
324+
let mut message = JupyterMessage::create(msg, None, session);
325+
message.metadata = metadata;
326+
let id = message.header.msg_id.clone();
327+
message.send(socket).unwrap();
328+
id
329+
}
330+
318331
#[track_caller]
319332
pub fn recv(socket: &Socket) -> Message {
320333
// It's important to wait with a timeout because the kernel thread might have

crates/ark/src/console/console_repl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,9 @@ impl Console {
888888
return result;
889889
}
890890

891-
// Similarly, if we have pending inputs, we're about to immediately
892-
// continue with the next expression. Don't emit debug notifications
893-
// for these intermediate browser prompts.
891+
// As with auto-stepping above, if we have pending inputs we're
892+
// about to immediately continue with the next expression. Don't
893+
// emit debug notifications for these intermediate browser prompts.
894894
let has_pending = self.pending_inputs.as_ref().is_some_and(|p| !p.is_empty());
895895

896896
// Only now that we know we're stopping for real, set state and

crates/ark/src/dap/dap_state.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub struct Dap {
227227
/// Whether R is stopped at an unexpected `browser()` prompt in notebook
228228
/// mode (no active debug session). Mutually exclusive with `is_debugging`.
229229
/// Used by the interrupt handler to decide whether to send a "Q" command.
230-
/// `id_debugging` and `is_stopped_at_browser` could be folded into a single
230+
/// `is_debugging` and `is_debugging_stdin` could be folded into a single
231231
/// enum in the future.
232232
pub is_debugging_stdin: bool,
233233

@@ -285,7 +285,7 @@ pub struct Dap {
285285

286286
/// IOPub sender for emitting DAP events as `debug_event` messages
287287
/// in notebook debugging mode (Jupyter Debug Protocol path).
288-
iopub_tx: Option<Sender<IOPubMessage>>,
288+
notebook_iopub_tx: Option<Sender<IOPubMessage>>,
289289

290290
/// Sequence counter for IOPub DAP event messages.
291291
iopub_seq: i64,
@@ -314,7 +314,7 @@ impl Dap {
314314
current_variables_reference: 1,
315315
current_breakpoint_id: 1,
316316
comm_tx: None,
317-
iopub_tx: None,
317+
notebook_iopub_tx: None,
318318
iopub_seq: 0,
319319
r_request_tx,
320320
shared_self: None,
@@ -388,7 +388,7 @@ impl Dap {
388388
let was_debugging = self.is_debugging;
389389
self.is_debugging = false;
390390

391-
if was_debugging && (self.is_connected || self.iopub_tx.is_some()) {
391+
if was_debugging && (self.is_connected || self.notebook_iopub_tx.is_some()) {
392392
log::trace!("DAP: Sending `stop_debug` events");
393393

394394
if let Some(comm_tx) = &self.comm_tx {
@@ -406,15 +406,15 @@ impl Dap {
406406
}
407407

408408
pub fn set_iopub_tx(&mut self, tx: Sender<IOPubMessage>) {
409-
self.iopub_tx = Some(tx);
409+
self.notebook_iopub_tx = Some(tx);
410410
}
411411

412412
fn send_backend_event(&mut self, event: DapBackendEvent) {
413413
if let Some(tx) = &self.backend_events_tx {
414414
tx.send(event.clone()).log_err();
415415
}
416416

417-
if let Some(tx) = &self.iopub_tx {
417+
if let Some(tx) = &self.notebook_iopub_tx {
418418
let dap_event = event.into_dap_event();
419419
self.iopub_seq += 1;
420420

@@ -611,6 +611,8 @@ impl Dap {
611611
return;
612612
};
613613

614+
// Collect events first: `bp_list` borrows from `self.breakpoints`,
615+
// which prevents calling `&mut self` methods like `send_backend_event()`.
614616
let mut events = Vec::new();
615617

616618
for bp in bp_list.iter_mut() {
@@ -871,7 +873,7 @@ mod tests {
871873
current_breakpoint_id: 1,
872874
is_interrupting_for_debugger: false,
873875
comm_tx: None,
874-
iopub_tx: None,
876+
notebook_iopub_tx: None,
875877
iopub_seq: 0,
876878
is_debugging_stdin: false,
877879
r_request_tx,
@@ -985,7 +987,7 @@ mod tests {
985987
current_breakpoint_id: 1,
986988
is_interrupting_for_debugger: false,
987989
comm_tx: None,
988-
iopub_tx: None,
990+
notebook_iopub_tx: None,
989991
iopub_seq: 0,
990992
is_debugging_stdin: false,
991993
r_request_tx,

0 commit comments

Comments
 (0)