-
Notifications
You must be signed in to change notification settings - Fork 926
WIP: Add an option for maximizing lines #2447
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,15 @@ configuration_option_enum! { Color: | |
Auto, | ||
} | ||
|
||
configuration_option_enum! { LineWidth: | ||
// Always format lines as short as possible (?) | ||
Minimum, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
// Use width heuristics to determine whether to reformat a line | ||
Medium, | ||
// Format lines to be as long as possible | ||
Maximum, | ||
} | ||
|
||
#[derive(Deserialize, Serialize, Clone, Debug)] | ||
pub struct WidthHeuristics { | ||
// Maximum width of the args of a function call before falling back | ||
|
@@ -235,6 +244,17 @@ impl WidthHeuristics { | |
single_line_if_else_max_width: (50.0 * max_width_ratio).round() as usize, | ||
} | ||
} | ||
|
||
pub fn maximum(max_width: usize) -> WidthHeuristics { | ||
WidthHeuristics { | ||
fn_call_width: max_width, | ||
struct_lit_width: max_width, | ||
struct_variant_width: max_width, | ||
array_width: max_width, | ||
chain_width: max_width, | ||
single_line_if_else_max_width: max_width, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fwiw, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
} | ||
|
||
impl ::std::str::FromStr for WidthHeuristics { | ||
|
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 think it is better to talk about how aggressively we put items across multiple lines, rather than 'general width of lines', which seems to invite confusion with
max_width
. So, rather than LineWidth::Minimum, we talk about making items as vertically formatted as possible, whereas Maximum is about making items maximally horizontal. (Or mutli-line vs single-line, if you prefer)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.
This is still the biggest thing holding me back from finishing up this PR. The line length heuristics are confusing. I don't think "more horizontal" vs "more vertical" even really describes the options.
use_small_heuristics: true
: (default)use_small_heuristics: false
This means that enabling heuristics leads to code being sometimes more vertical and sometimes less vertical. This makes it really hard for me to describe what
use_small_heuristics: false
does in plain English, which also makes it hard to come up with a non-boolean name for what it does :(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.
Hmm, yeah I know what you mean. The logic is that with
use_small_heuristics
false, we use the same formatting for small things as we do for large things, whereas when true we do things differently depending on the size - we've never tried to frame it as making lines longer or shorted, just 'better' (easier to read, prettier, etc). I guess the trouble with describing this is that even withoutuse_small_heuristics
, the set of things which is put on one line, rather than multiple lines is somewhat arbitrary.Perhaps values like
None
(today's false),Default
(today's true), andMax
(for the new stuff) is OK. They're not very self-explanatory, but I don't think we'll do better.