Solargraph: Solargraph no longer gives autocomplete on initialization blocks

Created on 12 Sep 2020  路  2Comments  路  Source: castwide/solargraph

Lets say we have a Paket model and this model has members like id, name, password etc..

Let's declare a block:

Paket.new do |pk|
  pk. # < I expect autocomplete for the member sof Paket here. Instead none given.
end

However, If I explicitly give param yard doc, then all works:

# @param [Paket]
Paket.new do |pk|
  pk.na # < name is given as autocomplete suggestion.
end

Most helpful comment

The autocomplete suggestions will only be available with a @param tag on the call or a @yieldparam tag on the initialize function. Example:

class Paket
  # @yieldparam [self]
  def initialize; end
end

Paket.new do |p|
  p. # < recognized as a Paket
end

I assume, in your example, Paket is a subclass of ActiveRecord::Base. A more practical solution would be to add an @!override ActiveRecord::Base#initialize to supply the @yieldparam. Unfortunately, @!override doesn't work correctly with initialize methods. I'll work on a fix for it.

All 2 comments

The autocomplete suggestions will only be available with a @param tag on the call or a @yieldparam tag on the initialize function. Example:

class Paket
  # @yieldparam [self]
  def initialize; end
end

Paket.new do |p|
  p. # < recognized as a Paket
end

I assume, in your example, Paket is a subclass of ActiveRecord::Base. A more practical solution would be to add an @!override ActiveRecord::Base#initialize to supply the @yieldparam. Unfortunately, @!override doesn't work correctly with initialize methods. I'll work on a fix for it.

Fred, you were right. It is how you said was.

I checked two different projects. It seems I've added yieldparam as you said for the initialize. That's why it is not working on current project because this project seems have older rake task I wrote recent year.

Sorry for the confusion. I will leave this issue open as you said about override issue. Please feel free to close if you think you can track this down on your own.

Gencer.

This is what I have added to other project which works:

image

Rake task:

        data += '' "
          # @yieldparam [#{prefix}#{cleaned_table}]
          def initialize
            yield self if block_given?
          end\n\n
          " ''

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tylerlu94 picture tylerlu94  路  5Comments

clmay picture clmay  路  3Comments

castwide picture castwide  路  4Comments

dgutov picture dgutov  路  5Comments

gencer picture gencer  路  3Comments