From ad82b013f88bd7ee63448d23bf88cd8f3752fe80 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 26 Oct 2023 13:52:45 +0100 Subject: [PATCH] Support activating IRB as console with a config --- README.md | 1 + lib/debug/config.rb | 1 + lib/debug/session.rb | 5 +++++ test/console/irb_test.rb | 17 +++++++++++++++++ 4 files changed, 24 insertions(+) diff --git a/README.md b/README.md index c46a5d058..6edabe520 100644 --- a/README.md +++ b/README.md @@ -477,6 +477,7 @@ config set no_color true * `RUBY_DEBUG_NO_RELINE` (`no_reline`): Do not use Reline library (default: false) * `RUBY_DEBUG_NO_HINT` (`no_hint`): Do not show the hint on the REPL (default: false) * `RUBY_DEBUG_NO_LINENO` (`no_lineno`): Do not show line numbers (default: false) + * `RUBY_DEBUG_IRB_CONSOLE` (`irb_console`): Use IRB as the console (default: false) * CONTROL * `RUBY_DEBUG_SKIP_PATH` (`skip_path`): Skip showing/entering frames for given paths diff --git a/lib/debug/config.rb b/lib/debug/config.rb index f6f1a066d..af557a0cf 100644 --- a/lib/debug/config.rb +++ b/lib/debug/config.rb @@ -22,6 +22,7 @@ module DEBUGGER__ no_reline: ['RUBY_DEBUG_NO_RELINE', "UI: Do not use Reline library", :bool, "false"], no_hint: ['RUBY_DEBUG_NO_HINT', "UI: Do not show the hint on the REPL", :bool, "false"], no_lineno: ['RUBY_DEBUG_NO_LINENO', "UI: Do not show line numbers", :bool, "false"], + irb_console: ["RUBY_DEBUG_IRB_CONSOLE", "UI: Use IRB as the console", :bool, "false"], # control setting skip_path: ['RUBY_DEBUG_SKIP_PATH', "CONTROL: Skip showing/entering frames for given paths", :path], diff --git a/lib/debug/session.rb b/lib/debug/session.rb index 191b4e4fd..76b6d8721 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -202,6 +202,11 @@ def activate ui = nil, on_fork: false end @tp_thread_end.enable + if CONFIG[:irb_console] + require_relative "irb_integration" + thc.activate_irb_integration + end + # session start q << true session_server_main diff --git a/test/console/irb_test.rb b/test/console/irb_test.rb index 8cdf5801a..c4aaf3540 100644 --- a/test/console/irb_test.rb +++ b/test/console/irb_test.rb @@ -24,5 +24,22 @@ def test_irb_command_switches_console_to_irb type 'q!' end end + + def test_irb_console_config_activates_irb + ENV["RUBY_DEBUG_IRB_CONSOLE"] = "true" + + debug_code(program, remote: false) do + type '123' + assert_line_text 'irb:rdbg(main):002> 123' + type 'irb_info' + assert_line_text('IRB version:') + type 'next' + type 'info' + assert_line_text([/a = 1/, /b = nil/]) + type 'q!' + end + ensure + ENV["RUBY_DEBUG_IRB_CONSOLE"] = nil + end end end