This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 666
feat(rome_formatter): will_break utility #2771
Merged
Merged
Conversation
This file contains 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
ematipico
changed the title
fix(rome_js_formatter): custom formatting for test calls
feat(rome_formatter): will_break utility
Jun 23, 2022
Deploying with Cloudflare Pages
|
ematipico
force-pushed
the
feature/will-break-functionality
branch
from
June 23, 2022 18:05
8a0c3af
to
568aca5
Compare
MichaReiser
previously requested changes
Jun 24, 2022
MichaReiser
added a commit
that referenced
this pull request
Jun 24, 2022
This PR adds the `inspect` method to `Memoized` that allows inspecting the formatted content. This can be useful in scenarios where some formatting must determine if some content will break to decide the best formatting. This is different from #2771 because the buffer should be preferred in cases where the fact whatever some content breaks is only used to determine the formatting of another element because it avoids interning/memoizing the inner content. The API shown here should be preferred when the formatting of the element itself depends on whatever its content breaks where using the `WillBreakBuffer` would need to rewind to the previous state.
MichaReiser
added a commit
that referenced
this pull request
Jun 24, 2022
This PR adds the `inspect` method to `Memoized` that allows inspecting the formatted content. This can be useful in scenarios where some formatting must determine if some content will break to decide the best formatting. This is different from #2771 because the buffer should be preferred in cases where the fact whatever some content breaks is only used to determine the formatting of another element because it avoids interning/memoizing the inner content. The API shown here should be preferred when the formatting of the element itself depends on whatever its content breaks where using the `WillBreakBuffer` would need to rewind to the previous state.
MichaReiser
added a commit
that referenced
this pull request
Jun 24, 2022
This PR adds the `inspect` method to `Memoized` that allows inspecting the formatted content. This can be useful in scenarios where some formatting must determine if some content will break to decide the best formatting. This is different from #2771 because the buffer should be preferred in cases where the fact whatever some content breaks is only used to determine the formatting of another element because it avoids interning/memoizing the inner content. The API shown here should be preferred when the formatting of the element itself depends on whatever its content breaks where using the `WillBreakBuffer` would need to rewind to the previous state.
MichaReiser
added a commit
that referenced
this pull request
Jun 24, 2022
This PR adds the `inspect` method to `Memoized` that allows inspecting the formatted content. This can be useful in scenarios where some formatting must determine if some content will break to decide the best formatting. This is different from #2771 because the buffer should be preferred in cases where the fact whatever some content breaks is only used to determine the formatting of another element because it avoids interning/memoizing the inner content. The API shown here should be preferred when the formatting of the element itself depends on whatever its content breaks where using the `WillBreakBuffer` would need to rewind to the previous state.
MichaReiser
added a commit
that referenced
this pull request
Jun 24, 2022
This PR adds the `inspect` method to `Memoized` that allows inspecting the formatted content. This can be useful in scenarios where some formatting must determine if some content will break to decide the best formatting. This is different from #2771 because the buffer should be preferred in cases where the fact whatever some content breaks is only used to determine the formatting of another element because it avoids interning/memoizing the inner content. The API shown here should be preferred when the formatting of the element itself depends on whatever its content breaks where using the `WillBreakBuffer` would need to rewind to the previous state.
ematipico
force-pushed
the
feature/will-break-functionality
branch
3 times, most recently
from
June 24, 2022 13:37
2f0b4df
to
5654902
Compare
MichaReiser
added a commit
that referenced
this pull request
Jun 24, 2022
This PR adds the `inspect` method to `Memoized` that allows inspecting the formatted content. This can be useful in scenarios where some formatting must determine if some content will break to decide the best formatting. This is different from #2771 because the buffer should be preferred in cases where the fact whatever some content breaks is only used to determine the formatting of another element because it avoids interning/memoizing the inner content. The API shown here should be preferred when the formatting of the element itself depends on whatever its content breaks where using the `WillBreakBuffer` would need to rewind to the previous state.
ematipico
force-pushed
the
feature/will-break
branch
from
June 28, 2022 11:02
f5cf7e6
to
e3b2aaa
Compare
ematipico
commented
Jun 28, 2022
@@ -176,7 +176,7 @@ impl<'buf, Context> Formatter<'buf, Context> { | |||
impl<Context> Formatter<'_, Context> { | |||
/// Take a snapshot of the state of the formatter | |||
#[inline] | |||
pub fn snapshot(&self) -> FormatterSnapshot { | |||
pub fn state_snapshot(&self) -> FormatterSnapshot { |
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.
These two functions were going in conflict with the ones created by the Buffer
trait. While using them in some cases, the compiler wasn't able to compute the correct types.
leops
reviewed
Jun 28, 2022
leops
approved these changes
Jun 29, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 adds two new APIs to the formatter:
inspect_will_break
: this API creates a new buffer where the element gets written in the main buffer, but it also uses theFormatElement::will_break
to track if the element written in the buffer breaks. The consumer has to call.finish()
to retrieve that information. This means that the information can be retrieved only after the element is written in the buffer.inspect_null
: this API creates a buffer where all the formatted elements are ignored. This can be useful to compute information before the elements are written in the main buffer.I created a couple of examples that work with the "will break" functionality.
The PR also adds a couple of bug fixes around call arguments. The checks come from prettier, and they are not aligned with it; here's the source code: https://github.com/prettier/prettier/blob/9dd761a6e491ffff3856eea47fb10b4573b351a6/src/language-js/print/call-arguments.js#L235-L244
Test Plan
cargo test
and checked that the snapshots matches prettierPR
File Based Average Prettier Similarity: 76.41%
Line Based Average Prettier Similarity: 71.98%
main
File Based Average Prettier Similarity: 76.38%
Line Based Average Prettier Similarity: 71.92%