Merged
Conversation
This was referenced Jun 22, 2023
Merged
Member
Author
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
Contributor
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
afad5cc to
0a3ed21
Compare
0bea2d4 to
a78246b
Compare
konstin
approved these changes
Jun 22, 2023
| let printed = format_module(&content)?; | ||
| let formatted_code = printed.as_code(); | ||
|
|
||
| let reformatted = |
Member
Author
There was a problem hiding this comment.
My understanding is that ensure_stability_when_formatting_twice now already asserts that reformatting the file twice yields the same result. Thanks to your refactor :)
a78246b to
ae9cadf
Compare
895d416 to
54b2b11
Compare
ae9cadf to
d2df571
Compare
Member
Author
|
Graphite rebased this pull request after merging its parent, because this pull request is set to merge when ready. |
d2df571 to
20158e7
Compare
Member
Author
|
@MichaReiser merged this pull request with Graphite. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
This PR implements formatting for non-f-string Strings that do not use implicit concatenation.
Docstring formatting is out of the scope of this PR.
Test Plan
I added a few tests for simple string literals.
Performance
Ouch. This is hitting performance somewhat hard. This is probably because we now iterate each string a couple of times:
Edit: I integrated the detection of newlines into the preferred quote detection so that we only iterate the string three time.
We can probably do better by merging the implicit string continuation with the quote detection and new line detection by iterating till the end of the string part and returning the offset. We then use our simple tokenizer to skip over any comments or whitespace until we find the first non trivia token. From there we keep continue doing this in a loop until we reach the end o the string. I'll leave this improvement for later.