Skip to content

Commit df945bc

Browse files
committed
Fix ri completion to always return candidates start with a given name
1 parent 4e14158 commit df945bc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/rdoc/ri/driver.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ def complete name
744744
complete_klass name, klass, selector, method, completions
745745
complete_method name, klass, selector, completions
746746

747-
completions.sort.uniq
747+
completions.sort.uniq.select {|s| s.start_with? name }
748748
end
749749

750750
def complete_klass name, klass, selector, method, completions # :nodoc:
@@ -779,7 +779,15 @@ def complete_method name, klass, selector, completions # :nodoc:
779779
completions << "#{klass}#{selector}"
780780
end
781781

782-
completions.concat methods
782+
methods.each do |klass_sel_method|
783+
match = klass_sel_method.match(/^(.+)(#|\.|::)([^#.:]+)$/)
784+
# match[2] is `::` for class method and `#` for instance method.
785+
# To be consistent with old completion that completes `['Foo#i', 'Foo::c']` for `Foo.`,
786+
# `.` should be a wildcard for both `#` and `::` here.
787+
if match && match[2] == selector || selector == '.'
788+
completions << match[1] + selector + match[3]
789+
end
790+
end
783791
end
784792
end
785793

test/rdoc/test_rdoc_ri_driver.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def test_complete
537537
assert_equal %w[ Foo::Bar], @driver.complete('Foo::B')
538538

539539
assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#'
540-
assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.'
540+
assert_equal %w[Foo.Bar Foo.bar], @driver.complete('Foo.'), 'Foo.'
541541
assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::'
542542

543543
assert_equal %w[ Foo::bar], @driver.complete('Foo::b'), 'Foo::b'
@@ -548,7 +548,9 @@ def test_complete_ancestor
548548

549549
assert_equal %w[Foo::Bar#i_method], @driver.complete('Foo::Bar#')
550550

551-
assert_equal %w[Foo::Bar#i_method Foo::Bar::c_method Foo::Bar::new],
551+
assert_equal %w[Foo::Bar::c_method Foo::Bar::new], @driver.complete('Foo::Bar::')
552+
553+
assert_equal %w[Foo::Bar.c_method Foo::Bar.i_method Foo::Bar.new],
552554
@driver.complete('Foo::Bar.')
553555
end
554556

0 commit comments

Comments
 (0)