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

Provide code navigation features to erb files

Open st0012 opened this issue 1 year ago • 1 comments

Motivation

This commit allows Ruby LSP to start handling requests for ERB files, such as definition, completion, hover...etc., which will give users the same level of code navigation features in ERB and Ruby.

However, certain requests are not supported:

  • formatting
  • on_type_formatting
  • diagnostics
  • code_actions

Implementation

  1. Update extension so VS Code knows it can send erb requests to Ruby LSP too
  2. Introduce ERBDocument (written by @vinistock) with a scanner that returns extracted Ruby and remaining html code (not used yet)
  3. Make the requests that don't support erb files return early
  4. Avoid assuming Object as view helper calls receiver type as it'll stop Ruby LSP from suggesting any definition candidates

Demo

https://github.com/Shopify/ruby-lsp/assets/5079556/39cd8227-721f-40c9-8b9c-66316fc098b3

Automated Tests

Manual Tests

st0012 avatar Jun 28 '24 15:06 st0012

Worth adding an ERB fixture just for ease of tophatting?

andyw8 avatar Jun 28 '24 17:06 andyw8

Hello,

Is there a recommended setup that does format on save for erb files?

robikovacs avatar Dec 14 '24 06:12 robikovacs

We don't support linting or formatting ERB yet. You can follow progress on #536.

vinistock avatar Dec 16 '24 16:12 vinistock