-
Notifications
You must be signed in to change notification settings - Fork 175
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
Recover from files with initial syntax errors #224
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should let the exception bubble up to to handle
and catch it there rather than making all those types nilable?
lib/ruby_lsp/document.rb
Outdated
def parse | ||
@tree = SyntaxTree.parse(@source) | ||
rescue SyntaxTree::Parser::ParseError | ||
# Do not raise if we failed to parse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we log something in the console in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's valuable, but I'll suggest doing this in a follow up PR. If we're going to log something, we should include the URI, which is currently not passed to Document
. I can create a follow up as soon as this one goes in.
Would we be able to recover from the errors if we let the handler take care of it? The complication is that we only receive the full document source once, when opening the file and then only receive incremental text changes to it. So we need to save the initial document, regardless of whether there are errors or not. |
Ah I see. Ok then 👍 |
41a74d9
to
1aeaef3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may not be the best solution for the problem. Currently, successful document parsing and document processing logic (including caching) go hand-in-hand. And that's why it's safe for the latter because it saves us the need to handle nil
in a lot of places.
If we want to make parsing part failable, we shouldn't compromise the safety we have on document processing. Instead, we should probably consider handling requests in stages, like:
1. Document parsing + storing
2. Parsing result check + early return
3. Document processing
It'll likely require structural change on the Handler
class but I think it'd be better.
Another concern is that VSCode will hang if it doesn't receive a request's response (see #149). So we may need to pay more attention on the early return's implementation and make sure it still returns something?
Update: I gave the crossed part a try and it doesn't work because requests like didOpen
do need to handle the text -> document conversion. So if we separate a request into stages, it'll just make those requests hard to understand. Also, a lot of nilable
change will disappear because #221 has been merged so the code will look less confusing.
1aeaef3
to
cea52c6
Compare
cea52c6
to
fd919d7
Compare
@st0012 the void vs nil returns has been addressed in #100. Returning The reason it was hanging in #149 is because RuboCop would print argument errors to STDOUT. Printing anything to STDOUT from inside the LSP will always put it in an endless loop. |
…rrors Recover from files with initial syntax errors
…ce_to_error_telemetry Add params and backtrace to error telemetry
Motivation
We are getting some errors on user's machines of the
document
instance beingnil
. The only possibility for this, is if we weren't able to parse the first version of the file due to syntax errors and never recovered.Implementation
This PR attempts to make this process more robust by always inserting the document into the store regardless of syntax errors. If a syntax error occurs, the
tree
will benil
, which we have to handle in requests.When edits are made to the file with syntax errors,
push_edits
will take care of re-parsing.Automated Tests
Added a couple of examples and changed some existing ones.
Manual Tests
If you wanna try this manually
def Foo
)end