Skip to content

Commit de59901

Browse files
committed
Merge pull request #601 from thorbenk/chains_tabbed_indent
Chains tabbed indent
2 parents 7fe9272 + d4be6a4 commit de59901

8 files changed

+55
-1
lines changed

src/chains.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
5656
} else if is_block_expr(parent, &parent_rewrite) {
5757
(parent_block_indent, false)
5858
} else {
59-
(offset + Indent::new(context.config.tab_spaces, 0), false)
59+
match context.config.chain_indent {
60+
BlockIndentStyle::Inherit => (context.block_indent, false),
61+
BlockIndentStyle::Tabbed => {
62+
(context.block_indent.block_indent(context.config), false)
63+
}
64+
BlockIndentStyle::Visual => {
65+
(offset + Indent::new(context.config.tab_spaces, 0), false)
66+
}
67+
}
6068
};
6169

6270
let max_width = try_opt!((width + offset.width()).checked_sub(indent.width()));

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ create_config! {
294294
report_fixme: ReportTactic, ReportTactic::Never,
295295
"Report all, none or unnumbered occurrences of FIXME in source file comments";
296296
chain_base_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on chain base";
297+
chain_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indentation of chain";
297298
reorder_imports: bool, false, "Reorder import statements alphabetically";
298299
single_line_if_else: bool, false, "Put else on same line as closing brace for if statements";
299300
format_strings: bool, true, "Format string literals, or leave as is";

tests/source/chains-indent-inherit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// rustfmt-chain_indent: Inherit
2+
3+
fn test() {
4+
let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it();
5+
}

tests/source/chains-indent-tabbed.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// rustfmt-chain_indent: Tabbed
2+
3+
fn test() {
4+
let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it();
5+
}

tests/source/chains-indent-visual.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// rustfmt-chain_indent: Visual
2+
3+
fn test() {
4+
let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it();
5+
}

tests/target/chains-indent-inherit.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-chain_indent: Inherit
2+
3+
fn test() {
4+
let x = my_long_function()
5+
.my_even_longer_function()
6+
.my_nested_function()
7+
.some_random_name()
8+
.another_function()
9+
.do_it();
10+
}

tests/target/chains-indent-tabbed.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-chain_indent: Tabbed
2+
3+
fn test() {
4+
let x = my_long_function()
5+
.my_even_longer_function()
6+
.my_nested_function()
7+
.some_random_name()
8+
.another_function()
9+
.do_it();
10+
}

tests/target/chains-indent-visual.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-chain_indent: Visual
2+
3+
fn test() {
4+
let x = my_long_function()
5+
.my_even_longer_function()
6+
.my_nested_function()
7+
.some_random_name()
8+
.another_function()
9+
.do_it();
10+
}

0 commit comments

Comments
 (0)