Skip to content

Commit 92d81c6

Browse files
committed
Introduce UI_DAP.local_to_remote_path
Breakpoint path is given by DAP client (VSCode, etc) and the path should be translated to remote file name by the mapping configulation. This patch introduce `local_to_remote_path` method to do that. Also `local_fs_map_path` is renamed to `remote_to_local_path`. fix ruby/vscode-rdbg#32
1 parent 4e853b1 commit 92d81c6

1 file changed

Lines changed: 50 additions & 25 deletions

File tree

lib/debug/server_dap.rb

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ def show_protocol dir, msg
7575
# nil: no localfs
7676
@local_fs_map = nil
7777

78-
def self.local_fs_map_path path
78+
def self.remote_to_local_path path
7979
case @local_fs_map
8080
when nil
81-
false
81+
nil
8282
when true
8383
path
8484
else # Array
@@ -92,6 +92,23 @@ def self.local_fs_map_path path
9292
end
9393
end
9494

95+
def self.local_to_remote_path path
96+
case @local_fs_map
97+
when nil
98+
nil
99+
when true
100+
path
101+
else # Array
102+
@local_fs_map.each do |(remote_path_prefix, local_path_prefix)|
103+
if path.start_with? local_path_prefix
104+
return path.sub(local_path_prefix){ remote_path_prefix }
105+
end
106+
end
107+
108+
nil
109+
end
110+
end
111+
95112
def self.local_fs_map_set map
96113
return if @local_fs_map # already setup
97114

@@ -276,21 +293,29 @@ def process
276293
end
277294

278295
when 'setBreakpoints'
279-
path = args.dig('source', 'path')
280-
SESSION.clear_line_breakpoints path
281-
282-
bps = []
283-
args['breakpoints'].each{|bp|
284-
line = bp['line']
285-
if cond = bp['condition']
286-
bps << SESSION.add_line_breakpoint(path, line, cond: cond)
287-
else
288-
bps << SESSION.add_line_breakpoint(path, line)
289-
end
290-
}
291-
send_response req, breakpoints: (bps.map do |bp| {verified: true,} end)
296+
req_path = args.dig('source', 'path')
297+
path = UI_DAP.local_to_remote_path(req_path)
298+
299+
if path
300+
SESSION.clear_line_breakpoints path
301+
302+
bps = []
303+
args['breakpoints'].each{|bp|
304+
line = bp['line']
305+
if cond = bp['condition']
306+
bps << SESSION.add_line_breakpoint(path, line, cond: cond)
307+
else
308+
bps << SESSION.add_line_breakpoint(path, line)
309+
end
310+
}
311+
send_response req, breakpoints: (bps.map do |bp| {verified: true,} end)
312+
else
313+
send_response req, success: false, message: "#{req_path} is not available"
314+
end
315+
292316
when 'setFunctionBreakpoints'
293317
send_response req
318+
294319
when 'setExceptionBreakpoints'
295320
process_filter = ->(filter_id, cond = nil) {
296321
bp =
@@ -302,19 +327,19 @@ def process
302327
else
303328
nil
304329
end
305-
{
306-
verified: !bp.nil?,
307-
message: bp.inspect,
330+
{
331+
verified: !bp.nil?,
332+
message: bp.inspect,
333+
}
308334
}
309-
}
310335

311-
SESSION.clear_catch_breakpoints 'Exception', 'RuntimeError'
336+
SESSION.clear_catch_breakpoints 'Exception', 'RuntimeError'
312337

313-
filters = args.fetch('filters').map {|filter_id|
314-
process_filter.call(filter_id)
315-
}
338+
filters = args.fetch('filters').map {|filter_id|
339+
process_filter.call(filter_id)
340+
}
316341

317-
filters += args.fetch('filterOptions', {}).map{|bp_info|
342+
filters += args.fetch('filterOptions', {}).map{|bp_info|
318343
process_filter.call(bp_info['filterId'], bp_info['condition'])
319344
}
320345

@@ -689,7 +714,7 @@ def process_dap args
689714
path = frame.realpath || frame.path
690715
source_name = path ? File.basename(path) : frame.location.to_s
691716

692-
if (path && File.exist?(path)) && (local_path = UI_DAP.local_fs_map_path(path))
717+
if (path && File.exist?(path)) && (local_path = UI_DAP.remote_to_local_path(path))
693718
# ok
694719
else
695720
ref = frame.file_lines

0 commit comments

Comments
 (0)