Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann Mayer <[email protected]>
  • Loading branch information
Jack12816 committed Dec 8, 2023
1 parent 9b179b7 commit c1862ae
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
48 changes: 48 additions & 0 deletions lib/byebug/processors/pry_remote_processor.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion lib/pry-byebug/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/pry-byebug/commands/exit_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/pry-byebug/commands/finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FinishCommand < Pry::ClassCommand
BANNER

def process
PryByebug.current_remote_server&.teardown
PryByebug.check_file_context(target)

breakout_navigation :finish
Expand Down
14 changes: 12 additions & 2 deletions lib/pry-byebug/pry_ext.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
# frozen_string_literal: true

require "byebug/processors/pry_processor"
require "byebug/processors/pry_remote_processor"

class << Pry::REPL
alias start_without_pry_byebug start

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)
end
end

alias start start_with_pry_byebug

def run_remote?
PryByebug.current_remote_server
end
end
17 changes: 8 additions & 9 deletions lib/pry-byebug/pry_remote_ext.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require "pry-remote"
require "pry-remote-reloaded"

module PryRemote
module PryRemoteReloaded
#
# Overrides PryRemote::Server
#
Expand All @@ -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

Expand Down

0 comments on commit c1862ae

Please sign in to comment.