Skip to content

Commit 55d6f2c

Browse files
committed
Make irb_console toggleable with config update
1. When the user sets `irb_console` to `true` through the command, the `irb:rdbg` will now be enabled the same way as typing the `irb` command. 2. When the user sets `irb_console` to `false` through the command, the `irb:rdbg` will now be disabled. 3. Users can now enable `irb:rdbg` by setting `irb_console` to `true` in their `.rdbgrc` file.
1 parent ab937ac commit 55d6f2c

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

lib/debug/config.rb

+20
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ def update conf
158158
SESSION.set_no_sigint_hook old, new
159159
end
160160
end
161+
162+
if_updated old_conf, conf, :irb_console do |old, new|
163+
if defined?(SESSION) && SESSION.active?
164+
# irb_console is switched from true to false
165+
if old
166+
Reline.completion_proc = nil
167+
Reline.output_modifier_proc = nil
168+
Reline.autocompletion = false
169+
Reline.dig_perfect_match_proc = nil
170+
SESSION.reset_ui UI_LocalConsole.new
171+
# irb_console is switched from false to true
172+
else
173+
if CONFIG[:open]
174+
SESSION.instance_variable_get(:@ui).puts "\nIRB is not supported on the remote console."
175+
else
176+
SESSION.activate_irb_integration
177+
end
178+
end
179+
end
180+
end
161181
end
162182

163183
private def if_updated old_conf, new_conf, key

lib/debug/session.rb

+15-7
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,19 @@ def activate ui = nil, on_fork: false
202202
end
203203
@tp_thread_end.enable
204204

205-
if CONFIG[:irb_console] && !CONFIG[:open]
206-
require_relative "irb_integration"
207-
thc.activate_irb_integration
208-
end
209-
210205
# session start
211206
q << true
212207
session_server_main
213208
end
214209
first_q << :ok
215210

216211
q.pop
212+
213+
# For activating irb:rdbg with startup config like `RUBY_DEBUG_IRB_CONSOLE=1`
214+
# Because in that case the `Config#if_updated` callback would not be triggered
215+
if CONFIG[:irb_console] && !CONFIG[:open]
216+
activate_irb_integration
217+
end
217218
end
218219

219220
def deactivate
@@ -942,10 +943,11 @@ def register_default_command
942943
register_command 'irb' do |arg|
943944
if @ui.remote?
944945
@ui.puts "\nIRB is not supported on the remote console."
945-
:retry
946946
else
947-
request_eval :irb, nil
947+
config_set :irb_console, true
948948
end
949+
950+
:retry
949951
end
950952

951953
### Trace
@@ -1876,6 +1878,12 @@ def check_unsafe
18761878
end
18771879
end
18781880

1881+
def activate_irb_integration
1882+
require_relative "irb_integration"
1883+
thc = get_thread_client(@session_server)
1884+
thc.activate_irb_integration
1885+
end
1886+
18791887
def enter_postmortem_session exc
18801888
return unless exc.instance_variable_defined? :@__debugger_postmortem_frames
18811889

lib/debug/thread_client.rb

-3
Original file line numberDiff line numberDiff line change
@@ -1056,9 +1056,6 @@ def wait_next_action_
10561056
end
10571057
when :call
10581058
result = frame_eval(eval_src)
1059-
when :irb
1060-
require_relative "irb_integration"
1061-
activate_irb_integration
10621059
when :display, :try_display
10631060
failed_results = []
10641061
eval_src.each_with_index{|src, i|

test/console/irb_test.rb

+26-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@
44

55
module DEBUGGER__
66
class IrbTest < ConsoleTestCase
7-
def setup
8-
@original_pager = ENV["PAGER"]
9-
ENV["PAGER"] = "cat"
10-
end
11-
12-
def teardown
13-
ENV["PAGER"] = @original_pager
14-
end
15-
167
def program
178
<<~RUBY
189
1| a = 1
@@ -26,6 +17,12 @@ def test_irb_command_is_disabled_in_remote_mode
2617
assert_line_text 'IRB is not supported on the remote console.'
2718
type 'q!'
2819
end
20+
21+
debug_code(program, remote: :remote_only) do
22+
type 'config set irb_console true'
23+
assert_line_text 'IRB is not supported on the remote console.'
24+
type 'q!'
25+
end
2926
end
3027

3128
def test_irb_command_switches_console_to_irb
@@ -38,6 +35,11 @@ def test_irb_command_switches_console_to_irb
3835
type 'next'
3936
type 'info'
4037
assert_line_text([/a = 1/, /b = nil/])
38+
39+
# disable irb console
40+
type 'config set irb_console false'
41+
type '456'
42+
assert_raw_line_text '(rdbg) 456'
4143
type 'q!'
4244
end
4345
end
@@ -53,10 +55,25 @@ def test_irb_console_config_activates_irb
5355
type 'next'
5456
type 'info'
5557
assert_line_text([/a = 1/, /b = nil/])
58+
59+
# disable irb console
60+
type 'config set irb_console false'
61+
type '456'
62+
assert_raw_line_text '(rdbg) 456'
5663
type 'q!'
5764
end
5865
ensure
5966
ENV["RUBY_DEBUG_IRB_CONSOLE"] = nil
6067
end
68+
69+
private
70+
71+
# assert_line_text ignores the prompt line, so we can't use it to assert the prompt transition
72+
# assert_raw_line_text is a workaround for that
73+
def assert_raw_line_text(expectation)
74+
@scenario.push(Proc.new do |test_info|
75+
assert_include(test_info.last_backlog.join, expectation)
76+
end)
77+
end
6178
end
6279
end

0 commit comments

Comments
 (0)