castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.87k stars 154 forks source link

method directives are not parsed when comment block starts with double hash (##) #667

Closed tatthurs closed 4 months ago

tatthurs commented 1 year ago

Problem

YARD method directives are not parsed when the defining comment block begins with a double hash ##.

Reproduction

Paste the following into https://solargraph.org/demo and note that foos will autocomplete with signature information, but foobar will not:

# This editor uses solargraph-rails to provide Ruby code completion.
# Code suggestions include the core Ruby library, local class and variable
# definitions, and hints from YARD documentation.
# Hit ctrl+space anywhere in code to get context-aware suggestions.

str = 'Hello, world!'
# Try entering `str.` and hitting ctrl+space to see String instance methods.

class Bar
  ##
  # @!method foobar()
  #   @return [String]
  define_method :foobar do
    "foobar"
  end

  #
  # @!method foos()
  #   @return [String]
  define_method :foos do
    "foos"
  end
end

class Foo
  include Bar
  def bar
    # this will autocomplete with type signature information
    foos
    # this will not
    foobar
  end
end

foo = Foo.new
# Try entering `foo.` and hitting ctrl+space to see Foo instance methods.
tatthurs commented 1 year ago

There is an existing parsing test for multiple hash prefixes: https://github.com/castwide/solargraph/blob/d48f3963d1ce19b369efbc7f0327b27767fc7b0c/spec/source_spec.rb#L290-L300

tatthurs commented 1 year ago

There isn't anything special about double hash -- any number of hashes > 1 will reproduce the issue.

tatthurs commented 1 year ago

Interestingly, type annotations seem unaffected by this. Eg:

  ##
  # @return [Number]
  def baz
    "baz"
  end

works as expected and shows signature information.

castwide commented 12 months ago

Confirmed. I'll work on a fix.

castwide commented 7 months ago

Fix released in v0.50.0.