Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix irb-1.9.0 crash on {}. completion #764

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ def retrieve_completion_data(input, bind:, doc_namespace:)
end

when /^([^\}]*\})\.([^.]*)$/
# Proc or Hash
# Hash or Proc
receiver = $1
message = $2

if doc_namespace
["Proc.#{message}", "Hash.#{message}"]
["Hash.#{message}", "Proc.#{message}"]
else
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
select_message(receiver, message, proc_candidates | hash_candidates)
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
select_message(receiver, message, hash_candidates | proc_candidates)
end

when /^(:[^:.]+)$/
Expand Down
3 changes: 3 additions & 0 deletions lib/irb/input-method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def show_doc_dialog_proc
return nil if result.nil? or pointer.nil? or pointer < 0

name = doc_namespace.call(result[pointer])
# Use first one because document dialog does not support multiple namespaces.
name = name.first if name.is_a?(Array)

show_easter_egg = name&.match?(/\ARubyVM/) && !ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']

options = {}
Expand Down
4 changes: 2 additions & 2 deletions test/irb/test_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def test_complete_array
def test_complete_hash_and_proc
# hash
assert_include(completion_candidates("{}.an", binding), "{}.any?")
assert_equal(["Proc.any?", "Hash.any?"], doc_namespace("{}.any?", binding))
assert_equal(["Hash.any?", "Proc.any?"], doc_namespace("{}.any?", binding))

# proc
assert_include(completion_candidates("{}.bin", binding), "{}.binding")
assert_equal(["Proc.binding", "Hash.binding"], doc_namespace("{}.binding", binding))
assert_equal(["Hash.binding", "Proc.binding"], doc_namespace("{}.binding", binding))
end

def test_complete_numeric
Expand Down
15 changes: 15 additions & 0 deletions test/irb/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ def test_symbol_with_backtick
EOC
end

def test_autocomplete_with_multiple_doc_namespaces
write_irbrc <<~'LINES'
puts 'start IRB'
LINES
start_terminal(4, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
write("{}.__id_")
write("\C-i")
close
assert_screen(<<~EOC)
start IRB
irb(main):001> {}.__id__
}.__id__
EOC
end

def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_right
rdoc_dir = File.join(@tmpdir, 'rdoc')
system("bundle exec rdoc -r -o #{rdoc_dir}")
Expand Down