Skip to content

Commit a7b1bef

Browse files
author
Daniel Trinh
committed
more temp work
1 parent 2dd4271 commit a7b1bef

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

scalariform/src/main/scala/scalariform/formatter/ExprFormatter.scala

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,11 +1005,11 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
10051005

10061006
if (formattingPreferences(PreserveDanglingCloseParenthesis))
10071007
formatResult = formatResult.before(rparen, formatterState.currentIndentLevelInstruction)
1008-
else if (clauseIndex > 0)
1009-
// Only indent subsequent param clauses if dangling parenthesis are off.
1010-
// This is done because having dangling parenthesis is enough visual distiction
1011-
// to see where new param clauses start/end.
1012-
paramFormatterState = paramFormatterState.indent(paramIndent)
1008+
// else if (clauseIndex > 0)
1009+
// // Only indent subsequent param clauses if dangling parenthesis are off.
1010+
// // This is done because having dangling parenthesis is enough visual distiction
1011+
// // to see where new param clauses start/end.
1012+
// paramFormatterState = paramFormatterState.indent(paramIndent)
10131013

10141014
if (alignParameters) {
10151015
// Place implicit on it's own line
@@ -1025,27 +1025,31 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
10251025
params.foreach { param =>
10261026
val firstToken = param.firstToken
10271027

1028+
// Indent prefixes (annotations, modifiers, and id)
10281029
if (first) {
1029-
paramFormatterState = formatterState.alignWithToken(relativeToken)
1030+
val firstToken = param.firstToken
10301031

10311032
if (hiddenPredecessors(firstToken).containsNewline) {
10321033
formatResult = formatResult.before(firstToken, formatterState.indent(paramIndent).currentIndentLevelInstruction)
1033-
} else if (containsNewline(param) && alignParameters) {
1034+
paramFormatterState = formatterState.alignWithToken(relativeToken)
1035+
} else if (containsNewline(param)) {
10341036
paramFormatterState = formatterState.alignWithToken(relativeToken)
10351037
}
1038+
1039+
// paramFormatterState = formatterState.alignWithToken(relativeToken)
1040+
// if (hiddenPredecessors(firstToken).containsNewline) {
1041+
// formatResult = formatResult.before(firstToken, formatterState.indent(paramIndent).currentIndentLevelInstruction)
1042+
// } else if (containsNewline(param) && alignParameters) {
1043+
// paramFormatterState = formatterState.alignWithToken(relativeToken)
1044+
// }
10361045
first = false
10371046
} else {
10381047
if (hiddenPredecessors(firstToken).containsNewline) {
1039-
formatterState.indent(paramIndent)
1048+
paramFormatterState = if (alignParameters) formatterState.alignWithToken(relativeToken) else formatterState.indent(paramIndent)
10401049
formatResult = formatResult.before(firstToken, paramFormatterState.currentIndentLevelInstruction)
10411050
}
10421051
}
10431052

1044-
// Indent Prefix Or Id
1045-
// formatResult = formatResult.before(firstToken, paramFormatterState.indent(paramIndent).currentIndentLevelInstruction)
1046-
1047-
// paramFormatterState = paramFormatterState.alignWithToken(relativeToken)
1048-
10491053
// Indent Type
10501054
for ((colon, typeAst) <- param.paramTypeOpt) {
10511055
val typeSpaces = maxSectionLengths.prefixAndIdLength + 1
@@ -1082,20 +1086,19 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
10821086
}
10831087
} else {
10841088
for (param <- firstParamOption) {
1085-
formatNotAlignedParam(param, implicitOption getOrElse param.firstToken)
1089+
val firstToken = param.firstToken
1090+
if (hiddenPredecessors(firstToken).containsNewline) {
1091+
formatResult = formatResult.before(firstToken, formatterState.indent(paramIndent).currentIndentLevelInstruction)
1092+
paramFormatterState = formatterState.indent(paramIndent)
1093+
}
10861094
}
10871095
for ((comma, param) otherParams) {
1088-
formatNotAlignedParam(param, param.firstToken)
1089-
}
1090-
}
1091-
1092-
def formatNotAlignedParam(param: Param, firstToken: Token) = {
1093-
1094-
if (hiddenPredecessors(firstToken).containsNewline) {
1095-
formatResult = formatResult.before(firstToken, formatterState.indent(paramIndent).currentIndentLevelInstruction)
1096+
val firstToken = param.firstToken
1097+
if (hiddenPredecessors(firstToken).containsNewline) {
1098+
paramFormatterState = formatterState.indent(paramIndent)
1099+
formatResult = formatResult.before(firstToken, paramFormatterState.currentIndentLevelInstruction)
1100+
}
10961101
}
1097-
1098-
formatResult ++= format(param)(paramFormatterState)
10991102
}
11001103

11011104
// for (firstParam ← firstParamOption) {
@@ -1113,16 +1116,14 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
11131116
// }
11141117
// formatResult ++= format(firstParam)(paramFormatterState)
11151118
// }
1116-
// for ((comma, param) ← otherParams) {
1117-
// val token = param.firstToken
1118-
1119-
// if (hiddenPredecessors(token).containsNewline) {
1120-
// formatterState.indent(paramIndent)
1121-
// formatResult = formatResult.before(token, paramFormatterState.currentIndentLevelInstruction)
1122-
// }
1123-
// formatResult ++= format(param)(paramFormatterState)
1124-
// }
1125-
1119+
// for ((comma, param) ← otherParams) {
1120+
// val token = param.firstToken
1121+
// if (hiddenPredecessors(token).containsNewline) {
1122+
// paramFormatterState = if (alignParameters) formatterState.alignWithToken(relativeToken) else formatterState.indent(paramIndent)
1123+
// formatResult = formatResult.before(token, paramFormatterState.currentIndentLevelInstruction)
1124+
// }
1125+
// formatResult ++= format(param)(paramFormatterState)
1126+
// }
11261127

11271128
(formatResult, paramFormatterState)
11281129
}

scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,20 @@ class TemplateFormatterTest extends AbstractFormatterTest {
385385
|parameterOne: Int = 1,
386386
|val parameterTwo: Option[String] = None,
387387
|three: String = "three")(
388+
|intermediate: Int
389+
|)(
388390
|implicit val four: Int,
389391
|five: String,
390392
|six: Boolean)""" ==>
391-
"""class SomeClass(
392-
| parameterOne: Int = 1,
393-
| val parameterTwo: Option[String] = None,
394-
| three: String = "three")(
395-
| implicit
396-
| val four: Int,
397-
| five: String,
398-
| six: Boolean)"""
393+
"""class SomeClass(
394+
| parameterOne: Int = 1,
395+
| val parameterTwo: Option[String] = None,
396+
| three: String = "three")(
397+
| intermediate: Int)(
398+
| implicit
399+
| val four: Int,
400+
| five: String,
401+
| six: Boolean)"""
399402
//
400403
// Handles annotations, modifiers, and comments
401404
"""def extraStuff(

0 commit comments

Comments
 (0)