Skip to content

Commit

Permalink
FormatWriter: change ParamClause alignment owner
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 11, 2023
1 parent 1f537f5 commit 8ad74b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,13 @@ class FormatWriter(formatOps: FormatOps) {
locations(idx).leftLineId != fl.leftLineId
}

private def onSingleLine(t: Tree): Boolean = {
val ttokens = t.tokens
val beg = tokens.after(ttokens.head)
val end = tokens.before(ttokens.last)
getLineDiff(locations, beg, end) == 0
}

object AlignContainer {
def unapply(tree: Tree): Option[Tree] =
tree match {
Expand Down Expand Up @@ -1291,6 +1298,15 @@ class FormatWriter(formatOps: FormatOps) {
}
if (keepGoing) getAlignContainerParent(p) else p
case Some(p: Term.ForYield) if child ne p.body => p
case Some(p: Member.ParamClause) =>
p.parent match {
// if all on single line, keep going
case Some(q) if onSingleLine(q) => getAlignContainerParent(p)
// if this one not on single line, use parent as the owner
case Some(q) if !onSingleLine(p) => // skip ParamClauseGroup
if (q.is[Member.ParamClauseGroup]) q.parent.getOrElse(q) else q
case _ => p // this one on single line, but the rest are not
}
case Some(p: Member.SyntaxValuesClause) => getAlignContainerParent(p)
case Some(p: Member.ParamClauseGroup) => getAlignContainerParent(p)
case Some(p) => p.parent.getOrElse(p)
Expand Down
36 changes: 18 additions & 18 deletions scalafmt-tests/src/test/resources/align/DefaultWithAlign.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1901,18 +1901,18 @@ object a {
>>>
object a {
def longDefNameThatCausesLinesToWrap1(x: Type0)(y: Type1)(implicit
a: Type2,
bb: Type3,
ccc: Type4,
dddd: Type5,
eeeee: Type6
a: Type2,
bb: Type3,
ccc: Type4,
dddd: Type5,
eeeee: Type6
): Future[Option[ReturnType]] = { ??? }
def longDefNameThatCausesLinesToWrap1(x: Type0)(y: Type1)(implicit
dddd: Type5,
eeeee: Type6
dddd: Type5,
eeeee: Type6
): Future[Option[ReturnType]] = { ??? }
def longDefNameThatCausesLinesToWrap1(x: Type0)(y: Type1)(implicit
eeeee: Type6
eeeee: Type6
): Future[Option[ReturnType]] = { ??? }
}
<<< curry params before
Expand Down Expand Up @@ -1945,14 +1945,14 @@ object a {
ccc: Type4,
dddd: Type5,
eeeee: Type6
)(x: Type0)(y: Type1): Future[Option[ReturnType]] = { ??? }
)(x: Type0)(y: Type1): Future[Option[ReturnType]] = { ??? }
def longDefNameThatCausesLinesToWrap1(
dddd: Type5,
eeeee: Type6
)(x: Type0)(y: Type1): Future[Option[ReturnType]] = { ??? }
)(x: Type0)(y: Type1): Future[Option[ReturnType]] = { ??? }
def longDefNameThatCausesLinesToWrap1(
eeeee: Type6
)(x: Type0)(y: Type1): Future[Option[ReturnType]] = { ??? }
)(x: Type0)(y: Type1): Future[Option[ReturnType]] = { ??? }
}
<<< curry params before and after
align.tokens."+" = [{
Expand All @@ -1978,16 +1978,16 @@ object a {
>>>
object a {
def longDefNameThatCausesLinesToWrap1(
a: Type2,
bb: Type3,
ccc: Type4
)(x: Type0)(y: Type1)(
a: Type2,
bb: Type3,
ccc: Type4
)(x: Type0)(y: Type1)(
dddd: Type5,
eeeee: Type6
): Future[Option[ReturnType]] = { ??? }
def longDefNameThatCausesLinesToWrap1(
eeeee: Type6
)(x: Type0)(y: Type1)(
)(x: Type0)(y: Type1)(
eeeee: Type6
): Future[Option[ReturnType]] = { ??? }
}
Expand Down Expand Up @@ -2019,13 +2019,13 @@ object a {
a: Type2,
bb: Type3,
ccc: Type4
)(x: Type0)(y: Type1)(
)(x: Type0)(y: Type1)(
dddd: Type5,
eeeee: Type6
): Future[Option[ReturnType]] = { ??? }
def longDefNameThatCausesLinesToWrap1(
eeeee: Type6
)(x: Type0)(y: Type1)(
)(x: Type0)(y: Type1)(
eeeee: Type6
): Future[Option[ReturnType]] = { ??? }
}

0 comments on commit 8ad74b6

Please sign in to comment.