From 0413c47a09d24ecd4494b2dc73442b88087f1020 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 1 Sep 2015 17:22:00 +1200 Subject: [PATCH] Support different tabbing of function args (Although, frankly anything other than visual is deeply wrong). --- src/config.rs | 2 ++ src/items.rs | 12 ++++++++++-- tests/config/small_tabs.toml | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1abdc9e80b77..8ba88725d01b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -90,6 +90,7 @@ create_config! { fn_return_indent: ReturnIndent, fn_args_paren_newline: bool, fn_args_layout: Density, + fn_arg_indent: BlockIndentStyle, struct_trailing_comma: SeparatorTactic, struct_lit_trailing_comma: SeparatorTactic, struct_lit_style: StructLitStyle, @@ -115,6 +116,7 @@ impl Default for Config { fn_return_indent: ReturnIndent::WithArgs, fn_args_paren_newline: true, fn_args_layout: Density::Tall, + fn_arg_indent: BlockIndentStyle::Visual, struct_trailing_comma: SeparatorTactic::Vertical, struct_lit_trailing_comma: SeparatorTactic::Vertical, struct_lit_style: StructLitStyle::BlockIndent, diff --git a/src/items.rs b/src/items.rs index 18cf58b667b5..694662b4eed6 100644 --- a/src/items.rs +++ b/src/items.rs @@ -18,7 +18,7 @@ use expr::rewrite_assign_rhs; use comment::FindUncommented; use visitor::FmtVisitor; use rewrite::Rewrite; -use config::Config; +use config::{Config, BlockIndentStyle}; use syntax::{ast, abi}; use syntax::codemap::{self, Span, BytePos}; @@ -237,6 +237,7 @@ impl<'a> FmtVisitor<'a> { explicit_self, one_line_budget, multi_line_budget, + indent, arg_indent, args_span)); result.push(')'); @@ -293,6 +294,7 @@ impl<'a> FmtVisitor<'a> { explicit_self: Option<&ast::ExplicitSelf>, one_line_budget: usize, multi_line_budget: usize, + indent: usize, arg_indent: usize, span: Span) -> String { @@ -341,11 +343,17 @@ impl<'a> FmtVisitor<'a> { item.item = arg; } + let indent = match self.config.fn_arg_indent { + BlockIndentStyle::Inherit => indent, + BlockIndentStyle::Tabbed => indent + self.config.tab_spaces, + BlockIndentStyle::Visual => arg_indent, + }; + let fmt = ListFormatting { tactic: self.config.fn_args_layout.to_list_tactic(), separator: ",", trailing_separator: SeparatorTactic::Never, - indent: arg_indent, + indent: indent, h_width: one_line_budget, v_width: multi_line_budget, ends_with_newline: false, diff --git a/tests/config/small_tabs.toml b/tests/config/small_tabs.toml index c05f173177b9..d489f960917d 100644 --- a/tests/config/small_tabs.toml +++ b/tests/config/small_tabs.toml @@ -7,6 +7,7 @@ fn_brace_style = "SameLineWhere" fn_return_indent = "WithArgs" fn_args_paren_newline = true fn_args_layout = "Tall" +fn_arg_indent = "Visual" struct_trailing_comma = "Vertical" struct_lit_trailing_comma = "Vertical" struct_lit_style = "BlockIndent"