From 099c8c3c2bb7148d575c857d91e7d310ec1ba99b Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 1 Jul 2022 11:32:12 +0900 Subject: [PATCH] support `levels` and `startFrame` of`stackTrace` fix #637 --- lib/debug/server_dap.rb | 53 +++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index a83bed5c7..ced2811d0 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -441,6 +441,7 @@ def process_protocol_request req when 'stackTrace' tid = req.dig('arguments', 'threadId') + if tc = find_waiting_tc(tid) request_tc [:dap, :backtrace, req] else @@ -551,9 +552,10 @@ def dap_event args case type when :backtrace - result[:stackFrames].each.with_index{|fi, i| + result[:stackFrames].each{|fi| + frame_depth = fi[:id] fi[:id] = id = @frame_map.size + 1 - @frame_map[id] = [req.dig('arguments', 'threadId'), i] + @frame_map[id] = [req.dig('arguments', 'threadId'), frame_depth] if fi[:source] if src = fi[:source][:sourceReference] src_id = @src_map.size + 1 @@ -620,27 +622,36 @@ def process_dap args case type when :backtrace - event! :dap_result, :backtrace, req, { - stackFrames: @target_frames.map{|frame| - path = frame.realpath || frame.path - source_name = path ? File.basename(path) : frame.location.to_s - - if !UI_DAP.local_fs || !(path && File.exist?(path)) - ref = frame.file_lines - end + start_frame = req.dig('arguments', 'startFrame') || 0 + levels = req.dig('arguments', 'levels') || 1_000 + frames = [] + @target_frames.each_with_index do |frame, i| + next if i < start_frame + break if (levels -= 1) < 0 + + path = frame.realpath || frame.path + source_name = path ? File.basename(path) : frame.location.to_s + + if !UI_DAP.local_fs || !(path && File.exist?(path)) + ref = frame.file_lines + end - { - # id: ??? # filled by SESSION - name: frame.name, - line: frame.location.lineno, - column: 1, - source: { - name: source_name, - path: path, - sourceReference: ref, - }, - } + frames << { + id: i, # id is refilled by SESSION + name: frame.name, + line: frame.location.lineno, + column: 1, + source: { + name: source_name, + path: path, + sourceReference: ref, + }, } + end + + event! :dap_result, :backtrace, req, { + stackFrames: frames, + totalFrames: @target_frames.size, } when :scopes fid = args.shift