@@ -707,7 +707,7 @@ impl RMain {
707
707
buflen : c_int ,
708
708
_hist : c_int ,
709
709
) -> ConsoleResult {
710
- let info = Self :: prompt_info ( prompt) ;
710
+ let info = self . prompt_info ( prompt) ;
711
711
log:: trace!( "R prompt: {}" , info. input_prompt) ;
712
712
713
713
// Upon entering read-console, finalize any debug call text that we were capturing.
@@ -918,20 +918,27 @@ impl RMain {
918
918
// We prefer to panic if there is an error while trying to determine the
919
919
// prompt type because any confusion here is prone to put the frontend in a
920
920
// bad state (e.g. causing freezes)
921
- fn prompt_info ( prompt_c : * const c_char ) -> PromptInfo {
921
+ fn prompt_info ( & self , prompt_c : * const c_char ) -> PromptInfo {
922
922
let n_frame = harp:: session:: r_n_frame ( ) . unwrap ( ) ;
923
923
log:: trace!( "prompt_info(): n_frame = '{n_frame}'" ) ;
924
924
925
925
let prompt_slice = unsafe { CStr :: from_ptr ( prompt_c) } ;
926
926
let prompt = prompt_slice. to_string_lossy ( ) . into_owned ( ) ;
927
927
928
+ let continuation_prompt: String = harp:: get_option ( "continue" ) . try_into ( ) . unwrap ( ) ;
929
+ let matches_continuation = prompt == continuation_prompt;
930
+
928
931
// Detect browser prompt by matching the prompt string
929
932
// https://github.com/posit-dev/positron/issues/4742.
930
933
// There are ways to break this detection, for instance setting
931
934
// `options(prompt =, continue = ` to something that looks like
932
935
// a browser prompt, or doing the same with `readline()`. We have
933
936
// chosen to not support these edge cases.
934
- let browser = RE_DEBUG_PROMPT . is_match ( & prompt) ;
937
+ // Additionally, we send code to R one line at a time, so even if we are debugging
938
+ // it can look like we are in a continuation state. To try and detect that, we
939
+ // detect if we matched the continuation prompt while the DAP is active.
940
+ let browser =
941
+ RE_DEBUG_PROMPT . is_match ( & prompt) || ( self . dap . is_debugging ( ) && matches_continuation) ;
935
942
936
943
// If there are frames on the stack and we're not in a browser prompt,
937
944
// this means some user code is requesting input, e.g. via `readline()`
@@ -941,8 +948,6 @@ impl RMain {
941
948
// we're in a user request, e.g. `readline("+ ")`. To guard against
942
949
// this, we check that we are at top-level (call stack is empty or we
943
950
// have a debug prompt).
944
- let continuation_prompt: String = harp:: get_option ( "continue" ) . try_into ( ) . unwrap ( ) ;
945
- let matches_continuation = prompt == continuation_prompt;
946
951
let top_level = n_frame == 0 || browser;
947
952
let incomplete = matches_continuation && top_level;
948
953
0 commit comments