Solargraph: Namespace conflicts in method completion

Created on 25 Nov 2018  Â·  7Comments  Â·  Source: castwide/solargraph

Given the following code:

class Foo
  def root_method; end
end

module Other
  class Foo
    def other_method; end
  end

  # @type [Foo]
  var1 = get_other_foo
  # @type [::Foo]
  var2 = get_foo
end

Since var1 is declared inside Other, its type should be resolved as the nearest match, Other::Foo. Since var2's type has a namespace prefix, its type should be the root Foo class. In v0.28.4, this works correctly when inferring the variable's type (e.g., in a hover), but requesting completions for var2 erroneously returns Other::Foo instance methods.

This bug is fixed in the master branch and is scheduled for inclusion in v0.29.0.

Most helpful comment

Oh my goodness! If you didn't say this I wouldn't aware of that /_sequel/Comment.rb doesn't exists.

Totally false alarm here. I put Comment.rb that auto generate from database (you can see others in _sequel/ dir. And it just worked.

See, I know that Solargraph doesn't well work with Rails thing. So I generate helper methods myself. I just did not generate Comment.rb yet.

I'm so sorry for this confusion.

Work here:
image

So, this issue is fixed in master as you stated.

All 7 comments

@castwide, on master I still have this issue.

@gencer Do you have an example? When I test the above code, it correctly gives me Other::Foo methods for var1 and Foo methods for var2.

image

image

@castwide, I've sent you an another project. This time I included multiple files from my project. Please have a look at your email and hope you can reproduce at on your end.

BTW, When I try your example, yes, it just works. However, within my existing project it doesn't. Email sent.

Instructions:

  1. Open project and go to “app/box/v1/entities.rb”
  2. Find line 198. You will see that i assigned comment with an object.
  3. Enter there and write “comment.” You wont see my models/classess.

@gencer This case might be stretching Solargraph's limits. Neither the Comment class in app/models/comment.rb nor its superclass Sequel::Model have methods that can be detected through static analysis.

I hope to improve support for Rails conventions in particular--e.g., recognizing that has_many :users exposes a users method--but it has a long way to go.

Oh my goodness! If you didn't say this I wouldn't aware of that /_sequel/Comment.rb doesn't exists.

Totally false alarm here. I put Comment.rb that auto generate from database (you can see others in _sequel/ dir. And it just worked.

See, I know that Solargraph doesn't well work with Rails thing. So I generate helper methods myself. I just did not generate Comment.rb yet.

I'm so sorry for this confusion.

Work here:
image

So, this issue is fixed in master as you stated.

Ah! Thanks for the followup. Glad you caught it.

Fix released in v0.29.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dgutov picture dgutov  Â·  5Comments

siumennel picture siumennel  Â·  5Comments

Shougo picture Shougo  Â·  4Comments

Sam-Killgallon picture Sam-Killgallon  Â·  5Comments

dansdantas picture dansdantas  Â·  5Comments