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 irb_console toggleable with config update #1057

Merged
merged 2 commits into from
Feb 21, 2024
Merged
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
16 changes: 16 additions & 0 deletions lib/debug/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ def update conf
SESSION.set_no_sigint_hook old, new
end
end

if_updated old_conf, conf, :irb_console do |old, new|
if defined?(SESSION) && SESSION.active?
# irb_console is switched from true to false
if old
SESSION.deactivate_irb_integration
# irb_console is switched from false to true
else
if CONFIG[:open]
SESSION.instance_variable_get(:@ui).puts "\nIRB is not supported on the remote console."
else
SESSION.activate_irb_integration
end
end
end
end
end

private def if_updated old_conf, new_conf, key
Expand Down
10 changes: 10 additions & 0 deletions lib/debug/irb_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ def activate_irb_integration
IRB::Context.prepend(IrbPatch)
end
end

class Session
def deactivate_irb_integration
Reline.completion_proc = nil
Reline.output_modifier_proc = nil
Reline.autocompletion = false
Reline.dig_perfect_match_proc = nil
reset_ui UI_LocalConsole.new
end
end
end
22 changes: 15 additions & 7 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,19 @@ def activate ui = nil, on_fork: false
end
@tp_thread_end.enable

if CONFIG[:irb_console] && !CONFIG[:open]
require_relative "irb_integration"
thc.activate_irb_integration
end

# session start
q << true
session_server_main
end
first_q << :ok

q.pop

# For activating irb:rdbg with startup config like `RUBY_DEBUG_IRB_CONSOLE=1`
# Because in that case the `Config#if_updated` callback would not be triggered
if CONFIG[:irb_console] && !CONFIG[:open]
activate_irb_integration
end
end

def deactivate
Expand Down Expand Up @@ -942,10 +943,11 @@ def register_default_command
register_command 'irb' do |arg|
if @ui.remote?
@ui.puts "\nIRB is not supported on the remote console."
:retry
else
request_eval :irb, nil
config_set :irb_console, true
end

:retry
end

### Trace
Expand Down Expand Up @@ -1876,6 +1878,12 @@ def check_unsafe
end
end

def activate_irb_integration
require_relative "irb_integration"
thc = get_thread_client(@session_server)
thc.activate_irb_integration
end

def enter_postmortem_session exc
return unless exc.instance_variable_defined? :@__debugger_postmortem_frames

Expand Down
3 changes: 0 additions & 3 deletions lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,6 @@ def wait_next_action_
end
when :call
result = frame_eval(eval_src)
when :irb
require_relative "irb_integration"
activate_irb_integration
when :display, :try_display
failed_results = []
eval_src.each_with_index{|src, i|
Expand Down
26 changes: 26 additions & 0 deletions test/console/irb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def test_irb_command_is_disabled_in_remote_mode
assert_line_text 'IRB is not supported on the remote console.'
type 'q!'
end

debug_code(program, remote: :remote_only) do
type 'config set irb_console true'
assert_line_text 'IRB is not supported on the remote console.'
type 'q!'
end
end

def test_irb_command_switches_console_to_irb
Expand All @@ -47,6 +53,11 @@ def test_irb_command_switches_console_to_irb
type 'next'
type 'info'
assert_line_text([/a = 1/, /b = nil/])

# disable irb console
type 'config set irb_console false'
type '456'
assert_raw_line_text '(rdbg) 456'
type 'q!'
end
end
Expand All @@ -62,10 +73,25 @@ def test_irb_console_config_activates_irb
type 'next'
type 'info'
assert_line_text([/a = 1/, /b = nil/])

# disable irb console
type 'config set irb_console false'
type '456'
assert_raw_line_text '(rdbg) 456'
type 'q!'
end
ensure
ENV["RUBY_DEBUG_IRB_CONSOLE"] = nil
end

private

# assert_line_text ignores the prompt line, so we can't use it to assert the prompt transition
# assert_raw_line_text is a workaround for that
def assert_raw_line_text(expectation)
@scenario.push(Proc.new do |test_info|
assert_include(test_info.last_backlog.join, expectation)
end)
end
end
end
Loading