Skip to content

Commit

Permalink
Avoid completing empty input (#832)
Browse files Browse the repository at this point in the history
The candidate list for empty input is all methods + all variables +
all constants + all keywords. It's a long list that is not useful.
  • Loading branch information
st0012 authored Jan 3, 2024
1 parent 5843616 commit 812dc2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,13 @@ def retrieve_completion_data(input, bind:, doc_namespace:)
else
select_message(receiver, message, candidates.sort)
end

when /^\s*$/
# empty input
if doc_namespace
nil
else
[]
end
else
if doc_namespace
vars = (bind.local_variables | bind.eval_instance_variables).collect{|m| m.to_s}
Expand Down
7 changes: 7 additions & 0 deletions test/irb/test_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ def test_complete_constants
end
end

def test_not_completing_empty_string
assert_equal([], completion_candidates("", binding))
assert_equal([], completion_candidates(" ", binding))
assert_equal([], completion_candidates("\t", binding))
assert_equal(nil, doc_namespace("", binding))
end

def test_complete_symbol
symbols = %w"UTF-16LE UTF-7".map do |enc|
"K".force_encoding(enc).to_sym
Expand Down
6 changes: 4 additions & 2 deletions test/irb/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_right
puts 'start IRB'
LINES
start_terminal(4, 19, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
write("IR\C-i")
write("IR")
write("\C-i")
close

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

0 comments on commit 812dc2d

Please sign in to comment.