Skip to content

Commit d2382d2

Browse files
committed
Rename to is_debugging_stdin
1 parent 3a1f696 commit d2382d2

3 files changed

Lines changed: 31 additions & 34 deletions

File tree

crates/ark/src/console/console_repl.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -869,15 +869,15 @@ impl Console {
869869
return result;
870870
}
871871

872-
// In notebook mode, unexpected browser() or debug() calls (i.e.
873-
// without an active debug session) are routed to stdin so the user
874-
// can type debug commands in an input box rather than hanging.
872+
// In notebook mode, `browser()` or `debug()` calls causing a
873+
// browser prompt outside of an active debugging session are routed
874+
// to stdin so the user can type debug commands in an input box.
875875
if self.session_mode == SessionMode::Notebook &&
876876
!self.debug_dap.lock().unwrap().is_connected
877877
{
878-
self.debug_dap.lock().unwrap().is_stopped_at_browser = true;
878+
self.debug_dap.lock().unwrap().is_debugging_stdin = true;
879879
let result = self.handle_input_request(&info, buf, buflen);
880-
self.debug_dap.lock().unwrap().is_stopped_at_browser = false;
880+
self.debug_dap.lock().unwrap().is_debugging_stdin = false;
881881
return result;
882882
}
883883

@@ -994,21 +994,17 @@ impl Console {
994994
// package. 50ms seems to be more in line with RStudio (posit-dev/positron#7235).
995995
let polled_events_rx = crossbeam::channel::tick(Duration::from_millis(50));
996996

997-
// This is the main kind of message from the frontend that we are expecting.
998-
// We either wait for `input_reply` messages on StdIn, or for
999-
// `execute_request` on Shell.
1000-
let (r_request_index, stdin_reply_index) = match wait_for {
1001-
WaitFor::ExecuteRequest => (Some(select.recv(&r_request_rx)), None),
1002-
WaitFor::InputReply => {
1003-
// In notebook mode, also listen for debug commands (e.g. Quit
1004-
// from the interrupt handler) while waiting for stdin input.
1005-
let r_request_index = if self.session_mode == SessionMode::Notebook {
1006-
Some(select.recv(&r_request_rx))
1007-
} else {
1008-
None
1009-
};
1010-
(r_request_index, Some(select.recv(&stdin_reply_rx)))
1011-
},
997+
// This is the main kind of message from the frontend that we are
998+
// expecting. We either wait for `input_reply` messages on StdIn, or for
999+
// `execute_request` on Shell. We also listen for R requests, including
1000+
// while waiting on StdIn. Such requests are only expected in Notebook
1001+
// mode when debugging via StdIn. The interrupt handler may send us a
1002+
// Quit command to terminate the debugging session. For simplicity we
1003+
// listen for these requests unconditionally, including in Console sessions.
1004+
let r_request_index = select.recv(&r_request_rx);
1005+
let stdin_reply_index = match wait_for {
1006+
WaitFor::ExecuteRequest => None,
1007+
WaitFor::InputReply => Some(select.recv(&stdin_reply_rx)),
10121008
};
10131009

10141010
let kernel_request_index = select.recv(&kernel_request_rx);
@@ -1072,16 +1068,16 @@ impl Console {
10721068

10731069
match oper.index() {
10741070
// We've got an execute request from the frontend
1075-
i if Some(i) == r_request_index => {
1071+
i if i == r_request_index => {
10761072
let req = oper.recv(&r_request_rx);
10771073
let Ok(req) = req else {
10781074
// The channel is disconnected and empty
10791075
return ConsoleResult::Disconnected;
10801076
};
10811077

1082-
// During stdin-browser (notebook mode, waiting for input
1083-
// at a browser prompt), the interrupt handler sends
1084-
// DebugCommand(Quit) to exit the browser cleanly.
1078+
// When debugging via StdIn in notebook mode, waiting for
1079+
// input at a browser prompt, the interrupt handler may send
1080+
// a Quit command to exit the browser cleanly.
10851081
if matches!(wait_for, WaitFor::InputReply) {
10861082
if let RRequest::DebugCommand(ref cmd) = req {
10871083
let input = crate::request::debug_request_command(cmd.clone());

crates/ark/src/control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl ControlHandler for Control {
9292
// debugging on interrupt is natural UX in that context.
9393
if matches!(self.session_mode, SessionMode::Notebook) {
9494
let dap = self.dap.lock().unwrap();
95-
if dap.is_debugging || dap.is_stopped_at_browser {
95+
if dap.is_debugging || dap.is_debugging_stdin {
9696
drop(dap);
9797
self.r_request_tx
9898
.send(RRequest::DebugCommand(crate::request::DebugRequest::Quit))

crates/ark/src/dap/dap_state.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ pub struct Dap {
224224
/// Whether the REPL is stopped with a browser prompt.
225225
pub is_debugging: bool,
226226

227+
/// Whether R is stopped at an unexpected `browser()` prompt in notebook
228+
/// mode (no active debug session). Mutually exclusive with `is_debugging`.
229+
/// 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
231+
/// enum in the future.
232+
pub is_debugging_stdin: bool,
233+
227234
/// Whether the DAP server is connected to a client.
228235
pub is_connected: bool,
229236

@@ -273,12 +280,6 @@ pub struct Dap {
273280
/// Whether an interrupt was sent to drop into the debugger
274281
pub(crate) is_interrupting_for_debugger: bool,
275282

276-
/// Whether R is stopped at a browser prompt in notebook mode
277-
/// (either a debug session breakpoint or an unexpected browser()
278-
/// routed to stdin). Used by the interrupt handler to decide
279-
/// whether to send a "Q" command.
280-
pub(crate) is_stopped_at_browser: bool,
281-
282283
/// Channel for sending events to the comm frontend.
283284
comm_tx: Option<CommOutgoingTx>,
284285

@@ -301,6 +302,7 @@ impl Dap {
301302
pub fn new_shared(r_request_tx: Sender<RRequest>) -> Arc<Mutex<Self>> {
302303
let state = Self {
303304
is_debugging: false,
305+
is_debugging_stdin: false,
304306
is_connected: false,
305307
backend_events_tx: None,
306308
stack: None,
@@ -317,7 +319,6 @@ impl Dap {
317319
r_request_tx,
318320
shared_self: None,
319321
is_interrupting_for_debugger: false,
320-
is_stopped_at_browser: false,
321322
};
322323

323324
let shared = Arc::new(Mutex::new(state));
@@ -872,7 +873,7 @@ mod tests {
872873
comm_tx: None,
873874
iopub_tx: None,
874875
iopub_seq: 0,
875-
is_stopped_at_browser: false,
876+
is_debugging_stdin: false,
876877
r_request_tx,
877878
shared_self: None,
878879
};
@@ -986,7 +987,7 @@ mod tests {
986987
comm_tx: None,
987988
iopub_tx: None,
988989
iopub_seq: 0,
989-
is_stopped_at_browser: false,
990+
is_debugging_stdin: false,
990991
r_request_tx,
991992
shared_self: None,
992993
};

0 commit comments

Comments
 (0)