-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Handle parentheses when formatting slice expressions #5882
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
0634adc
to
98e8d42
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
let mut tokens = SimpleTokenizer::new(contents, TextRange::new(after_upper, range.end())) | ||
.skip_trivia() | ||
.skip_while(|token| token.kind == TokenKind::RParen); |
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 create a helper for this. It's not the first time we incorrectly assumed that there are never right parens. But I don't have a good idea of how, and this is cleary out of this PR's scope.
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.
An after node range search util would be nice. I did some small changes in #5885
98e8d42
to
e062233
Compare
**Summary** Fix the formatter crash with `x[(1) :: ]` and related code. **Problem** For assigning comments in slices in subscripts, we need to find the positions of the colons to assign comments before and after the colon to the respective lower/upper/step node (or dangling in that section). Formatting `x[(1) :: ]` was broken because we were looking for a `:` after the `1` but didn't consider that there could be a `)` outside the range of the lower node, which contains just the `1` and no optional parentheses. **Solution** Use the simple tokenizer directly and skip all closing parentheses. **Test Plan** I added regression tests. Closes #5733
e062233
to
46b65d0
Compare
## Summary A bit more consistency inspired by #5882 (comment) ## Test Plan Existing tests (refactoring)
Summary Fix the formatter crash with
x[(1) :: ]
and related code.Problem For assigning comments in slices in subscripts, we need to find the positions of the colons to assign comments before and after the colon to the respective lower/upper/step node (or dangling in that section). Formatting
x[(1) :: ]
was broken because we were looking for a:
after the1
but didn't consider that there could be a)
outside the range of the lower node, which contains just the1
and no optional parentheses.Solution Use the simple tokenizer directly and skip all closing parentheses.
Test Plan I added regression tests.
Closes #5733