From d4be6a43e98883c04d38b101c663ddf990e247f3 Mon Sep 17 00:00:00 2001 From: Thorben Kroeger Date: Sat, 14 Nov 2015 17:47:59 +0100 Subject: [PATCH] new config 'chain_indent' --- src/chains.rs | 10 +++++++++- src/config.rs | 1 + tests/source/chains-indent-inherit.rs | 5 +++++ tests/source/chains-indent-tabbed.rs | 5 +++++ tests/source/chains-indent-visual.rs | 5 +++++ tests/target/chains-indent-inherit.rs | 10 ++++++++++ tests/target/chains-indent-tabbed.rs | 10 ++++++++++ tests/target/chains-indent-visual.rs | 10 ++++++++++ 8 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/source/chains-indent-inherit.rs create mode 100644 tests/source/chains-indent-tabbed.rs create mode 100644 tests/source/chains-indent-visual.rs create mode 100644 tests/target/chains-indent-inherit.rs create mode 100644 tests/target/chains-indent-tabbed.rs create mode 100644 tests/target/chains-indent-visual.rs diff --git a/src/chains.rs b/src/chains.rs index 9c5b37d35cb..31cd9624016 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -56,7 +56,15 @@ pub fn rewrite_chain(mut expr: &ast::Expr, } else if is_block_expr(parent, &parent_rewrite) { (parent_block_indent, false) } else { - (offset + Indent::new(context.config.tab_spaces, 0), false) + match context.config.chain_indent { + BlockIndentStyle::Inherit => (context.block_indent, false), + BlockIndentStyle::Tabbed => { + (context.block_indent.block_indent(context.config), false) + } + BlockIndentStyle::Visual => { + (offset + Indent::new(context.config.tab_spaces, 0), false) + } + } }; let max_width = try_opt!((width + offset.width()).checked_sub(indent.width())); diff --git a/src/config.rs b/src/config.rs index 9f260f93ab8..dcf0816335b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -294,6 +294,7 @@ create_config! { report_fixme: ReportTactic, ReportTactic::Never, "Report all, none or unnumbered occurrences of FIXME in source file comments"; chain_base_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on chain base"; + chain_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indentation of chain"; reorder_imports: bool, false, "Reorder import statements alphabetically"; single_line_if_else: bool, false, "Put else on same line as closing brace for if statements"; format_strings: bool, true, "Format string literals, or leave as is"; diff --git a/tests/source/chains-indent-inherit.rs b/tests/source/chains-indent-inherit.rs new file mode 100644 index 00000000000..67272a656c6 --- /dev/null +++ b/tests/source/chains-indent-inherit.rs @@ -0,0 +1,5 @@ +// rustfmt-chain_indent: Inherit + +fn test() { + let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it(); +} diff --git a/tests/source/chains-indent-tabbed.rs b/tests/source/chains-indent-tabbed.rs new file mode 100644 index 00000000000..89bf5bb1a69 --- /dev/null +++ b/tests/source/chains-indent-tabbed.rs @@ -0,0 +1,5 @@ +// rustfmt-chain_indent: Tabbed + +fn test() { + let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it(); +} diff --git a/tests/source/chains-indent-visual.rs b/tests/source/chains-indent-visual.rs new file mode 100644 index 00000000000..7e7f0558ffe --- /dev/null +++ b/tests/source/chains-indent-visual.rs @@ -0,0 +1,5 @@ +// rustfmt-chain_indent: Visual + +fn test() { + let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it(); +} diff --git a/tests/target/chains-indent-inherit.rs b/tests/target/chains-indent-inherit.rs new file mode 100644 index 00000000000..76d3ef8204b --- /dev/null +++ b/tests/target/chains-indent-inherit.rs @@ -0,0 +1,10 @@ +// rustfmt-chain_indent: Inherit + +fn test() { + let x = my_long_function() + .my_even_longer_function() + .my_nested_function() + .some_random_name() + .another_function() + .do_it(); +} diff --git a/tests/target/chains-indent-tabbed.rs b/tests/target/chains-indent-tabbed.rs new file mode 100644 index 00000000000..4611b0587ff --- /dev/null +++ b/tests/target/chains-indent-tabbed.rs @@ -0,0 +1,10 @@ +// rustfmt-chain_indent: Tabbed + +fn test() { + let x = my_long_function() + .my_even_longer_function() + .my_nested_function() + .some_random_name() + .another_function() + .do_it(); +} diff --git a/tests/target/chains-indent-visual.rs b/tests/target/chains-indent-visual.rs new file mode 100644 index 00000000000..e91317bd5de --- /dev/null +++ b/tests/target/chains-indent-visual.rs @@ -0,0 +1,10 @@ +// rustfmt-chain_indent: Visual + +fn test() { + let x = my_long_function() + .my_even_longer_function() + .my_nested_function() + .some_random_name() + .another_function() + .do_it(); +}