Skip to content

Commit fdd7bae

Browse files
committed
Optionally put the opening paren on the previous line for args
1 parent b7579f6 commit fdd7bae

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct Config {
1919
pub newline_style: ::NewlineStyle,
2020
pub fn_brace_style: ::BraceStyle,
2121
pub fn_return_indent: ::ReturnIndent,
22+
pub fn_args_paren_newline: bool,
2223
pub struct_trailing_comma: bool,
2324
pub struct_lit_trailing_comma: ::lists::SeparatorTactic,
2425
}

src/default.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ tab_spaces = 4
55
newline_style = "Unix"
66
fn_brace_style = "SameLineWhere"
77
fn_return_indent = "WithArgs"
8+
fn_args_paren_newline = true
89
struct_trailing_comma = true
910
struct_lit_trailing_comma = "Vertical"

src/items.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,26 @@ impl<'a> FmtVisitor<'a> {
130130
let ret_str = self.rewrite_return(&fd.output);
131131

132132
// Args.
133-
let (one_line_budget, multi_line_budget, arg_indent) =
134-
self.compute_budgets_for_args(&mut result, indent, ret_str.len(), newline_brace);
133+
let (one_line_budget, multi_line_budget, mut arg_indent) =
134+
self.compute_budgets_for_args(&result, indent, ret_str.len(), newline_brace);
135135

136136
debug!("rewrite_fn: one_line_budget: {}, multi_line_budget: {}, arg_indent: {}",
137137
one_line_budget, multi_line_budget, arg_indent);
138138

139-
result.push('(');
139+
if one_line_budget <= 0 {
140+
if config!(fn_args_paren_newline) {
141+
result.push('\n');
142+
result.push_str(&make_indent(arg_indent));
143+
arg_indent = arg_indent + 1;
144+
result.push('(');
145+
} else {
146+
result.push_str("(\n");
147+
result.push_str(&make_indent(arg_indent));
148+
}
149+
} else {
150+
result.push('(');
151+
}
152+
140153
result.push_str(&self.rewrite_args(&fd.inputs,
141154
explicit_self,
142155
one_line_budget,
@@ -330,7 +343,7 @@ impl<'a> FmtVisitor<'a> {
330343
}
331344

332345
fn compute_budgets_for_args(&self,
333-
result: &mut String,
346+
result: &String,
334347
indent: usize,
335348
ret_str_len: usize,
336349
newline_brace: bool)
@@ -365,8 +378,6 @@ impl<'a> FmtVisitor<'a> {
365378

366379
// Didn't work. we must force vertical layout and put args on a newline.
367380
if let None = budgets {
368-
result.push('\n');
369-
result.push_str(&make_indent(indent + 4));
370381
// 6 = new indent + `()`
371382
let used_space = indent + 6;
372383
let max_space = config!(ideal_width) + config!(leeway);
@@ -375,7 +386,7 @@ impl<'a> FmtVisitor<'a> {
375386
// TODO take evasive action, perhaps kill the indent or something.
376387
} else {
377388
// 5 = new indent + `(`
378-
budgets = Some((0, max_space - used_space, indent + 5));
389+
budgets = Some((0, max_space - used_space, indent + 4));
379390
}
380391
}
381392

0 commit comments

Comments
 (0)