Skip to content

Commit caec1c5

Browse files
committed
Use default max_lines when calling up & down
Both `up` and `down` only show 1 source line when called, I think it would be more useful if they provided more context. This removes the `max_lines: 1` kwarg when they call `show_src`. `max_lines` in `show_src` will default to `CONFIG[:show_src_lines]`[^1]. [^1]:(https://github.com/ruby/debug/blob/0b77e8294b5b220b3b2a089bf09f94808654899a/lib/debug/thread_client.rb#L510)
1 parent 0b77e82 commit caec1c5

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

lib/debug/thread_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1079,13 +1079,13 @@ def wait_next_action_
10791079
when :up
10801080
if @current_frame_index + 1 < @target_frames.size
10811081
@current_frame_index += 1
1082-
show_src max_lines: 1
1082+
show_src
10831083
show_frame(@current_frame_index)
10841084
end
10851085
when :down
10861086
if @current_frame_index > 0
10871087
@current_frame_index -= 1
1088-
show_src max_lines: 1
1088+
show_src
10891089
show_frame(@current_frame_index)
10901090
end
10911091
when :set

test/console/config_test.rb

+56-18
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,28 @@ def test_config_show_frames_set
7272
class ShowSrcLinesTest < ConsoleTestCase
7373
def program
7474
<<~RUBY
75-
1| p 1
76-
2| p 2
77-
3| p 3
78-
4| p 4
79-
5| p 5
80-
6| p 6
81-
7| p 7
82-
8| p 8
83-
9| p 9
84-
10| binding.b
85-
11| p 11
86-
12| p 12
87-
13| p 13
88-
14| p 14
89-
15| p 15
75+
1| class Foo
76+
2| def self.a
77+
3| p 1
78+
4| p 2
79+
5| p 3
80+
6| p 3
81+
7| p 5
82+
8| p 6
83+
9| p 7
84+
10| p 8
85+
11| p 9
86+
12| p 10
87+
13| b
88+
14| end
89+
15|
90+
16| def self.b
91+
17| binding.b
92+
18| p 11
93+
19| end
94+
20| end
95+
21|
96+
22| Foo.a
9097
RUBY
9198
end
9299

@@ -95,11 +102,42 @@ def test_show_src_lines_control_the_lines_displayed_on_breakpoint
95102
type 'config set show_src_lines 2'
96103
type 'continue'
97104
assert_line_text([
98-
/9| p 9/,
99-
/=> 10| binding.b/
105+
/16\| def self\.b/,
106+
/=> 17\| binding\.b/
100107
])
108+
assert_no_line_text(/15\|/)
109+
assert_no_line_text(/18\|/)
110+
type 'continue'
111+
end
112+
end
101113

102-
assert_no_line_text(/p 11/)
114+
def test_show_src_lines_control_the_lines_displayed_on_up
115+
debug_code(program) do
116+
type 'config set show_src_lines 2'
117+
type 'continue'
118+
type 'up'
119+
assert_line_text([
120+
/12\| p 10/,
121+
/=> 13\| b/,
122+
])
123+
assert_no_line_text(/11\|/)
124+
assert_no_line_text(/14\|/)
125+
type 'continue'
126+
end
127+
end
128+
129+
def test_show_src_lines_control_the_lines_displayed_on_down
130+
debug_code(program) do
131+
type 'config set show_src_lines 2'
132+
type 'continue'
133+
type 'up'
134+
type 'down'
135+
assert_line_text([
136+
/16\| def self\.b/,
137+
/=> 17\| binding\.b/
138+
])
139+
assert_no_line_text(/15\|/)
140+
assert_no_line_text(/18\|/)
103141
type 'continue'
104142
end
105143
end

0 commit comments

Comments
 (0)