Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate all possible features for ERB #2563

Merged
merged 1 commit into from
Sep 19, 2024
Merged

Conversation

vinistock
Copy link
Member

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:

<% @users.each do |user| %>
  <button onclick="document."></button>
<% end %>

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.

@vinistock vinistock added enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes server This pull request should be included in the server gem's release notes labels Sep 17, 2024
@vinistock vinistock self-assigned this Sep 17, 2024
@vinistock vinistock requested a review from a team as a code owner September 17, 2024 16:03
dev.yml Show resolved Hide resolved
vscode/src/client.ts Outdated Show resolved Hide resolved
vscode/src/client.ts Outdated Show resolved Hide resolved
@vinistock vinistock enabled auto-merge (squash) September 19, 2024 14:42
@vinistock vinistock merged commit 5eac211 into main Sep 19, 2024
34 checks passed
@vinistock vinistock deleted the vs-delegate-all-erb-requests branch September 19, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server This pull request should be included in the server gem's release notes vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement request delegation for ERB
3 participants