ruby-lsp-rails icon indicating copy to clipboard operation
ruby-lsp-rails copied to clipboard

Implement "go to definition" for `render` calls in ERB templates

Open janko opened this issue 2 months ago • 2 comments

It's common to want to traverse through several partials while updating HTML that a controller action renders. Rails.vim has a neat gf shortcut for this. This brings the same functionality to Ruby LSP Rails, by implementing "go to definition" support for render calls inside ERB templates.

https://github.com/user-attachments/assets/51080039-4655-4de5-84d1-4307da8a1802

It supports partial name passed as positional argument, or via :partial, :layout, and :spacer_template keyword arguments. It even handles :variants, :formats, and :handlers options, as well as :template for rendering non-partial templates.

The initial implementation mimicked the template lookup logic inside the language server. However, that turned out to be more complex and didn't handle custom view_paths. So, I ended up calling ActionView::LookupContext to perform the actual template lookup on the server. I also needed to determine the controller from the template directory in a way that handles custom view_paths, as well as handle controllerless template directories.

To avoid the overhead of booting the Rails process too many times in tests, I updated the test helpers to allow sending multiple textDocument/definition requests to the same server.

janko avatar Oct 28 '25 20:10 janko

@rafaelfranca I believe I addressed all your feedback and fixed typechecking.

janko avatar Nov 03 '25 15:11 janko

I have signed the CLA!

janko avatar Nov 10 '25 13:11 janko

Very cool feature! Any plans to get this merged?

cb341 avatar Dec 15 '25 16:12 cb341