ruby-lsp-rails-routes

A Ruby LSP add-on that adds go to definition from Rails route helpers to the controller action they map to.

ruby-lsp-rails already lets you jump from a *_path / *_url helper to its declaration in config/routes.rb. This add-on goes one step further: it resolves the named route to its controller action at runtime and offers the action's def line as an additional candidate. The routes.rb declaration is still offered, so both show up in the definition picker.

redirect_to users_path # go to definition -> UsersController#index (and config/routes.rb)

Requirements

  • ruby-lsp >= 0.26.0, < 0.27.0
  • ruby-lsp-rails — this add-on talks to its rails runner to resolve routes, so both must be installed.

Installation

Add the gem to your application's Gemfile:

group :development do
  gem 'ruby-lsp-rails-routes', require: false
end

Then run bundle install and restart the Ruby LSP server in your editor. The add-on is discovered automatically by Ruby LSP via the lib/ruby_lsp/**/addon.rb convention.

Scope

The route helper must be called with a self (or implicit) receiver. Route helpers reached through an explicit receiver (some_object.users_path), url_for, and polymorphic routes are not supported. Routes that do not map to a controller action (redirect, mounted Rack apps, mounted engines) are skipped.

License

MIT