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

Use parse_lex instead of parse for Ruby and ERB documents #3252

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Feb 26, 2025

Motivation

This is part of #1849, which is moving forward now with the immense help of @koic.

This PR switches the LSP from using parse to using parse_lex for Ruby and ERB documents. The difference is that parse only returns the AST nodes, whereas parse_lex returns both the AST + tokenization information. That information is required for RuboCop to use the Prism AST.

Implementation

The LSP itself doesn't need the lex part of the information. We will only need it for RuboCop related things.

So I created an ast method to return the same thing as parse does and fixed all of the call sites.

Note

Parse lex is actually quite a bit slower than regular parse. However, the performance gains we will get from avoiding the double-parse for every diagnostic computation will more than compensate for this price.

We'll monitor our performance telemetry to see if there's any meaningful degradation, but I don't expect that to be the case.

Automated Tests

Updated accordingly.

Copy link
Member Author


How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock force-pushed the 02-26-use_parse_lex_instead_of_parse_for_ruby_and_erb_documents branch from 39f084f to 0611106 Compare February 26, 2025 22:11
@vinistock vinistock marked this pull request as ready for review February 26, 2025 22:12
@vinistock vinistock requested a review from a team as a code owner February 26, 2025 22:12
@vinistock vinistock added server This pull request should be included in the server gem's release notes breaking-change Non-backward compatible change labels Feb 26, 2025 — with Graphite App
@vinistock vinistock self-assigned this Feb 26, 2025
vinistock added a commit to Shopify/tapioca that referenced this pull request Feb 27, 2025
### Motivation

The changes in Shopify/ruby-lsp#3252 will be breaking because the return of `document.parse_result` will change. However, that doesn't impact Tapioca and we will not include any breaking changes that do impact Tapioca in v0.24.

Let's bump our upper requirement ahead of time, so that people can already start upgrading and so we can eliminate any windows where the Tapioca add-on wouldn't work.

### Implementation

Just bumped the upper bound to < 0.25.
@vinistock vinistock force-pushed the 02-26-use_parse_lex_instead_of_parse_for_ruby_and_erb_documents branch from 0611106 to 8b6dce7 Compare February 28, 2025 14:34
@vinistock vinistock force-pushed the 02-26-use_parse_lex_instead_of_parse_for_ruby_and_erb_documents branch from 8b6dce7 to 21a1986 Compare March 5, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Non-backward compatible change server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants