@@ -10,44 +10,44 @@ module UI_DAP
1010 SHOW_PROTOCOL = ENV [ 'DEBUG_DAP_SHOW_PROTOCOL' ] == '1' || ENV [ 'RUBY_DEBUG_DAP_SHOW_PROTOCOL' ] == '1'
1111
1212 def self . setup debug_port
13- dir = Dir . mktmpdir ( "ruby-debug-vscode-" )
14- at_exit {
13+ if File . directory? '.vscode'
14+ dir = Dir . pwd
15+ else
16+ dir = Dir . mktmpdir ( "ruby-debug-vscode-" )
17+ tempdir = true
18+ end
19+
20+ at_exit do
1521 CONFIG [ :skip_path ] = [ // ] # skip all
16- FileUtils . rm_rf dir
17- }
22+ FileUtils . rm_rf dir if tempdir
23+ end
24+
25+ key = rand . to_s
26+
1827 Dir . chdir ( dir ) do
19- Dir . mkdir ( '.vscode' )
20- open ( 'README.rb' , 'w' ) { |f |
21- f . puts <<~MSG
22- # Wait for starting the attaching to the Ruby process
23- # This file will be removed at the end of the debuggee process.
24- #
25- # Note that vscode-rdbg extension is needed. Please install if you don't have.
26- MSG
27- }
28- open ( '.vscode/launch.json' , 'w' ) { |f |
28+ Dir . mkdir ( '.vscode' ) if tempdir
29+
30+ # vscode-rdbg 0.0.9 or later is needed
31+ open ( '.vscode/rdbg_autoattach.json' , 'w' ) do |f |
2932 f . puts JSON . pretty_generate ( {
30- version : '0.2.0' ,
31- configurations : [
32- {
33- type : "rdbg" ,
34- name : "Attach with rdbg" ,
35- request : "attach" ,
36- rdbgPath : File . expand_path ( '../../exe/rdbg' , __dir__ ) ,
37- debugPort : debug_port ,
38- autoAttach : true ,
39- }
40- ]
33+ type : "rdbg" ,
34+ name : "Attach with rdbg" ,
35+ request : "attach" ,
36+ rdbgPath : File . expand_path ( '../../exe/rdbg' , __dir__ ) ,
37+ debugPort : debug_port ,
38+ localfs : true ,
39+ autoAttach : key ,
4140 } )
42- }
41+ end
4342 end
4443
45- cmds = [ 'code' , "#{ dir } /" , " #{ dir } /README.rb" ]
44+ cmds = [ 'code' , "#{ dir } /" ]
4645 cmdline = cmds . join ( ' ' )
47- ssh_cmdline = "code --remote ssh-remote+[SSH hostname] #{ dir } / #{ dir } /README.rb "
46+ ssh_cmdline = "code --remote ssh-remote+[SSH hostname] #{ dir } /"
4847
4948 STDERR . puts "Launching: #{ cmdline } "
5049 env = ENV . delete_if { |k , h | /RUBY/ =~ k } . to_h
50+ env [ 'RUBY_DEBUG_AUTOATTACH' ] = key
5151
5252 unless system ( env , *cmds )
5353 DEBUGGER__ . warn <<~MESSAGE
0 commit comments