Shopify / Shopify/ruby-lsp-rails
CodeLens support for rails routes with constraints
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 688
- Forks
- 44
- PR merge metrics
- No merged PRs in 30d
Description
Thanks for your great work on this add-on!
I noticed that I don't see the Rails routes in controllers (https://shopify.github.io/ruby-lsp/rails-add-on.html#go-to-controller-action-route) due to the routes being inside constraints (https://guides.rubyonrails.org/routing.html#request-based-constraints). If I move the route outside of the constraint and reindex, the route shows up in the CodeLens. Is it possible to extend the support for these?
I think it fails because of not having the subdomain requirement present here:
https://github.com/Shopify/ruby-lsp-rails/blob/main/lib/ruby_lsp/ruby_lsp_rails/server.rb#L193-L198
For example one my routes has these
@defaults={:subdomain=>"app", :controller=>"health", :action=>"index"},
which would not match when requirements just have the controller and action present and comparing the full hash (route.requirements == requirements)
::Rails.application.routes.from_requirements({ controller: "health", action: "index" })
=> nil
::Rails.application.routes.from_requirements({ controller: "health", action: "index", subdomain: "app" })
=>
#<ActionDispatch::Journey::Route:0x0000000133e56e18
If the full hash comparison does not give any results, could there be a fallback that just checks with controller and action or something like that?
::Rails.application.routes.routes.find { |route| route.requirements[:controller] == requirements.fetch(:controller) && route.requirements[:action] == requirements.fetch(:action) }
Or is there a way to get the subdomain context somehow in the params?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/ruby_lsp/ruby_lsp_rails/server.rb around lines 193-198 and reproduce the missing CodeLens with a route inside a Rails constraint. Inspect how route requirements are matched, then verify that the constrained controller action appears in CodeLens while preserving existing unconstrained route behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100