Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeLens support for rails routes with constraints #543

Open
jukra opened this issue Dec 11, 2024 · 0 comments
Open

CodeLens support for rails routes with constraints #543

jukra opened this issue Dec 11, 2024 · 0 comments

Comments

@jukra
Copy link

jukra commented Dec 11, 2024

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?

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

No branches or pull requests

1 participant