Skip to content

Conversation

@sucicfilip
Copy link

@sucicfilip sucicfilip commented Dec 29, 2025

Added basic "Go to Definition" support for Rails routes in routes.rb files.
This allows navigating from route strings like 'users#archive' to the corresponding controller action. This can be expanded in another PR (e.g. adding goto definiton support for things like resource :special_user, only: [:show] - executing goto definition on :special_user would take us to SpecialUserController)

The implementation is limited in that it does not consider the exact position of the cursor. Ideally, hovering on the controller (users) would jump to the first line of the controller file, while hovering on the action (archive) would jump directly to the method. Currently, we lack cursor information to differentiate these cases.

When multiple controllers share the same name and action, for example if both Admin::UsersController#archive and UsersController#archive exist, all matching methods are returned. This could potentially be improved by using Shopify/ruby-lsp#3863 and traversing the nesting nodes. But, I believe this is not really needed. It adds a huge amount of complexity (parsing the nesting_nodes) and it doesn't guarantee results all the time. Let's say we have a setup like this:

concern :tenanted do
  get :archive, on: :collection, to: "users#archive"
end

scope module: 'tenanted' do
  concerns :tenanted
end

It is effectively impossible to determine that we need to look for Tenanted::UsersController#archive here. So I think it is better to just look for any UsersController with the #archive method and return all of them :)

recording.mp4

@sucicfilip sucicfilip requested a review from a team as a code owner December 29, 2025 10:56
@sucicfilip
Copy link
Author

I have signed the CLA!

@sucicfilip sucicfilip force-pushed the feature/routes-goto-definition branch 6 times, most recently from d2c3ac3 to 557f3c4 Compare December 29, 2025 22:47
@sucicfilip sucicfilip changed the title Implement schema goto definitions Implement basic schema goto definitions Dec 30, 2025
@sucicfilip sucicfilip force-pushed the feature/routes-goto-definition branch from 557f3c4 to 6750816 Compare December 30, 2025 14:34
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

Successfully merging this pull request may close these issues.

1 participant