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

Merged
merged 2 commits into from
Oct 10, 2024

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.

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 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I think it's alright but we should only finalize capture if in a browser prompt? The only edge case I can think of is with adversarial readline prompts so this does not matter much I guess.

Copy link
Contributor

@lionel- lionel- left a comment

Choose a reason for hiding this comment

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

LGTM! It now makes sense to me to do that since input requests are nested in execute-requests (posit-dev/positron#4901 (comment)).

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

Choose a reason for hiding this comment

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

hmm, I think it's alright but we should only finalize capture if in a browser prompt? The only edge case I can think of is with adversarial readline prompts so this does not matter much I guess.

…st issue

The ordering is now:
- Handle input requests
- Then pending lines
- Then close out active requests
@DavisVaughan DavisVaughan merged commit 990109f into main Oct 10, 2024
6 checks passed
@DavisVaughan DavisVaughan deleted the fix/input-request-in-multiline branch October 10, 2024 17:12
@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants