Skip to content

Commit 20b4645

Browse files
committed
skip cleanup code
fix #431
1 parent 237349a commit 20b4645

File tree

2 files changed

+60
-55
lines changed

2 files changed

+60
-55
lines changed

lib/debug/server.rb

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -401,61 +401,8 @@ def initialize sock_dir: nil, sock_path: nil
401401
end
402402

403403
def vscode_setup
404-
require 'tmpdir'
405-
require 'json'
406-
require 'fileutils'
407-
408-
dir = Dir.mktmpdir("ruby-debug-vscode-")
409-
at_exit{
410-
FileUtils.rm_rf dir
411-
}
412-
Dir.chdir(dir) do
413-
Dir.mkdir('.vscode')
414-
open('README.rb', 'w'){|f|
415-
f.puts <<~MSG
416-
# Wait for starting the attaching to the Ruby process
417-
# This file will be removed at the end of the debuggee process.
418-
#
419-
# Note that vscode-rdbg extension is needed. Please install if you don't have.
420-
MSG
421-
}
422-
open('.vscode/launch.json', 'w'){|f|
423-
f.puts JSON.pretty_generate({
424-
version: '0.2.0',
425-
configurations: [
426-
{
427-
type: "rdbg",
428-
name: "Attach with rdbg",
429-
request: "attach",
430-
rdbgPath: File.expand_path('../../exe/rdbg', __dir__),
431-
debugPort: @sock_path,
432-
autoAttach: true,
433-
}
434-
]
435-
})
436-
}
437-
end
438-
439-
cmds = ['code', "#{dir}/", "#{dir}/README.rb"]
440-
cmdline = cmds.join(' ')
441-
ssh_cmdline = "code --remote ssh-remote+[SSH hostname] #{dir}/ #{dir}/README.rb"
442-
443-
STDERR.puts "Launching: #{cmdline}"
444-
env = ENV.delete_if{|k, h| /RUBY/ =~ k}.to_h
445-
446-
unless system(env, *cmds)
447-
DEBUGGER__.warn <<~MESSAGE
448-
Can not invoke the command.
449-
Use the command-line on your terminal (with modification if you need).
450-
451-
#{cmdline}
452-
453-
If your application is running on a SSH remote host, please try:
454-
455-
#{ssh_cmdline}
456-
457-
MESSAGE
458-
end
404+
require_relative 'server_dap'
405+
UI_DAP.setup @sock_path
459406
end
460407

461408
def accept

lib/debug/server_dap.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,69 @@
22

33
require 'json'
44
require 'irb/completion'
5+
require 'tmpdir'
6+
require 'json'
7+
require 'fileutils'
58

69
module DEBUGGER__
710
module UI_DAP
811
SHOW_PROTOCOL = ENV['DEBUG_DAP_SHOW_PROTOCOL'] == '1' || ENV['RUBY_DEBUG_DAP_SHOW_PROTOCOL'] == '1'
912

13+
def self.setup sock_path
14+
dir = Dir.mktmpdir("ruby-debug-vscode-")
15+
at_exit{
16+
CONFIG[:skip_path] = [//] # skip all
17+
FileUtils.rm_rf dir
18+
}
19+
Dir.chdir(dir) do
20+
Dir.mkdir('.vscode')
21+
open('README.rb', 'w'){|f|
22+
f.puts <<~MSG
23+
# Wait for starting the attaching to the Ruby process
24+
# This file will be removed at the end of the debuggee process.
25+
#
26+
# Note that vscode-rdbg extension is needed. Please install if you don't have.
27+
MSG
28+
}
29+
open('.vscode/launch.json', 'w'){|f|
30+
f.puts JSON.pretty_generate({
31+
version: '0.2.0',
32+
configurations: [
33+
{
34+
type: "rdbg",
35+
name: "Attach with rdbg",
36+
request: "attach",
37+
rdbgPath: File.expand_path('../../exe/rdbg', __dir__),
38+
debugPort: sock_path,
39+
autoAttach: true,
40+
}
41+
]
42+
})
43+
}
44+
end
45+
46+
cmds = ['code', "#{dir}/", "#{dir}/README.rb"]
47+
cmdline = cmds.join(' ')
48+
ssh_cmdline = "code --remote ssh-remote+[SSH hostname] #{dir}/ #{dir}/README.rb"
49+
50+
STDERR.puts "Launching: #{cmdline}"
51+
env = ENV.delete_if{|k, h| /RUBY/ =~ k}.to_h
52+
53+
unless system(env, *cmds)
54+
DEBUGGER__.warn <<~MESSAGE
55+
Can not invoke the command.
56+
Use the command-line on your terminal (with modification if you need).
57+
58+
#{cmdline}
59+
60+
If your application is running on a SSH remote host, please try:
61+
62+
#{ssh_cmdline}
63+
64+
MESSAGE
65+
end
66+
end
67+
1068
def show_protocol dir, msg
1169
if SHOW_PROTOCOL
1270
$stderr.puts "\##{Process.pid}:[#{dir}] #{msg}"

0 commit comments

Comments
 (0)