|
1 | 1 | package com.danieltrinh.scalariform.formatter |
2 | 2 |
|
| 3 | +import com.danieltrinh.scalariform.formatter.Alignment._ |
| 4 | +import com.danieltrinh.scalariform.formatter.AnnotationFormatter |
3 | 5 | import com.danieltrinh.scalariform.lexer.Chars |
4 | 6 | import com.danieltrinh.scalariform.lexer.Token |
5 | 7 | import com.danieltrinh.scalariform.lexer.Tokens._ |
6 | 8 | import com.danieltrinh.scalariform.parser._ |
7 | 9 | import com.danieltrinh.scalariform.utils.{ TextEditProcessor, Utils } |
8 | 10 | import com.danieltrinh.scalariform.formatter.preferences._ |
9 | 11 | import scala.PartialFunction._ |
10 | | -import Alignment._ |
11 | 12 |
|
12 | 13 | trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter with HasHiddenTokenInfo with TypeFormatter with TemplateFormatter with ScalaFormatter with XmlFormatter with CaseClauseFormatter ⇒ |
13 | 14 |
|
@@ -756,16 +757,26 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi |
756 | 757 | if (statSeq.firstTokenOption.isDefined) { |
757 | 758 | statSeq.firstStatOpt match { |
758 | 759 | case Some(Expr(List(anonFn @ AnonymousFunction(params, arrowToken, subStatSeq)))) ⇒ |
| 760 | + def hasNestedAnonymousFunction(subStatSeq: StatSeq): Boolean = |
| 761 | + (for { |
| 762 | + firstStat <- subStatSeq.firstStatOpt |
| 763 | + head <- firstStat.immediateChildren.headOption |
| 764 | + } yield head.isInstanceOf[AnonymousFunction]).getOrElse(false) |
| 765 | + |
759 | 766 | val (instruction, subStatState) = |
760 | | - if (hiddenPredecessors(params(0).firstToken).containsNewline) |
| 767 | + if (hasNestedAnonymousFunction(subStatSeq)) |
| 768 | + (CompactEnsuringGap, indentedState.indent(-1)) |
| 769 | + else if (hiddenPredecessors(params(0).firstToken).containsNewline) |
761 | 770 | (indentedInstruction, indentedState.indent) |
762 | 771 | else |
763 | 772 | (CompactEnsuringGap, indentedState) |
764 | 773 | formatResult = formatResult.before(statSeq.firstToken, instruction) |
765 | 774 | formatResult ++= format(params) |
766 | 775 | for (firstToken ← subStatSeq.firstTokenOption) { |
767 | 776 | val instruction = |
768 | | - if (hiddenPredecessors(firstToken).containsNewline || containsNewline(subStatSeq)) |
| 777 | + if (hasNestedAnonymousFunction(subStatSeq)) |
| 778 | + CompactEnsuringGap |
| 779 | + else if (hiddenPredecessors(firstToken).containsNewline || containsNewline(subStatSeq)) |
769 | 780 | statFormatterState(subStatSeq.firstStatOpt)(subStatState).currentIndentLevelInstruction |
770 | 781 | else |
771 | 782 | CompactEnsuringGap |
|
0 commit comments