Skip to content

Commit b31cd4d

Browse files
committed
add support for a frame_manager
1 parent cacb767 commit b31cd4d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module PryDebugger
2+
class BeforeSessionHook
3+
4+
def caller_bindings(target)
5+
6+
bindings = binding.callers
7+
8+
start_frames = bindings.each_with_index.select do |b, i|
9+
(b.frame_type == :method &&
10+
b.eval("self.class") == Debugger::Context &&
11+
b.eval("__method__") == :at_line)
12+
end
13+
14+
start_frame_index = start_frames.first.last
15+
bindings = bindings.drop(start_frame_index + 1)
16+
17+
bindings
18+
end
19+
20+
def call(output, target, _pry_)
21+
return if binding.callers.map(&:frame_description).include?("start")
22+
bindings = caller_bindings(target)
23+
PryStackExplorer.create_and_push_frame_manager bindings, _pry_, :initial_frame => 0
24+
end
25+
end
26+
end

lib/pry-debugger/cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
#
1212

1313
require 'pry-debugger/base'
14+
require 'pry-debugger/before_session_hook.rb'
1415
require 'pry-debugger/pry_ext'
1516
require 'pry-debugger/commands'

lib/pry-debugger/pry_ext.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ def start(target = TOPLEVEL_BINDING, options = {})
2020
end
2121
end
2222
end
23+
24+
if Pry.plugins.include?("stack_explorer")
25+
Pry.config.hooks.add_hook(:before_session, :debugger_frame_manager, PryDebugger::BeforeSessionHook.new)
26+
27+
# move default to the back of before_session
28+
default = Pry.config.hooks.get_hook(:before_session, :default)
29+
Pry.config.hooks.delete_hook(:before_session, :default)
30+
Pry.config.hooks.add_hook(:before_session, :default, default)
31+
end

0 commit comments

Comments
 (0)