Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the pry-byebug compatible with pry-remote gem #339

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions lib/byebug/processors/pry_remote_processor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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
if defined?(@pry) && @pry
@pry.repl(new_binding)
else
@pry = Pry.start_without_pry_byebug(new_binding, input: input, output: output)
end
end
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
9 changes: 7 additions & 2 deletions lib/pry-byebug/pry_ext.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# frozen_string_literal: true

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

class << Pry
alias start_without_pry_byebug start

def start_with_pry_byebug(target = TOPLEVEL_BINDING, options = {})
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"]
run_remote? ? Byebug::PryRemoteProcessor.start : Byebug::PryProcessor.start
else
# No need for the tracer unless we have a file context to step through
start_without_pry_byebug(target, options)
end
end

def run_remote?
PryByebug.current_remote_server
end

alias start start_with_pry_byebug
end