Skip to content

Commit 03f3110

Browse files
authored
Merge pull request #1082 from tompng/reline_readline_completion_fix
Fix ri completion to always return candidates start with a given name
2 parents e93905f + acaf13d commit 03f3110

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
@@ -754,7 +754,7 @@ def complete name
754754
complete_klass name, klass, selector, method, completions
755755
complete_method name, klass, selector, completions
756756

757-
completions.sort.uniq
757+
completions.uniq.select {|s| s.start_with? name }.sort
758758
end
759759

760760
def complete_klass name, klass, selector, method, completions # :nodoc:
@@ -789,7 +789,15 @@ def complete_method name, klass, selector, completions # :nodoc:
789789
completions << "#{klass}#{selector}"
790790
end
791791

792-
completions.concat methods
792+
methods.each do |klass_sel_method|
793+
match = klass_sel_method.match(/^(.+)(#|\.|::)([^#.:]+)$/)
794+
# match[2] is `::` for class method and `#` for instance method.
795+
# To be consistent with old completion that completes `['Foo#i', 'Foo::c']` for `Foo.`,
796+
# `.` should be a wildcard for both `#` and `::` here.
797+
if match && match[2] == selector || selector == '.'
798+
completions << match[1] + selector + match[3]
799+
end
800+
end
793801
end
794802
end
795803

test/rdoc/test_rdoc_ri_driver.rb

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

562562
assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#'
563-
assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.'
563+
assert_equal %w[Foo.Bar Foo.bar], @driver.complete('Foo.'), 'Foo.'
564564
assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::'
565565

566566
assert_equal %w[ Foo::bar], @driver.complete('Foo::b'), 'Foo::b'
@@ -571,7 +571,9 @@ def test_complete_ancestor
571571

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

574-
assert_equal %w[Foo::Bar#i_method Foo::Bar::c_method Foo::Bar::new],
574+
assert_equal %w[Foo::Bar::c_method Foo::Bar::new], @driver.complete('Foo::Bar::')
575+
576+
assert_equal %w[Foo::Bar.c_method Foo::Bar.i_method Foo::Bar.new],
575577
@driver.complete('Foo::Bar.')
576578
end
577579

0 commit comments

Comments
 (0)