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 ri completion to always return candidates start with a given name #1082

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions test/rdoc/test_rdoc_ri_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand Down