nonsequitur / inf-ruby

218 stars 69 forks source link

(ruby-send-region) does not work with ruby's `debug` gem #165

Closed waymondo closed 1 year ago

waymondo commented 2 years ago

It seems to have something to do with the way the eval statement is formatted / executed that I don't totally grok.

Here's an example of the output if I run (run-ruby), run debugger in that process, then try to send a region of rand to it:

(rdbg) 
eval error: (rdbg)/(irb):1: can't find string "--inf-ruby--2585c5b624a00f-25420-35024-577055--" anywhere before EOF
(rdbg)/(irb):1: syntax error, unexpected ',', expecting end-of-input
...b624a00f-25420-35024-577055--', (defined?(IRB.conf) && IRB.c...
...                              ^
(rdbg) 0.7160654263057463
(rdbg) eval error: (rdbg)/(irb):1: syntax error, unexpected local variable or method, expecting end-of-input
--inf-ruby--2585c5b624a00f-25420-35024-577055--
                ^~~~~~~~~~
nil

It is worth noting that if you invoke irb within the debug process, (ruby-send-region) works as expected.

dgutov commented 2 years ago

Makes sense.

To make completion work in the "old" debugger, I had to fiddle with the syntax of the sent expression (4873a66a4d9bcdf). I'm guessing it uses a bespoke evaluator or somesuch.

Something similar could be happening here. The current scheme uses eval and a heredoc, and either could be handled a little bit imperfectly by debug.

waymondo commented 2 years ago

I think the primary culprit is that there isn't multi-line support for debug currently (https://github.com/ruby/debug/issues/299). Looking at my output above you can see it tries to eval each line separately, which results in the broken heredoc interpretation, but the actual send region output correctly evals in the middle. I'll mess around with it this week if I have time.

dgutov commented 1 year ago

It sounds like the new implementation of ruby-send-region (just merged to master) might work better here.

waymondo commented 1 year ago

very nice! the update seems to work for me, thanks for the ping