Merge pull request #74 from cassiersg/paren-expr

Add reformating for parentheses
This commit is contained in:
Nick Cameron
2015-05-25 09:57:20 +12:00
2 changed files with 19 additions and 0 deletions
+12
View File
@@ -125,6 +125,15 @@ fn rewrite_call(&mut self,
format!("{}({})", callee_str, args_str)
}
fn rewrite_paren(&mut self, subexpr: &ast::Expr, width: usize, offset: usize) -> String {
debug!("rewrite_paren, width: {}, offset: {}", width, offset);
// 1 is for opening paren, 2 is for opening+closing, we want to keep the closing
// paren on the same line as the subexpr
let subexpr_str = self.rewrite_expr(subexpr, width-2, offset+1);
debug!("rewrite_paren, subexpr_str: `{}`", subexpr_str);
format!("({})", subexpr_str)
}
pub fn rewrite_expr(&mut self, expr: &ast::Expr, width: usize, offset: usize) -> String {
match expr.node {
ast::Expr_::ExprLit(ref l) => {
@@ -140,6 +149,9 @@ pub fn rewrite_expr(&mut self, expr: &ast::Expr, width: usize, offset: usize) ->
ast::Expr_::ExprCall(ref callee, ref args) => {
return self.rewrite_call(callee, args, width, offset);
}
ast::Expr_::ExprParen(ref subexpr) => {
return self.rewrite_paren(subexpr, width, offset);
}
_ => {}
}
+7
View File
@@ -0,0 +1,7 @@
// Test parenthesis
fn foo() {
let very_long_variable_name = (a + first + simple + test);
let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBBB +
b + c);
}