-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
binding.pry doesn't fire when it's on the last line of a program #45
Comments
Hi @squarism, thanks for the report. I'm aware of this issue, I had a similar report in |
Rolled back to 1.3.2 only because of this. :( |
Hi @rf-! Yes, same issue, but only for end of script. Since this issue was opened I've been thinking about what to do with In any case, I propose 2 alternatives:
As I workaround while this is sorted out (for people who don't want to stick to the 1.x series), I suggest adding
to Gemfile, and then doing
normally but doing
when at the last line of your program. |
Interesting. Just for the record, I found pry-byebug through pry-nav's README which recommended pry-byebug since pry-nav is (planned to be) abandoned. I didn't even know what Thanks for the require tip, that's helpful for project style work although sometimes you don't have a Gemfile (scripts / bin / whatever). Not trying to dissuade you from your proposals while you are at the same time commenting that you are looking for motivation. The workaround for the last line doesn't act as a workaround.
When running this, it exits. No pry shell.
Interestingly, running
But then it exits.
Maybe I could compare states and dig into this to see the difference. Hmm. Anyway:
I'm still trying to find the exact combination of gem versions that replicates the (off-topic) pry start up problem. |
@squarism Sorry for the false workaround, I didn't know pry would load plugins automatically, and just assumed that would work... And thanks for your valuable comments! I think |
@deivid-rodriguez Thanks for giving your perspective on the "byebug plus REPL" vs. "Pry plus stepping" thing. This is really the same problem as the one-letter aliases, I think. As a Pry user, I would normally expect a plugin to stay out of the way unless I'm specifically trying to use it. On the other hand, it makes perfect sense that someone coming from the byebug side would want to make their Pry experience as byebug-like as possible. Anyway, I'm not sure anyone on the Pry team (including me) is going to want to commit to maintaining this project. Given that that's the case, and that you aren't using it, I wouldn't blame you at all for taking a while to fix this edge case. |
Re: the |
Yep, same problem as the aliases. Thanks for understanding, I'll way until someome wants to take over or until I find time myself. At least we have a valid workaround now! |
@deivid-rodriguez can you explain how to disable this behaviour? is it an easy change? If you can give me some guidance on reverting it back to the normal pry behaviour i'll take this on :) |
@deivid-rodriguez is it possible we could make this a config option and users could choose their behaviour? If possible, could we have teh default config to be the normal pry behaviour and for people who prefer your behaviour they could explicitly set it in their The unfortunate situation is that nearly everyone uses Is this an acceptable compromise? I hope so! |
@deivid-rodriguez oh i just heard that you fixed it for the case where Is it possible you could push out a new gem with this fix in it? I think that would reduce the majority of confusion, awesome 👍 John |
@banister I've been a bit reluctant to release because I haven't used last master myself in any app, and the current test suite doesn't give me enough confidence. Let me try the gem against an app in the next days and I'll release if everything is working fine. Or if you can confirm this yourself, I'll release right now! Does this sound reasonable? |
@banister done! |
Are you able to add a note asking for a new maintainer at the top of the readme? |
@gerrywastaken Do you think that's going to work? I mean anybody interested could try to fix this issue (or any other), this is open source after all, but nobody has stepped in... I don't think this gem needs a new mantainer, it needs contributions! |
@deivid-rodriguez Oh sorry! It seems I misunderstood what you were saying. Sorry then, I take it back. Regarding others fixing the issue. I suspect most want a revert of the auto advance feature, which would likely fix this and incompatibility issues with other pry gems. But I can understand reluctance to do this, given what you want from pry-byebug. |
No need to apologize! What I meant is that I currently have no motivation to fix some issues but I'm happy to review any patches and help contributors. If you think a note in the readme can encourage contrutions, it can be done. I don't think this specific issue affects many people. And regarding pry-rescue compatibility, some may consider it a regression but I never meant to support it in the first place... it was just "luck". |
@deivid-rodriguez this auto-advance behaviour actually does break a bunch of plugins and causes weird/unexpected behaviour, i think it does affect a lot of people it's just they've either set the gem version of It would be awesome, if we could revert auto advance -- i think i asked this a while ago, but would you be willing to merge a PR that reverted this behaviour? I appreciate the idea behind the feature, but it just doesn't work well with the Pry ecosystem in general as it breaks expectations of other pry-related gems. Again, I really appreciate the work you've done on this gem but this auto-advance behaviour is so out of tune with Pry in general that I'd really, really love to see it removed or at least turned off by default! :) I'd be happy to do the work in reverting this behaviour if I know that you'd merge it :) |
@banister Please, could you reread this conversation? Last time you talked you requested this same thing, but you hadn't tried last master. Then someone pointed out to you that this was fixed in the 90% case. Then you said it was ok but you asked for a release. So I released and requested some feedback from you. But you didn't reply. Now you ask for the same thing but don't explain what has changed... It's getting very difficult to me to understand what you want and why you want it. To the point that I feel you are disrespecting my time. Your input is always appreciated, you're 'pry`'s author after all, but I really think you're not adding any value. |
@deivid-rodriguez Sorry for not being clear :) Also, sorry for not responding earlier, i probably got distracted by some mundanity and forget to get back to you :( Earlier in the discussion I was just considering For example, auto advancing behaviour breaks 2 other very popular plugins: I hadn't realized how confused people were by the auto advancing behaviour until relatively recently. I don't want to waste your time by asking you to remove the feature yourself, but would you consider merging a PR that reverted this? :) |
No problem, sorry if my comment sounded harsh.
No. I'll consider PR's focusing on adding a feature "X" that I want (I'm up for supporting the kind of functionality Thanks anyways. |
I've been recently considering to actually change the command to enter Would that be a satisfactory resolution for this issue? |
@deivid-rodriguez I think this would be fine for me. I think most people wouldn't mind changing to a new thing. I personally have |
@squarism Thanks for the feedback. I have that vim snippet too :) |
FWIW, I got it to behave the way I would expect (didn't test much, just playing around): diff --git a/lib/byebug/processors/pry_processor.rb b/lib/byebug/processors/pry_processor.rb
index 57a4ee1..2d3ae78 100644
--- a/lib/byebug/processors/pry_processor.rb
+++ b/lib/byebug/processors/pry_processor.rb
@@ -11,11 +11,23 @@ module Byebug
def_delegators :@pry, :output
def_delegators Pry::Helpers::Text, :bold
- def self.start
+ def self.start(target=nil)
Byebug.start
Setting[:autolist] = false
- Context.processor = self
- Byebug.current_context.step_out(4, true)
+
+ # hack because byebug instantiates our class, so this lets us hang onto
+ # the binding until we have an instance to use it on
+ initializer = lambda do |*args, &b|
+ processor = new(*args, &b)
+ processor.enq_binding target if target.kind_of? ::Binding
+ processor
+ end
+ class << initializer
+ alias new call
+ end
+ Context.processor = initializer
+
+ Byebug.current_context.step_out(3, true)
end
#
@@ -37,6 +49,22 @@ module Byebug
return_value
end
+ def enq_binding(bnd)
+ enqueued_bindings << bnd
+ end
+
+ private def enqueued_bindings
+ @enqueued_bindings ||= []
+ end
+
+ private def new_binding
+ if enqueued_bindings.any?
+ enqueued_bindings.shift
+ else
+ frame._binding
+ end
+ end
+
#
# Set up a number of navigational commands to be performed by Byebug.
#
@@ -106,8 +134,6 @@ module Byebug
# Resume an existing Pry REPL at the paused point.
#
def resume_pry
- new_binding = frame._binding
-
run do
if defined?(@pry) && @pry
@pry.repl(new_binding)
diff --git a/lib/pry-byebug/pry_ext.rb b/lib/pry-byebug/pry_ext.rb
index abfdd96..583eefe 100644
--- a/lib/pry-byebug/pry_ext.rb
+++ b/lib/pry-byebug/pry_ext.rb
@@ -5,7 +5,7 @@ class << Pry
def start_with_pry_byebug(target = TOPLEVEL_BINDING, options = {})
if target.is_a?(Binding) && PryByebug.file_context?(target)
- Byebug::PryProcessor.start unless ENV["DISABLE_PRY"]
+ Byebug::PryProcessor.start target unless ENV["DISABLE_PRY"]
else
# No need for the tracer unless we have a file context to step through
start_without_pry_byebug(target, options) After looking at it for a while and reading a lot of the byebug source, I finally realized that we mostly just needed to pass the supplied binding to pry on the first invocation, and then after that, it can behave the way it currently does. It turned out to be a lot harder of a problem than I was would expecting, because Eg consider this program:
When we run it, we will see the tracepoint events. It prints:
So, we start on line 2, with a return from the C-function Frankly, it doesn't seem very thought-out. Eg replace the line that says Also, here's another example that I hit often, where the current implementation doesn't work (I use big case statements when iterating over things like ASTs): object = 123
case object
when Integer
puts 'its a number!'
require "pry"
binding.pry
when String
puts 'its a string!'
when Regexp
puts 'its a regex!'
end |
Hi @JoshCheek, thanks for your feedback. I still feel the best resolution for this issue would be to make But I'm of course I'm open to smarter, better thought-out implementations of |
I mean the "easiest". The best would be of course to fix this by somehow adding support for this in byebug. Or maybe making the autoadvance feature configurable, there's an old PR doing that that I never got to review. |
Yeah, that makes sense. An alternative would be to leave it as a plugin, but one which you explicitly enter, eg a Really, the pain I'm trying to solve is that one of my projects has it as a dependency, so it gets installed with that project, and I didn't really realize that. So, then when pry autoloads it, and it changes pry's behaviour, the line numbers are off, so I thought pry was buggy for ~6 months, and finally sat down last night to report it / try to fix it. Anything which addresses this unintentional loading and changing is sufficient, IMO. Do note that I may be an exception as I often work without bundler, allowing this situation to occur. |
Any movement on this bug? |
Adapted from JoshCheek code at deivid-rodriguez#45 This fixes ConradIrwin/pry-rescue#71
Any movement on this bug? |
(╯°□°)╯︵ ┻━┻ |
to have the |
Failing case:
gem install pry-byebug
Test:
ruby test.rb
. No pry shell opens.Passing case:
gem uninstall pry-byebug
Or, add a line with assignment. Oddly enough, ending lines of comments or simply an ending line of
1
doesn't workaround this.Test:
ruby test.rb
. The pry shell opens.The workaround is pretty simple. Ever since moving to ruby 2 and getting rid of pry-nav, I've just got in the habit of doing this. Logging an issue in case this is unexpected. 🍰
The text was updated successfully, but these errors were encountered: