Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 2 additions & 55 deletions lib/debug/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,61 +401,8 @@ def initialize sock_dir: nil, sock_path: nil
end

def vscode_setup
require 'tmpdir'
require 'json'
require 'fileutils'

dir = Dir.mktmpdir("ruby-debug-vscode-")
at_exit{
FileUtils.rm_rf dir
}
Dir.chdir(dir) do
Dir.mkdir('.vscode')
open('README.rb', 'w'){|f|
f.puts <<~MSG
# Wait for starting the attaching to the Ruby process
# This file will be removed at the end of the debuggee process.
#
# Note that vscode-rdbg extension is needed. Please install if you don't have.
MSG
}
open('.vscode/launch.json', 'w'){|f|
f.puts JSON.pretty_generate({
version: '0.2.0',
configurations: [
{
type: "rdbg",
name: "Attach with rdbg",
request: "attach",
rdbgPath: File.expand_path('../../exe/rdbg', __dir__),
debugPort: @sock_path,
autoAttach: true,
}
]
})
}
end

cmds = ['code', "#{dir}/", "#{dir}/README.rb"]
cmdline = cmds.join(' ')
ssh_cmdline = "code --remote ssh-remote+[SSH hostname] #{dir}/ #{dir}/README.rb"

STDERR.puts "Launching: #{cmdline}"
env = ENV.delete_if{|k, h| /RUBY/ =~ k}.to_h

unless system(env, *cmds)
DEBUGGER__.warn <<~MESSAGE
Can not invoke the command.
Use the command-line on your terminal (with modification if you need).

#{cmdline}

If your application is running on a SSH remote host, please try:

#{ssh_cmdline}

MESSAGE
end
require_relative 'server_dap'
UI_DAP.setup @sock_path
end

def accept
Expand Down
58 changes: 58 additions & 0 deletions lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,69 @@

require 'json'
require 'irb/completion'
require 'tmpdir'
require 'json'
require 'fileutils'

module DEBUGGER__
module UI_DAP
SHOW_PROTOCOL = ENV['DEBUG_DAP_SHOW_PROTOCOL'] == '1' || ENV['RUBY_DEBUG_DAP_SHOW_PROTOCOL'] == '1'

def self.setup sock_path
dir = Dir.mktmpdir("ruby-debug-vscode-")
at_exit{
CONFIG[:skip_path] = [//] # skip all
FileUtils.rm_rf dir
}
Dir.chdir(dir) do
Dir.mkdir('.vscode')
open('README.rb', 'w'){|f|
f.puts <<~MSG
# Wait for starting the attaching to the Ruby process
# This file will be removed at the end of the debuggee process.
#
# Note that vscode-rdbg extension is needed. Please install if you don't have.
MSG
}
open('.vscode/launch.json', 'w'){|f|
f.puts JSON.pretty_generate({
version: '0.2.0',
configurations: [
{
type: "rdbg",
name: "Attach with rdbg",
request: "attach",
rdbgPath: File.expand_path('../../exe/rdbg', __dir__),
debugPort: sock_path,
autoAttach: true,
}
]
})
}
end

cmds = ['code', "#{dir}/", "#{dir}/README.rb"]
cmdline = cmds.join(' ')
ssh_cmdline = "code --remote ssh-remote+[SSH hostname] #{dir}/ #{dir}/README.rb"

STDERR.puts "Launching: #{cmdline}"
env = ENV.delete_if{|k, h| /RUBY/ =~ k}.to_h

unless system(env, *cmds)
DEBUGGER__.warn <<~MESSAGE
Can not invoke the command.
Use the command-line on your terminal (with modification if you need).

#{cmdline}

If your application is running on a SSH remote host, please try:

#{ssh_cmdline}

MESSAGE
end
end

def show_protocol dir, msg
if SHOW_PROTOCOL
$stderr.puts "\##{Process.pid}:[#{dir}] #{msg}"
Expand Down