diff --git a/lib/debug/session.rb b/lib/debug/session.rb index 3a101d6ee..66ceeb67f 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -739,8 +739,15 @@ def register_default_command # * `whereami` # * Show the current frame with source code. - register_command 'whereami', unsafe: false do - request_tc [:show, :whereami] + # * `whereami -n` + # * Show the current frame with source code without line numbers. + register_command 'whereami', unsafe: false do |arg| + case arg ? arg.strip : nil + when "-n" + request_tc [:show, :whereami, {no_lineno: true}] + else + request_tc [:show, :whereami] + end end # * `edit` diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb index 0a92fe356..7bfabe0d6 100644 --- a/lib/debug/thread_client.rb +++ b/lib/debug/thread_client.rb @@ -466,11 +466,13 @@ def get_src(frame, max_lines:, start_line: nil, end_line: nil, - dir: +1) + dir: +1, + no_lineno: CONFIG[:no_lineno] + ) if file_lines = frame.file_lines frame_line = frame.location.lineno - 1 - if CONFIG[:no_lineno] + if no_lineno lines = file_lines else lines = file_lines.map.with_index do |e, i| @@ -509,7 +511,7 @@ def get_src(frame, exit! end - def show_src(frame_index: @current_frame_index, update_line: false, ignore_show_line: false, max_lines: CONFIG[:show_src_lines], **options) + def show_src(frame_index: @current_frame_index, update_line: false, ignore_show_line: false, max_lines: CONFIG[:show_src_lines], no_lineno: CONFIG[:no_lineno], **options) if frame = get_frame(frame_index) begin if ignore_show_line @@ -517,7 +519,7 @@ def show_src(frame_index: @current_frame_index, update_line: false, ignore_show_ frame.show_line = nil end - start_line, end_line, lines = *get_src(frame, max_lines: max_lines, **options) + start_line, end_line, lines = *get_src(frame, max_lines: max_lines, no_lineno: no_lineno, **options) if start_line if update_line @@ -1119,7 +1121,7 @@ def wait_next_action_ show_src(update_line: true, **(args.first || {})) when :whereami - show_src ignore_show_line: true + show_src(ignore_show_line: true, **(args.first || {})) show_frames CONFIG[:show_frames] when :edit diff --git a/test/console/whereami_test.rb b/test/console/whereami_test.rb index 3d937fdea..5a6b142c5 100644 --- a/test/console/whereami_test.rb +++ b/test/console/whereami_test.rb @@ -7,26 +7,26 @@ class WhereamiTest < ConsoleTestCase def program <<~RUBY 1| a = 1 - 2| a = 1 - 3| a = 1 - 4| a = 1 - 5| a = 1 - 6| a = 1 - 7| a = 1 - 8| a = 1 - 9| a = 1 - 10| a = 1 - 11| b = 1 - 12| b = 1 - 13| b = 1 - 14| b = 1 - 15| b = 1 - 16| b = 1 - 17| b = 1 - 18| b = 1 - 19| b = 1 - 20| b = 1 - 21| c = 1 + 2| b = 1 + 3| c = 1 + 4| d = 1 + 5| e = 1 + 6| f = 1 + 7| g = 1 + 8| h = 1 + 9| i = 1 + 10| j = 1 + 11| k = 1 + 12| l = 1 + 13| m = 1 + 14| n = 1 + 15| o = 1 + 16| p = 1 + 17| q = 1 + 18| r = 1 + 19| s = 1 + 20| t = 1 + 21| u = 1 RUBY end @@ -36,20 +36,75 @@ def test_whereami_displays_current_frames_code type "list" # after 2 list commands, we should advance to the next 10 lines and not able to see the current frame's source - assert_no_line_text(/=> 1\| a = 1/) - assert_line_text(/b = 1/) + assert_no_line_text(/=> 10\| j = 1/) + assert_line_text(/k = 1/) type "whereami" # with whereami, we should see the current frame's source but have no visual outside the closest 10 lines - assert_no_line_text(/b = 1/) + assert_no_line_text(/k = 1/) assert_line_text(/=> 1\| a = 1/) type "list" # list command should work as normal after whereami is executed - assert_no_line_text(/b = 1/) - assert_line_text(/c = 1/) + assert_no_line_text(/t = 1/) + assert_line_text(/u = 1/) + + type "continue" + end + end + + def test_whereami_n_argument_removes_line_numbers + debug_code(program) do + type "whereami" + + assert_line_text([ + /1\| a = 1/, + /2\| b = 1/, + /3\| c = 1/, + /4\| d = 1/, + /5\| e = 1/, + /6\| f = 1/, + /7\| g = 1/, + /8\| h = 1/, + /9\| i = 1/, + /10\| j = 1/ + ]) + + type "whereami -n" + + # with -n there should be no line markers at all + assert_no_line_text(/\|/) + assert_line_text([ + /a = 1/, + /b = 1/, + /c = 1/, + /d = 1/, + /e = 1/, + /f = 1/, + /g = 1/, + /h = 1/, + /i = 1/, + /j = 1/ + ]) + + + # whereami should work as normal again + type "whereami" + + assert_line_text([ + /1\| a = 1/, + /2\| b = 1/, + /3\| c = 1/, + /4\| d = 1/, + /5\| e = 1/, + /6\| f = 1/, + /7\| g = 1/, + /8\| h = 1/, + /9\| i = 1/, + /10\| j = 1/ + ]) type "continue" end