Delegate all possible features for ERB #2563
Merged
+361
−49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Closes #2529
This PR starts delegating the remaining features that occur in the host language part of an ERB file to the appropriate language services.
The features that will be available for the host languages are now: definition, hover, signature help, document highlight, folding range and document link.
Caveats
JavaScript embedded in HTML in embedded Ruby
When using ERB in an HTML template, there's double delegation happening if the user is writing CSS or JavaScript. For example, consider this ERB template:
When typing the dot inside the
onclick
attribute, the HTML language server is in JavaScript mode, delegating all requests to the JS service.This is currently working, but I noticed that when the double-delegation is in place the completion results for JavaScript are not exactly the same as when you use a regular HTML file. I created a discussion for this because I'm not sure if this is an issue with our implementation, with VS Code or with the
html-language-features
extension.After #2561 goes in, I can add some documentation highlighting that this is a current limitation.
Semantic highlighting
The only missing feature that the Ruby LSP does implement is semantic highlighting. It is possible to support delegation for it by firing two requests and then concatenating the responses, but that requires that the Ruby LSP server stops encoding the tokens for ERB documents, so that they can be concatenated, ordered and only then encoded in the client.
It's not very trivial and I'm not sure how semantic tokens delta would work in this case. We would probably need to re-implement delta on the client so that we could compute deltas between fully merged semantic token responses. For now, I'm going to skip semantic highlighting due to the complexity.
Other features
Request delegation can only work for features that are supported by the Ruby LSP, so references and rename support are currently missing.
Implementation
For position based requests, we just followed the exactly same approach as we did for completion. For full document requests, we need to delegate the request, run the real request on the server and merge the responses.
This allows you to get features for the mixed document, like being able to fold both the Ruby and the HTML code in an ERB template at the right places.
Automated Tests
Added tests.