Shopify / Shopify/ruby-lsp-rails

CodeLens support for rails routes with constraints

Open
#543 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help-wanted
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.