diff --git a/lib/byebug/processors/pry_remote_processor.rb b/lib/byebug/processors/pry_remote_processor.rb new file mode 100644 index 00000000..98b0a022 --- /dev/null +++ b/lib/byebug/processors/pry_remote_processor.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require "byebug/core" + +module Byebug + # + # Extends the PryProcessor to make it work with Pry-Remote + # + class PryRemoteProcessor < PryProcessor + def self.start + super + + Byebug.current_context.step_out(5, true) + end + + def resume_pry + new_binding = frame._binding + + run do + return unless server + + if defined?(@pry) && @pry + @pry.repl(new_binding) + else + @pry = Pry::REPL.start_without_pry_byebug(target: new_binding, + input: input, + output: output) + end + end + rescue Errno::ECONNREFUSED + nil + end + + private + + def input + server.client.input_proxy + end + + def output + server.client.output + end + + def server + PryByebug.current_remote_server + end + end +end diff --git a/lib/pry-byebug/base.rb b/lib/pry-byebug/base.rb index 5b5c084d..ec7729bc 100644 --- a/lib/pry-byebug/base.rb +++ b/lib/pry-byebug/base.rb @@ -7,7 +7,9 @@ # module PryByebug # Reference to currently running pry-remote server. Used by the processor. - attr_accessor :current_remote_server + class << self + attr_accessor :current_remote_server + end module_function diff --git a/lib/pry-byebug/commands/exit_all.rb b/lib/pry-byebug/commands/exit_all.rb index e7d5ac2f..613ba12d 100644 --- a/lib/pry-byebug/commands/exit_all.rb +++ b/lib/pry-byebug/commands/exit_all.rb @@ -10,6 +10,7 @@ class ExitAllCommand < Pry::Command::ExitAll def process super ensure + PryByebug.current_remote_server&.teardown Byebug.stop if Byebug.stoppable? end end diff --git a/lib/pry-byebug/commands/finish.rb b/lib/pry-byebug/commands/finish.rb index 3c6ac7a4..3f5d7bfe 100644 --- a/lib/pry-byebug/commands/finish.rb +++ b/lib/pry-byebug/commands/finish.rb @@ -18,6 +18,7 @@ class FinishCommand < Pry::ClassCommand BANNER def process + PryByebug.current_remote_server&.teardown PryByebug.check_file_context(target) breakout_navigation :finish diff --git a/lib/pry-byebug/pry_ext.rb b/lib/pry-byebug/pry_ext.rb index cd37b023..d542b77a 100644 --- a/lib/pry-byebug/pry_ext.rb +++ b/lib/pry-byebug/pry_ext.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "byebug/processors/pry_processor" +require "byebug/processors/pry_remote_processor" class << Pry::REPL alias start_without_pry_byebug start @@ -8,8 +9,13 @@ class << Pry::REPL def start_with_pry_byebug(options = {}) target = options[:target] - if target.is_a?(Binding) && PryByebug.file_context?(target) - Byebug::PryProcessor.start unless ENV["DISABLE_PRY"] + if target.is_a?(Binding) && PryByebug.file_context?(target) && !ENV["DISABLE_PRY"] + if run_remote? + Byebug::PryRemoteProcessor.start + return start_without_pry_byebug(options) + end + + Byebug::PryProcessor.start else # No need for the tracer unless we have a file context to step through start_without_pry_byebug(options) @@ -17,4 +23,8 @@ def start_with_pry_byebug(options = {}) end alias start start_with_pry_byebug + + def run_remote? + PryByebug.current_remote_server + end end diff --git a/lib/pry-byebug/pry_remote_ext.rb b/lib/pry-byebug/pry_remote_ext.rb index 82da98c5..200380fb 100644 --- a/lib/pry-byebug/pry_remote_ext.rb +++ b/lib/pry-byebug/pry_remote_ext.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require "pry-remote" +require "pry-remote-reloaded" -module PryRemote +module PryRemoteReloaded # # Overrides PryRemote::Server # @@ -11,28 +11,27 @@ class Server # Override the call to Pry.start to save off current Server, and not # teardown the server right after Pry.start finishes. # + alias original_run run def run raise("Already running a pry-remote session!") if PryByebug.current_remote_server PryByebug.current_remote_server = self - setup - Pry.start @object, input: client.input_proxy, output: client.output + catch(:breakout_nav) { original_run } end # # Override to reset our saved global current server session. # - alias teardown_without_pry_byebug teardown - def teardown_with_pry_byebug - return if @torn + alias original_teardown teardown + def teardown + original_teardown - teardown_without_pry_byebug + return if @torn PryByebug.current_remote_server = nil @torn = true end - alias teardown teardown_with_pry_byebug end end