Skip to content

Commit 07e4d54

Browse files
authored
Fix irb crash on {}. completion (#764)
1 parent d3b7940 commit 07e4d54

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

lib/irb/completion.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,16 @@ def retrieve_completion_data(input, bind:, doc_namespace:)
210210
end
211211

212212
when /^([^\}]*\})\.([^.]*)$/
213-
# Proc or Hash
213+
# Hash or Proc
214214
receiver = $1
215215
message = $2
216216

217217
if doc_namespace
218-
["Proc.#{message}", "Hash.#{message}"]
218+
["Hash.#{message}", "Proc.#{message}"]
219219
else
220-
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
221220
hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
222-
select_message(receiver, message, proc_candidates | hash_candidates)
221+
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
222+
select_message(receiver, message, hash_candidates | proc_candidates)
223223
end
224224

225225
when /^(:[^:.]+)$/

lib/irb/input-method.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ def show_doc_dialog_proc
312312
return nil if result.nil? or pointer.nil? or pointer < 0
313313

314314
name = doc_namespace.call(result[pointer])
315+
# Use first one because document dialog does not support multiple namespaces.
316+
name = name.first if name.is_a?(Array)
317+
315318
show_easter_egg = name&.match?(/\ARubyVM/) && !ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
316319

317320
options = {}

test/irb/test_completion.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def test_complete_array
3737
def test_complete_hash_and_proc
3838
# hash
3939
assert_include(completion_candidates("{}.an", binding), "{}.any?")
40-
assert_equal(["Proc.any?", "Hash.any?"], doc_namespace("{}.any?", binding))
40+
assert_equal(["Hash.any?", "Proc.any?"], doc_namespace("{}.any?", binding))
4141

4242
# proc
4343
assert_include(completion_candidates("{}.bin", binding), "{}.binding")
44-
assert_equal(["Proc.binding", "Hash.binding"], doc_namespace("{}.binding", binding))
44+
assert_equal(["Hash.binding", "Proc.binding"], doc_namespace("{}.binding", binding))
4545
end
4646

4747
def test_complete_numeric

test/irb/yamatanooroti/test_rendering.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ def test_symbol_with_backtick
203203
EOC
204204
end
205205

206+
def test_autocomplete_with_multiple_doc_namespaces
207+
write_irbrc <<~'LINES'
208+
puts 'start IRB'
209+
LINES
210+
start_terminal(4, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
211+
write("{}.__id_")
212+
write("\C-i")
213+
close
214+
assert_screen(<<~EOC)
215+
start IRB
216+
irb(main):001> {}.__id__
217+
}.__id__
218+
EOC
219+
end
220+
206221
def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_right
207222
rdoc_dir = File.join(@tmpdir, 'rdoc')
208223
system("bundle exec rdoc -r -o #{rdoc_dir}")

0 commit comments

Comments
 (0)