Open
Conversation
This (as far as I know) matches what Rails will do when it doesn't understand a database type.
This a more accurate represenation of what ActiveRecord actually does at runtime, and therefore gives better code suggestions when dealing with associations and model classes. I've settled on this as being the best compromise after trying a few different approaches. There are two "challenges" that I believe can't be met any other way (at this time). 1. It is not possible to write a return type annotation for the methods of various ActiveRecord mixins that will be correct for both a model class (e.g. Person.where) and relation (e.g. people.where). [0], [1] 2. It is not possible to represent ActiveRecords "class methods are also relation methods" behaviour without model-specific relation types. It's conceivable that Solargraph could change it's interpretation of [self] on class methods to solve the first challenge, but the second one really forces our hand. In order to represent this correctly, Solargraph would need support for method-missing delegation, **and** delegating those missing methods to an associated/generic type. Given @castwide is working on RBS support and the Ruby ecosystem is likely to move that way in the future, it seems pragmatic to eat the cost repetition / manual labour in this gem rather than try to push YARD types into supporting that degree of type-level programming. 😅 [0]: castwide/solargraph#592 [1]: lsegal/yard#1257
Setting this binding the models hidden relation type makes it possible to refer to other scopes and the ActiveRecord API with correct types when defining a scope.
This fixes errors when the typecheck reporter is enabled.
The binder is expected to be a Solargraph::ComplexType
This _should_ be easier to both maintain and contribute to.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.