positron icon indicating copy to clipboard operation
positron copied to clipboard

Some multiline code in R console not working a

Open jonvanausdeln opened this issue 1 year ago • 4 comments

System details:

Windows, Ubuntu 22

Positron and OS details:

Dev build after ARK bumped to 0.1.143

Interpreter details:

R 4.4.1

Describe the issue:

Found in our automated ConsoleInput tests. This appears to be happening after the latest ARK version bump

Steps to reproduce the issue:

  1. Start and R Console
  2. Paste the following into the console
val <- readline(prompt = "Enter your name: ")
cat(sprintf('Hello %s!\n', val))

Results in Image

Expected or desired behavior:

Image

Were there any error messages in the UI, Output panel, or Developer Tools console?

jonvanausdeln avatar Oct 04 '24 17:10 jonvanausdeln

A little more info, looks like we need to recognize if we are in a readline state and pause on sending pending lines if we detect that

(To be clear, to reproduce you have to select both lines at once and send them all over)

Image

DavisVaughan avatar Oct 04 '24 17:10 DavisVaughan

There may be a little extra diagnostic info on OSX. Here is what I see with that test:

Image

[R] /Users/christophermead/posit/positron/extensions/positron-r/resources/ark/ark --connection_file /var/folders/rc/l24758015ggb5438npy04wtc0000gn/T/kernel-yfbhov/connection.json --log /var/folders/rc/l24758015ggb5438npy04wtc0000gn/T/kernel-yfbhov/kernel.log --startup-file /Users/christophermead/posit/positron/extensions/positron-r/resources/scripts/startup.R --session-mode console -- --interactive --no-restore-data
[R]   2024-10-04T17:46:02.111723Z ERROR  Panic! In file 'crates/ark/src/interface.rs' at line 686: internal error: entered unreachable code: Incomplete input in `ReadConsole` handler
[R] 
[R] Backtrace:
[R]    0: std::backtrace::Backtrace::create
[R]    1: ark::main::{{closure}}::{{closure}}
[R]    2: ark::main::{{closure}}
[R]    3: std::panicking::rust_panic_with_hook
[R]    4: std::panicking::begin_panic_handler::{{closure}}
[R]    5: std::sys::backtrace::__rust_end_short_backtrace
[R]    6: _rust_begin_unwind
[R]    7: core::panicking::panic_fmt
[R]    8: ark::interface::RMain::read_console
[R]    9: harp::exec::try_catch::callback
[R]   10: R_withCallingErrorHandler
[R]              at /Volumes/Builds/R4/R-4.3.3/src/main/errors.c:2613:16
[R]   11: harp::exec::top_level_exec::callback
[R]   12: R_ToplevelExec
[R]              at /Volumes/Builds/R4/R-4.3.3/src/main/context.c:799:2
[R]   13: harp::exec::r_sandbox
[R]   14: _r_read_console
[R]   15: Rf_ReplIteration
[R]              at /Volumes/Builds/R4/R-4.3.3/src/main/main.c:210:10
[R]   16: R_ReplConsole
[R]              at /Volumes/Builds/R4/R-4.3.3/src/main/main.c:314:11
[R]   17: run_Rmainloop
[R]              at /Volumes/Builds/R4/R-4.3.3/src/main/main.c:1200:5
[R]   18: ark::interface::RMain::start
[R]   19: ark::main
[R]   20: std::sys::backtrace::__rust_begin_short_backtrace
[R]   21: std::rt::lang_start::{{closure}}
[R]   22: std::rt::lang_start_internal
[R]   23: _main
[R] 
[R]     at crates/ark/src/main.rs:279
[R] 
[R] 
[R] *** Log started at Fri Oct  4 11:46:02 MDT 2024
[R] *** Command line:
[R] /Users/christophermead/posit/positron/extensions/positron-r/resources/ark/ark --connection_file /var/folders/rc/l24758015ggb5438npy04wtc0000gn/T/kernel-OLvWNf/connection.json --log /var/folders/rc/l24758015ggb5438npy04wtc0000gn/T/kernel-OLvWNf/kernel.log --startup-file /Users/christophermead/posit/positron/extensions/positron-r/resources/scripts/startup.R --session-mode console -- --interactive --no-restore-data

testlabauto avatar Oct 04 '24 17:10 testlabauto

QA Note: we are skipping the automated test (see #4902 ) and it will need to be re-enabled after this is fixed.

jonvanausdeln avatar Oct 04 '24 18:10 jonvanausdeln

I think we had decided not to maintain any internal stacks of pending inputs in the case of nested prompts, in particular debug prompts, because doing so would be incompatible with the frontend-side expression splitting (https://github.com/posit-dev/positron/issues/1326). Also we thought it'd be fine because this is the RStudio behaviour.

But now that I think of it, since in the Jupyter protocol readline prompts are nested in execute-request prompts, the frontend-side splitting will not result in pending expressions being sent to readline prompts. So there's a fundamental distinction between browser and readline prompts and I agree the behaviour change highlighted here should be fixed.

Worth noting that we have plans for browser prompts to become readline prompts in notebook-mode, because right now the behaviour is confusing (https://github.com/posit-dev/ark/issues/572). I wonder if we should do the same for browser prompts in console mode to benefit from the same nested structure.

lionel- avatar Oct 07 '24 09:10 lionel-

Verified Fixed

Positron Version(s) : 2024.11.0-49 OS Version(s) : Windows 11

Test scenario(s)

Input now works as expected.

Link(s) to TestRail test cases run or created:

R- User Input R - User Input can use Menu R - ESC dismisses autocomplete

jonvanausdeln avatar Oct 15 '24 18:10 jonvanausdeln