Skip to content

Commit 812dc2d

Browse files
authored
Avoid completing empty input (#832)
The candidate list for empty input is all methods + all variables + all constants + all keywords. It's a long list that is not useful.
1 parent 5843616 commit 812dc2d

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lib/irb/completion.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,13 @@ def retrieve_completion_data(input, bind:, doc_namespace:)
406406
else
407407
select_message(receiver, message, candidates.sort)
408408
end
409-
409+
when /^\s*$/
410+
# empty input
411+
if doc_namespace
412+
nil
413+
else
414+
[]
415+
end
410416
else
411417
if doc_namespace
412418
vars = (bind.local_variables | bind.eval_instance_variables).collect{|m| m.to_s}

test/irb/test_completion.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ def test_complete_constants
204204
end
205205
end
206206

207+
def test_not_completing_empty_string
208+
assert_equal([], completion_candidates("", binding))
209+
assert_equal([], completion_candidates(" ", binding))
210+
assert_equal([], completion_candidates("\t", binding))
211+
assert_equal(nil, doc_namespace("", binding))
212+
end
213+
207214
def test_complete_symbol
208215
symbols = %w"UTF-16LE UTF-7".map do |enc|
209216
"K".force_encoding(enc).to_sym

test/irb/yamatanooroti/test_rendering.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_right
232232
puts 'start IRB'
233233
LINES
234234
start_terminal(4, 19, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
235-
write("IR\C-i")
235+
write("IR")
236+
write("\C-i")
236237
close
237238

238239
# This is because on macOS we display different shortcut for displaying the full doc
@@ -268,7 +269,8 @@ def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_left
268269
puts 'start IRB'
269270
LINES
270271
start_terminal(4, 12, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
271-
write("IR\C-i")
272+
write("IR")
273+
write("\C-i")
272274
close
273275
assert_screen(<<~EOC)
274276
start IRB

0 commit comments

Comments
 (0)