debug icon indicating copy to clipboard operation
debug copied to clipboard

edit command does not work with Panic Nova

Open mzagaja opened this issue 3 years ago • 1 comments

Your environment

mzagaja@Matthews-MacBook-Pro-16 ~/D/roadrunner (PLAT-1878-remove-unused-topics-routes) [SIGINT]> ruby -v
ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-darwin21]
mzagaja@Matthews-MacBook-Pro-16 ~/D/roadrunner (PLAT-1878-remove-unused-topics-routes)> rdbg -v
rdbg 1.5.0

Describe the bug When I type edit into Ruby debug, it outputs the command information, but does not actually open the editor with the file.

To Reproduce

bundle exec rspec spec/requests/follows_spec.rb
Symfony User is deprecated!  Switch to Identity::User.
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 59410
.......[9, 18] in ~/Developer/roadrunner/spec/requests/follows_spec.rb
     9|   let(:session_user) { new_logged_in_session_user(identity_user: identity_user) }
    10|
    11|   describe 'creating' do
    12|     context 'logged in' do
    13|       it 'should succesfully create a follow for a user' do
=>  14|         debugger
    15|         allow_any_instance_of(Identity::Follow).to receive(:save) { true }
    16|         sign_in session_user
    17|         post '/follows.json', params: { follow: { subject_type: 'User', subject_id: 1234 } }
    18|         expect(response.status).to eq(200)
=>#0	block in <top (required)> (4 levels) at ~/Developer/roadrunner/spec/requests/follows_spec.rb:14
  #1	[C] BasicObject#instance_exec at ~/.rvm/gems/ruby-2.7.6@roadrunner/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:263
  # and 48 frames (use `bt' command for all frames)
(rdbg) edit    # command
command: nova -w
   path: /Users/mzagaja/Developer/roadrunner/spec/requests/follows_spec.rb
(rdbg) edit    # command
command: nova -w
   path: /Users/mzagaja/Developer/roadrunner/spec/requests/follows_spec.rb
(rdbg) edit    # command
command: nova -w
   path: /Users/mzagaja/Developer/roadrunner/spec/requests/follows_spec.rb
(rdbg) edit    # command
command: nova -w
   path: /Users/mzagaja/Developer/roadrunner/spec/requests/follows_spec.rb
(rdbg) exit

Expected behavior I expected the file the debugger is open in to open in Panic Nova.

mzagaja avatar Jul 21 '22 18:07 mzagaja

https://github.com/ruby/debug/blob/master/lib/debug/thread_client.rb#L646

It only calls system(...). Do you have any idea?

ko1 avatar Jul 27 '22 06:07 ko1

Please reopen it if you find another ideas.

ko1 avatar Sep 16 '22 08:09 ko1

@ko1 Thanks for your response, I have figured out the issue. I have set $EDITOR to nova -w because Panic Nova does not wait by default. This means calling system('nova', FILE_PATH) will continue execution before any changes are made.

The problem is calling system('nova -w', FILE_PATH) appears to not be valid because with the second argument system treats nova -w as the command instead of nova with the argument -w. Therefore working commands would be:

system('nova', '-w', FILE_PATH)
system("nova -w #{FILE_PATH}")

I am happy to make a pull request to suggest this change to the debug source you mention if it makes sense to you. Othewrise if this behavior seems wrong by Panic Nova, I can file a support ticket with them, they are usually responsive.

mzagaja avatar Sep 26 '22 14:09 mzagaja

Ah I see. It is a bug of debug.gem. I'll try it later (not sure when I can fix it) or patch is welcome.

ko1 avatar Oct 04 '22 08:10 ko1

Maybe we should Shellwords.split before calling system?

diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb
index 5f2d100..858fc0d 100644
--- a/lib/debug/thread_client.rb
+++ b/lib/debug/thread_client.rb
@@ -2,6 +2,7 @@

 require 'objspace'
 require 'pp'
+require 'shellwords'

 require_relative 'color'

@@ -643,7 +644,7 @@ module DEBUGGER__
         if editor = (ENV['RUBY_DEBUG_EDITOR'] || ENV['EDITOR'])
           puts "command: #{editor}"
           puts "   path: #{path}"
-          system(editor, path)
+          system(*Shellwords.split(editor), path)
         else
           puts "can not find editor setting: ENV['RUBY_DEBUG_EDITOR'] or ENV['EDITOR']"
         end

adam12 avatar Oct 04 '22 15:10 adam12

@adam12 That seems reasonable to me. Would be happy to see this included in next release. I'm happy to PR your diff if you are too busy but figured you might want the credit since you've pretty much done the work here 😄.

mzagaja avatar Oct 18 '22 18:10 mzagaja

@mzagaja If it the patch works for you, definitely go ahead and submit a PR using it :)

adam12 avatar Oct 18 '22 23:10 adam12

I tested this locally and it worked great. PR submitted.

mzagaja avatar Oct 21 '22 22:10 mzagaja