-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
While #15359 fixed a ton of bugs with our diagnostic rendering, it did introduce one regression related to parser diagnostics. Specifically, prior to #15359, we would get the following diagnostic in one case of a syntax error:
|
12 | exept: # spellchecker:disable-line
13 | pass
14 | b = 1
| Syntax Error: Expected a statement
|
(This is from crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap
.)
Now, the ^
is missing from the above. After #15359, the caret is added, but the diagnostic is now pointing at the end of the preceding line:
|
12 | exept: # spellchecker:disable-line
13 | pass
| ^ Syntax Error: Expected a statement
14 | b = 1
|
We might be able to fix this by tweaking the ranges emitted by the parser when creating a diagnostic:
ruff/crates/ruff_python_parser/src/parser/mod.rs
Lines 489 to 492 in 96da136
self.add_error( | |
recovery_context_kind.create_error(self), | |
self.current_token_range(), | |
); |
But I think it would probably be better to fix the renderer itself so that it points to the beginning of the following line automatically.
See #15509 which is related to this issue. These issues are technically separate since this one could be fixed independently of #15509. But if #15509 is fixed, then I think this one will automatically resolve itself as well.