Use parse_lex
instead of parse
for Ruby and ERB documents
#3252
+71
−59
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
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 usingparse_lex
for Ruby and ERB documents. The difference is thatparse
only returns the AST nodes, whereasparse_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 asparse
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.