Skip to content

Experimental improvements#79

Open
apiology wants to merge 219 commits intoiftheshoefritz:mainfrom
apiology:grncdr_hacks
Open

Experimental improvements#79
apiology wants to merge 219 commits intoiftheshoefritz:mainfrom
apiology:grncdr_hacks

Conversation

@apiology
Copy link
Copy Markdown
Collaborator

@apiology apiology commented May 9, 2025

  • specifically exclude non-working Solargraph versions

grncdr and others added 25 commits May 20, 2023 19:56
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.
@apiology apiology marked this pull request as draft May 9, 2025 11:43
@apiology apiology changed the title Support recent Solargraph versions Experimental improvements Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants