diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index 08c4d08f81..a227de2521 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -744,7 +744,7 @@ def complete name complete_klass name, klass, selector, method, completions complete_method name, klass, selector, completions - completions.sort.uniq + completions.uniq.select {|s| s.start_with? name }.sort end def complete_klass name, klass, selector, method, completions # :nodoc: @@ -779,7 +779,15 @@ def complete_method name, klass, selector, completions # :nodoc: completions << "#{klass}#{selector}" end - completions.concat methods + methods.each do |klass_sel_method| + match = klass_sel_method.match(/^(.+)(#|\.|::)([^#.:]+)$/) + # match[2] is `::` for class method and `#` for instance method. + # To be consistent with old completion that completes `['Foo#i', 'Foo::c']` for `Foo.`, + # `.` should be a wildcard for both `#` and `::` here. + if match && match[2] == selector || selector == '.' + completions << match[1] + selector + match[3] + end + end end end diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb index 39e6e67759..65599ecdc8 100644 --- a/test/rdoc/test_rdoc_ri_driver.rb +++ b/test/rdoc/test_rdoc_ri_driver.rb @@ -537,7 +537,7 @@ def test_complete assert_equal %w[ Foo::Bar], @driver.complete('Foo::B') assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#' - assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.' + assert_equal %w[Foo.Bar Foo.bar], @driver.complete('Foo.'), 'Foo.' assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::' assert_equal %w[ Foo::bar], @driver.complete('Foo::b'), 'Foo::b' @@ -548,7 +548,9 @@ def test_complete_ancestor assert_equal %w[Foo::Bar#i_method], @driver.complete('Foo::Bar#') - assert_equal %w[Foo::Bar#i_method Foo::Bar::c_method Foo::Bar::new], + assert_equal %w[Foo::Bar::c_method Foo::Bar::new], @driver.complete('Foo::Bar::') + + assert_equal %w[Foo::Bar.c_method Foo::Bar.i_method Foo::Bar.new], @driver.complete('Foo::Bar.') end