-
Notifications
You must be signed in to change notification settings - Fork 428
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
Fix incorrect error reporting in recoverable mode #1654
Conversation
Oh boy, this is a huge fix, thanks! |
@let-def This is definitely a huge improvement. Consider the following file: let x = 2340
let y = 234;
Before this PR, the
It didn't even include the second After this PR, we get this:
It correctly has the second line. This means the editor shows errors nicely like: The error makes sense too "statements must end with semicolon". But what's interesting is if I build this PR, and run
That points to the second I'm not sure which one is better, but do you know why they are different, and if they should be unified? |
I found one pretty big difference between the recovered reported locations and the non-recovered. Here's one example:
The exact error is at the very end of the final line and the nonrecovered parser prints the location correctly. However, the recovered version only produces this AST:
You can see it ate the entire file - and merely puts one error on the first line, the first character. Is there some way we can just "catch" any parsing error that happens, and then as a final step, insert a fake extension point with that specific location of the parsing error? We could retain some small state to determine if we've ever errored, and then before returning the final AST, in recover mode, inject a fake extension point? |
First message: With the recovered AST, the location is computed inside the grammar rule. The non-recovered path tend to use the location of the token in the lexing buffer more often. There is a bit of non necessary code duplication there, we could get a uniform behavior with a bit of refactoring. Second message: This case is worrying. I would like to experiment using the same approach for Reason. A benefit of this strategy is that it gives near perfect context information for completion, where the first parsing error is likely under or after the text cursor... And the errors are transmitted as you suggest. |
Error were not reported properly in recoverable mode (... because I forgot one step of menhir checkpoint interpretation when recovering, my bad 👎).
The first patch helped me make recovery code a bit more local but is not necessary, only the second one matters.
With this patch, errors in editors should be as good as error in batch mode (otherwise it deserves an issue).