Skip to content

Commit

Permalink
Fix ri completion to always return candidates start with a given name
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Jan 12, 2024
1 parent 4e14158 commit df945bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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.sort.uniq.select {|s| s.start_with? name }
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

0 comments on commit df945bc

Please sign in to comment.