This PR adds support for the Definition request for Rails routes. This allow jumping from names route, e.g. new_user_path, to the corresponding route declaration, e.g. in routes.rb.
For Sorbet projects using the Tapioca DSL generators for routes, the Definition Lookup will return two results - one for the RBI file, and one for the actual route.
~For Shopify folk: Unfortunately this doesn't work on Core, the source location always point to a super call in routing_annotations.rb. bin/rails routes --expanded has the same problem.~ As of 2024-06-17 this is now working.
TODO:
[x] confirm there is minimal performance impact for apps with a large number of routes
[x] verify it doesn't break on older versions of Rails
Testing
It's working well on Identity, (which doesn't use Sorbet) and Code DB (which does use Sorbet).
This PR adds support for the Definition request for Rails routes. This allow jumping from names route, e.g.
new_user_path
, to the corresponding route declaration, e.g. inroutes.rb
.The implementation is based on @tenderlove's prototype in https://github.com/tenderlove/refreshing, and uses the behaviour added by @luanzeba and others in https://github.com/rails/rails/pull/47877.
Notes:
For Sorbet projects using the Tapioca DSL generators for routes, the Definition Lookup will return two results - one for the RBI file, and one for the actual route.
~For Shopify folk: Unfortunately this doesn't work on Core, the source location always point to a
super
call inrouting_annotations.rb
.bin/rails routes --expanded
has the same problem.~ As of 2024-06-17 this is now working.TODO:
Testing
It's working well on Identity, (which doesn't use Sorbet) and Code DB (which does use Sorbet).