Skip to content

Commit fdf48d3

Browse files
committed
Signed-off-by: Hermann Mayer <[email protected]>
1 parent 9b179b7 commit fdf48d3

File tree

8 files changed

+75
-14
lines changed

8 files changed

+75
-14
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
pry-byebug-reloaded (3.10.1)
4+
pry-byebug-reloaded (3.10.2)
55
byebug (~> 11.0)
66
pry (>= 0.13, < 0.15)
77

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
return unless server
21+
22+
if defined?(@pry) && @pry
23+
@pry.repl(new_binding)
24+
else
25+
@pry = Pry::REPL.start_without_pry_byebug(target: new_binding,
26+
input: input,
27+
output: output)
28+
end
29+
end
30+
rescue Errno::ECONNREFUSED
31+
nil
32+
end
33+
34+
private
35+
36+
def input
37+
server.client.input_proxy
38+
end
39+
40+
def output
41+
server.client.output
42+
end
43+
44+
def server
45+
PryByebug.current_remote_server
46+
end
47+
end
48+
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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
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+
if run_remote?
14+
Byebug::PryRemoteProcessor.start
15+
return start_without_pry_byebug(options)
16+
end
17+
18+
Byebug::PryProcessor.start
1319
else
1420
# No need for the tracer unless we have a file context to step through
1521
start_without_pry_byebug(options)
1622
end
1723
end
1824

1925
alias start start_with_pry_byebug
26+
27+
def run_remote?
28+
PryByebug.current_remote_server
29+
end
2030
end

lib/pry-byebug/pry_remote_ext.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

3-
require "pry-remote"
3+
require "pry-remote-reloaded"
44

5-
module PryRemote
5+
module PryRemoteReloaded
66
#
77
# Overrides PryRemote::Server
88
#
@@ -11,28 +11,27 @@ class Server
1111
# Override the call to Pry.start to save off current Server, and not
1212
# teardown the server right after Pry.start finishes.
1313
#
14+
alias original_run run
1415
def run
1516
raise("Already running a pry-remote session!") if
1617
PryByebug.current_remote_server
1718

1819
PryByebug.current_remote_server = self
1920

20-
setup
21-
Pry.start @object, input: client.input_proxy, output: client.output
21+
catch(:breakout_nav) { original_run }
2222
end
2323

2424
#
2525
# Override to reset our saved global current server session.
2626
#
27-
alias teardown_without_pry_byebug teardown
28-
def teardown_with_pry_byebug
29-
return if @torn
27+
alias original_teardown teardown
28+
def teardown
29+
original_teardown
3030

31-
teardown_without_pry_byebug
31+
return if @torn
3232
PryByebug.current_remote_server = nil
3333
@torn = true
3434
end
35-
alias teardown teardown_with_pry_byebug
3635
end
3736
end
3837

lib/pry-byebug/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# Main container module for Pry-Byebug functionality
55
#
66
module PryByebug
7-
VERSION = "3.10.1"
7+
VERSION = "3.10.2"
88
end

0 commit comments

Comments
 (0)