castwide/solargraph

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

tatthurs opened this issue · 5 comments

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.

There is an existing parsing test for multiple hash prefixes:

it "formats comments with multiple hash prefixes" do
source = Solargraph::Source.load_string(%(
##
# one
# two
class Foo; end
))
node = source.node_at(4, 7)
comments = source.comments_for(node)
expect(comments.lines.map(&:chomp)).to eq(['one', 'two'])
end

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

Interestingly, type annotations seem unaffected by this. Eg:

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

works as expected and shows signature information.

Confirmed. I'll work on a fix.

Fix released in v0.50.0.