Skip to content

Commit 0caebcc

Browse files
committed
DAP: Allow debug command with ,command
* On the debug console, debug commands can type with `,command` (ex: `, info`) * Show welcome message on the debug console. Now this feature is experimental and `,command` can be changed in near future.
1 parent 6def10a commit 0caebcc

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/debug/server_dap.rb

+24-2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ def dap_setup bytes
199199
# supportsInstructionBreakpoints:
200200
)
201201
send_event 'initialized'
202+
puts <<~WELCOME
203+
Ruby REPL: You can run any Ruby expression here.
204+
Note that output to the STDOUT/ERR printed on the TERMINAL.
205+
[experimental]
206+
`,COMMAND` runs `COMMAND` debug command (ex: `,info`).
207+
`,help` to list all debug commands.
208+
WELCOME
202209
end
203210

204211
def send **kw
@@ -425,10 +432,20 @@ def process
425432
}
426433
}
427434

435+
when 'evaluate'
436+
expr = req.dig('arguments', 'expression')
437+
if /\A\s*,(.+)\z/ =~ expr
438+
dbg_expr = $1
439+
send_response req,
440+
result: "",
441+
variablesReference: 0
442+
debugger do: dbg_expr
443+
else
444+
@q_msg << req
445+
end
428446
when 'stackTrace',
429447
'scopes',
430448
'variables',
431-
'evaluate',
432449
'source',
433450
'completions'
434451
@q_msg << req
@@ -449,7 +466,11 @@ def respond req, res
449466

450467
def puts result
451468
# STDERR.puts "puts: #{result}"
452-
# send_event 'output', category: 'stderr', output: "PUTS!!: " + result.to_s
469+
send_event 'output', category: 'console', output: "#{result&.chomp}\n"
470+
end
471+
472+
def ignore_output_on_suspend?
473+
true
453474
end
454475

455476
def event type, *args
@@ -586,6 +607,7 @@ def process_protocol_request req
586607
if @frame_map[frame_id]
587608
tid, fid = @frame_map[frame_id]
588609
expr = req.dig('arguments', 'expression')
610+
589611
if tc = find_waiting_tc(tid)
590612
request_tc [:dap, :evaluate, req, fid, expr, context]
591613
else

lib/debug/session.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def process_event evt
274274

275275
when :suspend
276276
enter_subsession if ev_args.first != :replay
277-
output.each{|str| @ui.puts str}
277+
output.each{|str| @ui.puts str} unless @ui.ignore_output_on_suspend?
278278

279279
case ev_args.first
280280
when :breakpoint
@@ -2069,6 +2069,10 @@ def event type, *args
20692069
end
20702070
end
20712071

2072+
def ignore_output_on_suspend?
2073+
false
2074+
end
2075+
20722076
def flush
20732077
end
20742078
end

0 commit comments

Comments
 (0)