Solargraph: autocompletion does not work if array given for an object

Created on 18 Nov 2018  路  16Comments  路  Source: castwide/solargraph

When I declare type for solargraph and fetch an object from an array, autocompletion does not work. See here:

image

If I do this by giving a method or a static member then it works:

image

Basically, anything[] type does not support autocomplete. I cannot see methods in it.

Sample:

    # @type [Reserve]
    source = Reserve[source_id]
    # @type [Reserve]
    another = anonymous_method()

    source. # does not work.
    another. # works.

Most helpful comment

@gencer The bug related to your last email is being tracked in #108. The fix is scheduled for release in v0.29.0.

All 16 comments

@castwide, I'm not sure if this and above related to this gem or vscode extension but here is another issue:

first

In your first screenshot, it looks like def perform lacks an end. Solargraph will attempt to correct for parser errors while the file's being edited, but is sometimes unable to do so. Here are my results with and without a closing end:

image

image

If your second screenshot isn't inside an unclosed method definition, that could explain why it works.

The third screenshot might also be due to a similar parser error (if without end), although Solargraph should be able to detect and correct it in most cases:

image

It is interesting that it work for you.

I had end's already. But i figured it out why it is not working. I had a rescue at bottom. See this GIF:

first

As you can see, If I have a rescue, if and source. does not work. If I remove rescue part it just works both for if and source.

Thanks for the followup. I was able to reproduce the problem with rescue. I'll work on a fix.

Fortunately, the new source mapper made this relatively simple to fix. rescue nodes work in the master branch. There was a related issue with explicit begin nodes which is also fixed. I'll include the changes in gem version 0.29.0.

I'm happy to hear that and await for the new version.

Thanks!

@castwide, does this fix currently in master?

@gencer It should, yes. I just tested it again on my checkout.

@castwide Just wanted to be sure. Here is another issue:

If you assign a variable and tell solargraph of its type but use with a condition, autocomplete does not work.

first

Basically:

# @type [Array<Object>]
a = b
a. # <- auto complete works and Object get listed.

---

# @type [Array<Object>]
a = b unless b.nil?
a. # <- autocomplete does not work because we used unless/if.

Update: This can be a little tricky. See, We can use multiple if's for same variable. However, at least the first one should be used. Because whatever I return from a File, Folder or another object, Comments are always have same methods.

Confirmed. It's a minor bug that's also related to the new source mapper. I'll have it fixed in master shortly and will include the fix in v0.29.0.

@castwide one more question. Is there any way to use YARD documentation for attr_'s?

For example:

class User
   # @type [Comment]
   attr_reader :comment
end

user = User.new
user.comment. # <- I expect Comment object methods here but it does not work.

Attributes are kinds of methods, so you should use @return instead of @type.

class User
  # @return [Comment]
  attr_reader :comment
end

@castwide, Gotcha. Sorry for this.

I also send you an e-mail. Sample video + Sample project. There is an issue with autocomplete when nested classes used. You can watch there and test yourself.

Gencer.

@gencer The bug related to your last email is being tracked in #108. The fix is scheduled for release in v0.29.0.

Fix released in v0.29.0.

@castwide, if you get an e-mail (as notification) about this issue, please ignore it. My bad.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taylorthurlow picture taylorthurlow  路  4Comments

patilarpith picture patilarpith  路  5Comments

tylerlu94 picture tylerlu94  路  5Comments

dewetblomerus picture dewetblomerus  路  5Comments

castwide picture castwide  路  4Comments