-
Notifications
You must be signed in to change notification settings - Fork 138
Set evaluation result to _ local variable
#1159
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
Open
HeyNonster
wants to merge
1
commit into
ruby:master
Choose a base branch
from
HeyNonster:nony/underscore-last-result
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This PR makes a change to the thread client to set the `_` local variable to the result of the last evaluation similar to the behavior in irb[^1]. The reason `_` doesn't work even when using the `irb` console is because we leave the `irb` evaluation early if the input should be handled by the debugger[^2]. Otherwise, we would end up in IRB::Context#evaluate` and we would call `set_last_value`[^3]. There's a bit of a quirk here when using the `irb` console. I was hoping in `thread_client` to evaluate the result then set the `_` local variable and the `@last_value` ivar all in the same method, similar to how `irb` does it[^1]. However, because we're using the `irb` console we use a new `irb` `Workspace` which nils out `_` when initialized[^4]. To get around that, we set the local variable just before evaluating. [^1]:(https://github.com/ruby/irb/blob/d43c3d764ae439706aa1b26a3ec299cc45eaed5b/lib/irb/context.rb#L460-L465) [^2]:(https://github.com/ruby/irb/blob/d43c3d764ae439706aa1b26a3ec299cc45eaed5b/lib/irb.rb#L195-L198) [^3]:(https://github.com/ruby/irb/blob/d43c3d764ae439706aa1b26a3ec299cc45eaed5b/lib/irb/context.rb#L550-L558) [^4]:(https://github.com/ruby/irb/blob/d43c3d764ae439706aa1b26a3ec299cc45eaed5b/lib/irb/workspace.rb#L81) This PR was created by Zendesk's Ruby infrastructure team: Co-authored-by: Benjamin Quorning <bquorning@zendesk.com> Co-authored-by: Edyta Rozczypała <edyta.rozczypala@zendesk.com> Co-authored-by: Jury Razumau <jury.razumau@zendesk.com> Co-authored-by: Leonid Batizhevskii <leonid.batizhevskii@zendesk.com> Co-authored-by: Luis Manotas <lgerman@gmail.com> Co-authored-by: Thomas Countz <thomascountz@gmail.com>
❌ 1/689 Tests Failed/home/runner/work/debug/debug/test/protocol/catch_raw_dap_test.rb#test_catching_any_exception_works_correctly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This resolves #1069.
This PR makes a change to the thread client to set the
_local variable to the result of the last evaluation similar to the behavior in irb1.The reason
_doesn't work even when using theirbconsole is because we leave theirbevaluation early if the input should be handled by the debugger2. Otherwise, we would end up inIRB::Context#evaluateand we would callset_last_value3.There's a bit of a quirk here when using the
irbconsole. I was hoping inthread_clientto evaluate the result then set the_local variable and the@last_valueivar all in the same method, similar to howirbdoes it1. However, because we're using theirbconsole we use a newirbWorkspacewhich nils out_when initialized4. To get around that, we set the local variable just before evaluating.Footnotes
(https://github.com/ruby/irb/blob/d43c3d764ae439706aa1b26a3ec299cc45eaed5b/lib/irb/context.rb#L460-L465) ↩ ↩2
(https://github.com/ruby/irb/blob/d43c3d764ae439706aa1b26a3ec299cc45eaed5b/lib/irb.rb#L195-L198) ↩
(https://github.com/ruby/irb/blob/d43c3d764ae439706aa1b26a3ec299cc45eaed5b/lib/irb/context.rb#L550-L558) ↩
(https://github.com/ruby/irb/blob/d43c3d764ae439706aa1b26a3ec299cc45eaed5b/lib/irb/workspace.rb#L81) ↩