Skip to content

Commit e07dc8c

Browse files
committed
Revert "Revert "Appled deivid-rodriguez#339.""
This reverts commit 530e16b.
1 parent 530e16b commit e07dc8c

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require "byebug/core"
4+
5+
module Byebug
6+
#
7+
# Extends the PryProcessor to make it work with Pry-Remote
8+
#
9+
class PryRemoteProcessor < PryProcessor
10+
def self.start
11+
super
12+
13+
Byebug.current_context.step_out(5, true)
14+
end
15+
16+
def resume_pry
17+
new_binding = frame._binding
18+
19+
run do
20+
if defined?(@pry) && @pry
21+
@pry.repl(new_binding)
22+
else
23+
@pry = Pry.start_without_pry_byebug(new_binding, input: input, output: output)
24+
end
25+
end
26+
end
27+
28+
private
29+
30+
def input
31+
server.client.input_proxy
32+
end
33+
34+
def output
35+
server.client.output
36+
end
37+
38+
def server
39+
PryByebug.current_remote_server
40+
end
41+
end
42+
end

lib/pry-byebug/base.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#
88
module PryByebug
99
# Reference to currently running pry-remote server. Used by the processor.
10-
attr_accessor :current_remote_server
10+
class << self
11+
attr_accessor :current_remote_server
12+
end
1113

1214
module_function
1315

lib/pry-byebug/commands/exit_all.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ExitAllCommand < Pry::Command::ExitAll
1010
def process
1111
super
1212
ensure
13+
PryByebug.current_remote_server&.teardown
1314
Byebug.stop if Byebug.stoppable?
1415
end
1516
end

lib/pry-byebug/commands/finish.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class FinishCommand < Pry::ClassCommand
1818
BANNER
1919

2020
def process
21+
PryByebug.current_remote_server&.teardown
2122
PryByebug.check_file_context(target)
2223

2324
breakout_navigation :finish

lib/pry-byebug/pry_ext.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
# frozen_string_literal: true
22

33
require "byebug/processors/pry_processor"
4+
require "byebug/processors/pry_remote_processor"
45

56
class << Pry::REPL
67
alias start_without_pry_byebug start
78

89
def start_with_pry_byebug(options = {})
910
target = options[:target]
1011

11-
if target.is_a?(Binding) && PryByebug.file_context?(target)
12-
Byebug::PryProcessor.start unless ENV["DISABLE_PRY"]
12+
if target.is_a?(Binding) && PryByebug.file_context?(target) && !ENV["DISABLE_PRY"]
13+
run_remote? ? Byebug::PryRemoteProcessor.start : Byebug::PryProcessor.start
1314
else
1415
# No need for the tracer unless we have a file context to step through
1516
start_without_pry_byebug(options)
1617
end
1718
end
1819

20+
def run_remote?
21+
PryByebug.current_remote_server
22+
end
23+
1924
alias start start_with_pry_byebug
2025
end

0 commit comments

Comments
 (0)