-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.first and .last on has_many associations are missing return types #34
Comments
LSP logs show that the server responds to the request for autocompletion of methods on the association with many items from
|
Most methods are missing return types. Type information is something that needs to be solved somehow. The simplest fix right now is to add types to https://github.com/iftheshoefritz/solargraph-rails/blob/main/lib/solargraph/rails/types.yml. But I'm not sure how sustainable that is, because there are a lot of methods in Rails, and filling them up by hand is a lot of manual labor. We might somehow automate this by writing a test suite and tracing method types while the suite runs. One example of this is Ruby 3.1 built-in type checker that has a mode for generating RBS type signatures from runtime execution https://evilmartians.com/chronicles/climbing-steep-hills-or-adopting-ruby-types. But RBS is Ruby 3 specific, and we'd have o port it to solaragraph type definitions so that this works on older versions of Ruby, at least until solargraph catches up with the Ruby vision of type checking |
Hmmm... I had this working in previous versions of solargraph-rails. With I see we still have the code to set the type on the collection method |
Interesting 🤔 I didn’t know it was working before. Maybe return type needs to be adjusted |
Your code at
which is converted to a YARD comment:
My best guess is that something else is overriding the return values on the pins created in |
The mystery deepens. I rolled back to solargraph 0.3.1 and I still don't see this working. Here is what I definitely had in the past: In the GIF here: you can see the behaviour that I want (watch the whole thing, I only demonstrate this late in the gif). However that GIF was made when I returned the association type In that issue I document how running I would swear that (at some point after I realised that All of that said, going back to the GIF, |
I tested with castwide/solargraph#585, but still |
@iftheshoefritz (and anybody else following) not sure if you saw my comments here castwide/solargraph#585 (comment) but I really would love to get some feedback on whether my "hacks" branches work well for other codebases. I want to open PRs and get everything merged upstream in solargraph and here, but I'm a bit pressed for time right now. |
@grncdr I'll check the hacks out shortly |
Describe the bug
Given:
and
MyOtherModel
has an attribute.my_attribute
I expect to be able to autocomplete the entire chain:
MyModel.new.my_other_models.first.my_attribute
I can autocomplete to
MyModel.my_other_models.first
, but the returned object does not have sufficient information to allow me to reachmy_attribute
.To Reproduce
Create a rails project with solargraph-rails 1.0.0.pre.1 installed and set up the models above.
Debug log
Run the following command in the project you are having problems:
The text was updated successfully, but these errors were encountered: