Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_formatter): measure first variant of BestFitting in flat mode #2675

Merged
merged 4 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/rome_formatter/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ macro_rules! format {
///
/// ## Examples
///
/// Temporarily ignored because [BestFitting] needs to be adjusted due to the
/// `fits_element_on_line` changes in https://github.com/rome/tools/pull/2645
/// ```ignore
/// ```
/// use rome_formatter::{Formatted, LineWidth, format, format_args};
/// use rome_formatter::prelude::*;
///
Expand Down
17 changes: 10 additions & 7 deletions crates/rome_formatter/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,20 @@ impl<'a> Printer<'a> {
// Test if this variant fits and if so, use it. Otherwise try the next
// variant.

if fits_on_line(
&[variant],
args.with_print_mode(PrintMode::Expanded),
queue,
self,
) {
// Try to fit only the first variant on a single line
let mode = if index == 0 {
PrintMode::Flat
} else {
PrintMode::Expanded
};

if fits_on_line(&[variant], args.with_print_mode(mode), queue, self)
{
self.state.measured_group_fits = true;

queue.enqueue(PrintElementCall::new(
variant,
args.with_print_mode(PrintMode::Expanded),
args.with_print_mode(mode),
));
return;
}
Expand Down