Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out handle_active_request() to correct multiline input request issue #568

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DavisVaughan
Copy link
Contributor

Addresses posit-dev/positron#4901

The problem was that in something like:

val <- readline("prompt>")
paste0(val, "-suffix")

if you send that whole selection, then we'd process the val <- readline("prompt>") line, but then R calls read_console() back and we'd just immediately shove paste0(val, "-suffix") through as the reply to the readline request! We need to use the prompt_info() to recognize that an intermediate expression has put us into an input_request state, and handle that before we handle pending_lines.

The ordering of our state machine is now:

  • Handle input requests
    • Falls through to event loop to wait for input reply
  • Then pending lines
  • Then close out active requests
    • Falls through to event loop to wait for next user input

I've accomplished this by factoring out handle_active_request(). This takes that big if/else branch related to the active request and gives it its own function. The logic in that if/else was actually pretty tricky, and I think it is much cleaner now. It also allows us to sneak in handle_pending_lines() between the input request check and closing out the active request.

…st issue

The ordering is now:
- Handle input requests
- Then pending lines
- Then close out active requests
Comment on lines +646 to +650
// Upon entering read-console, finalize any debug call text that we were capturing.
// At this point, the user can either advance the debugger, causing us to capture
// a new expression, or execute arbitrary code, where we will reuse a finalized
// debug call text to maintain the debug state.
self.dap.finalize_call_text();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure if it matters that this now runs before pending lines are handled 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant