Skip to content

Commit 76412f5

Browse files
committed
New --open=vscode mechanism
* respect existing `.vscode` directory. * Do not need `README.md` vscode-rdbg v0.0.9 or later is required to use this feature.
1 parent d3813d5 commit 76412f5

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ Also `open` command allows opening the debug port.
358358

359359
#### VSCode integration
360360

361+
([vscode-rdbg v0.0.9](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) or later is required)
362+
361363
If you don't run a debuggee Ruby process on VSCode, you can attach with VSCode later with the following steps.
362364

363365
`rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code` command).

lib/debug/server_dap.rb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

misc/README.md.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ Also `open` command allows opening the debug port.
358358

359359
#### VSCode integration
360360

361+
([vscode-rdbg v0.0.9](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg) or later is required)
362+
361363
If you don't run a debuggee Ruby process on VSCode, you can attach with VSCode later with the following steps.
362364

363365
`rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code` command).

0 commit comments

Comments
 (0)