Skip to content

CodeLens support for rails routes with constraints #543

Open
@jukra

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?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions