Skip to content

Commit

Permalink
FormatOps: add all arguments to argumentStarts
Browse files Browse the repository at this point in the history
This now allows us to handle bracketed arguments.
  • Loading branch information
kitbellew committed May 15, 2024
1 parent f434cc4 commit 0f2b117
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class FormatOps(
queue += topSourceTree :: Nil
while (queue.nonEmpty) queue.remove(0).foreach { tree =>
tree match {
case _: Lit.Unit | _: Member.SyntaxValuesClause =>
case t: Term.Param =>
case _: Lit.Unit | _: Term.ArgClause | _: Term.ParamClause =>
case t: Member.SyntaxValuesClause => t.values.foreach(add)
case t: Term.Param => // includes Term.ParamClause
add(t)
t.mods.foreach(addOptional)
addOptional(t.name)
case t: Term => add(t)
case t: Pat.Extract => t.argClause.values.foreach(add)
case t: Term => add(t) // includes Term.ArgClause
case _ =>
}
queue += tree.children
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,10 @@ class Router(formatOps: FormatOps) {
}
def optFT = nextCommaOrParen.fold(lastFT) { cp =>
if (cp.right.is[T.Comma]) if (oneline) cp else lastFT
else if (!cp.right.is[T.RightParen]) lastFT
else if (!style.newlines.avoidInResultType) lastFT
else if (
!style.newlines.avoidInResultType ||
style.newlines.sometimesBeforeColonInMethodReturnType
) lastFT
else {
val nft = findToken(next(cp), next) { x =>
x.right match {
Expand Down
4 changes: 2 additions & 2 deletions scalafmt-tests/src/test/resources/scalajs/Class.stat
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Promise[+A](
executor: js.Function2[js.Function1[A | Thenable[A], _], js.Function1[scala.Any, _], _])
>>>
class Promise[+A](
executor: js.Function2[js.Function1[A | Thenable[A], _], js.Function1[
scala.Any, _], _])
executor: js.Function2[js.Function1[A | Thenable[A], _],
js.Function1[scala.Any, _], _])
<<< #270
object a {
private class Encoder extends CharsetEncoder(
Expand Down
61 changes: 30 additions & 31 deletions scalafmt-tests/src/test/resources/scalajs/DefDef.stat
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ object a {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
override private[util] def newNode(key: K, hash: Int, value: V,
- previous: HashMap.Node[K, V],
+ previous: HashMap.Node[K,
+ V],
next: HashMap.Node[K, V]): HashMap.Node[K, V] = {
object a {
override private[util] def newNode(key: K, hash: Int, value: V,
previous: HashMap.Node[K, V], next: HashMap.Node[K, V])
: HashMap.Node[K, V] = {
new NullRejectingHashMap.Node(key, hash, value, previous, next)
}
}
<<< oneline def with keep, cfg+!dangle
preset = default
newlines.source = keep
Expand All @@ -444,13 +444,13 @@ object a {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
override private[util] def newNode(key: K, hash: Int, value: V,
- previous: HashMap.Node[K, V],
+ previous: HashMap.Node[K,
+ V],
next: HashMap.Node[K, V]): HashMap.Node[K, V] = {
object a {
override private[util] def newNode(key: K, hash: Int, value: V,
previous: HashMap.Node[K, V], next: HashMap.Node[K, V])
: HashMap.Node[K, V] = {
new NullRejectingHashMap.Node(key, hash, value, previous, next)
}
}
<<< oneline def with keep, !cfg+dangle
preset = default
newlines.source = keep
Expand All @@ -465,13 +465,13 @@ object a {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
override private[util] def newNode(key: K, hash: Int, value: V,
- previous: HashMap.Node[K, V],
+ previous: HashMap.Node[K,
+ V],
next: HashMap.Node[K, V]): HashMap.Node[K, V] = {
object a {
override private[util] def newNode(key: K, hash: Int, value: V,
previous: HashMap.Node[K, V], next: HashMap.Node[K, V])
: HashMap.Node[K, V] = {
new NullRejectingHashMap.Node(key, hash, value, previous, next)
}
}
<<< oneline def with keep, !cfg+!dangle
preset = default
newlines.source = keep
Expand All @@ -486,13 +486,13 @@ object a {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
override private[util] def newNode(key: K, hash: Int, value: V,
- previous: HashMap.Node[K, V],
+ previous: HashMap.Node[K,
+ V],
next: HashMap.Node[K, V]): HashMap.Node[K, V] = {
object a {
override private[util] def newNode(key: K, hash: Int, value: V,
previous: HashMap.Node[K, V], next: HashMap.Node[K, V])
: HashMap.Node[K, V] = {
new NullRejectingHashMap.Node(key, hash, value, previous, next)
}
}
<<< last comma right on maxColumn boundary, oneline
preset = default
maxColumn = 78
Expand All @@ -509,9 +509,8 @@ object a {
}
>>>
object a {
implicit def toFunction12[
VeryVeryVeryVeryVeryVeryVeryVeryVeryLongTypeParam, R](
f: js.Function12[VeryVeryVeryVeryVeryVeryVeryVeryVeryLongTypeParam,
implicit def toFunction12[VeryVeryVeryVeryVeryVeryVeryVeryVeryLongTypeParam,
R](f: js.Function12[VeryVeryVeryVeryVeryVeryVeryVeryVeryLongTypeParam,
R]): scala.Function12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
T12, R] =
(x1, x12) => f(x1, x12)
Expand Down

0 comments on commit 0f2b117

Please sign in to comment.