Skip to content

Commit

Permalink
Allow starting debug server without opening apps
Browse files Browse the repository at this point in the history
  • Loading branch information
amomchilov committed Jan 6, 2024
1 parent ab937ac commit cd0fd93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/debug/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def self.parse_argv argv
when 'tcp'
config[:open] = true
config[:port] ||= 0
when 'vscode', 'chrome', 'cdp'
when 'vscode', 'dap', 'chrome', 'cdp'
config[:open] = f&.downcase
else
raise "Unknown option for --open: #{f}"
Expand Down
15 changes: 11 additions & 4 deletions lib/debug/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ def after_fork_parent
# do nothing
end

def vscode_setup debug_port
def vscode_setup debug_port, launch_vscode: true
require_relative 'server_dap'
UI_DAP.setup debug_port
UI_DAP.setup debug_port if launch_vscode
end
end

Expand Down Expand Up @@ -442,8 +442,10 @@ def accept
case CONFIG[:open]
when 'chrome'
chrome_setup
when 'dap-server' # Start in Debug Adapter Protocol mode without launching Visual Studio Code
vscode_setup @local_addr.inspect_sockaddr, launch_vscode: false
when 'vscode'
vscode_setup @local_addr.inspect_sockaddr
vscode_setup @local_addr.inspect_sockaddr, launch_vscode: true
end

Socket.accept_loop(socks) do |sock, client|
Expand Down Expand Up @@ -496,7 +498,12 @@ def accept
end

::DEBUGGER__.warn "Debugger can attach via UNIX domain socket (#{@sock_path})"
vscode_setup @sock_path if CONFIG[:open] == 'vscode'
case CONFIG[:open]
when 'dap-server' # Start in Debug Adapter Protocol mode without launching Visual Studio Code
vscode_setup @sock_path, launch_vscode: false
when 'vscode'
vscode_setup @sock_path, launch_vscode: true
end

begin
Socket.unix_server_loop @sock_path do |sock, client|
Expand Down
8 changes: 7 additions & 1 deletion lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1118,9 +1118,15 @@ def register_default_command
when 'vscode'
CONFIG[:open] = 'vscode'
::DEBUGGER__.open nonstop: true
when 'chrome', 'cdp'
when 'dap'
CONFIG[:open] = 'dap'
::DEBUGGER__.open nonstop: true
when 'chrome'
CONFIG[:open] = 'chrome'
::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true
when 'cdp'
CONFIG[:open] = 'cdp'
::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true
else
raise "Unknown arg: #{arg}"
end
Expand Down

0 comments on commit cd0fd93

Please sign in to comment.