class RDoc::RI::Driver

def complete name

def complete name
  klasses = classes.keys
  completions = []
  klass, selector, method = parse_name name
  # may need to include Foo when given Foo::
  klass_name = method ? name : klass
  if name !~ /#|\./ then
    completions.push(*klasses.grep(/^#{klass_name}/))
  elsif selector then
    completions << klass if classes.key? klass
  elsif classes.key? klass_name then
    completions << klass_name
  end
  if completions.include? klass and name =~ /#|\.|::/ then
    methods = list_methods_matching name
    if not methods.empty? then
      # remove Foo if given Foo:: and a method was found
      completions.delete klass
    elsif selector then
      # replace Foo with Foo:: as given
      completions.delete klass
      completions << "#{klass}#{selector}"
    end
    completions.push(*methods)
  end
  completions.sort
end