From 3becfa1d66568ee4abb164cb236d1714335c3d6c Mon Sep 17 00:00:00 2001 From: Ruby Date: Fri, 5 May 2023 04:12:20 +0900 Subject: [PATCH] `no_lineno` config optiopn (default: false) See https://github.com/ruby/debug/issues/881 --- README.md | 3 +++ lib/debug/config.rb | 1 + lib/debug/thread_client.rb | 12 ++++++++---- test/console/config_test.rb | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5e7b72b27..c46a5d058 100644 --- a/README.md +++ b/README.md @@ -476,6 +476,7 @@ config set no_color true * `RUBY_DEBUG_NO_SIGINT_HOOK` (`no_sigint_hook`): Do not suspend on SIGINT (default: false) * `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) * CONTROL * `RUBY_DEBUG_SKIP_PATH` (`skip_path`): Skip showing/entering frames for given paths @@ -908,6 +909,8 @@ Attach mode: 'rdbg -A host port' tries to connect to host:port via TCP/IP. Other options: + -v Show version number + --version Show version number and exit -h, --help Print help --util=NAME Utility mode (used by tools) --stop-at-load Stop immediately when the debugging feature is loaded. diff --git a/lib/debug/config.rb b/lib/debug/config.rb index 1a95ce2b2..f6f1a066d 100644 --- a/lib/debug/config.rb +++ b/lib/debug/config.rb @@ -21,6 +21,7 @@ module DEBUGGER__ no_sigint_hook: ['RUBY_DEBUG_NO_SIGINT_HOOK', "UI: Do not suspend on SIGINT", :bool, "false"], 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"], # control setting skip_path: ['RUBY_DEBUG_SKIP_PATH', "CONTROL: Skip showing/entering frames for given paths", :path], diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb index e28e1c0cf..57a802615 100644 --- a/lib/debug/thread_client.rb +++ b/lib/debug/thread_client.rb @@ -469,10 +469,14 @@ def get_src(frame, if file_lines = frame.file_lines frame_line = frame.location.lineno - 1 - lines = file_lines.map.with_index do |e, i| - cur = i == frame_line ? '=>' : ' ' - line = colorize_dim('%4d|' % (i+1)) - "#{cur}#{line} #{e}" + if CONFIG[:no_lineno] + lines = file_lines + else + lines = file_lines.map.with_index do |e, i| + cur = i == frame_line ? '=>' : ' ' + line = colorize_dim('%4d|' % (i+1)) + "#{cur}#{line} #{e}" + end end unless start_line diff --git a/test/console/config_test.rb b/test/console/config_test.rb index 9925c017d..589be7488 100644 --- a/test/console/config_test.rb +++ b/test/console/config_test.rb @@ -411,4 +411,23 @@ def test_debugger_takes_log_level_config_from_config_option end end end + + class NoLinenoTest < ConsoleTestCase + def program + <<~RUBY + 1| a = :a + 2| b = :b + 3| c = :c + RUBY + end + + def test_no_lineno + debug_code(program) do + type 'config set no_lineno true' + type 'list' + assert_no_line_text(/^\s*\d/) + type 'c' + end + end + end end