Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatOps: force config style for all call sites #3277

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1157,12 +1157,12 @@ class FormatOps(
case FormatToken(
left: T.LeftParen,
_,
FormatToken.LeftOwner(app: Term.Apply)
FormatToken.LeftOwner(app @ CallArgsForConfigStyle(args))
)
if app.args.lengthCompare(minArgs) >= 0 &&
if args.lengthCompare(minArgs) >= 0 &&
distance(left, matching(left)) > maxDistance =>
forces += app
app.args.foreach { arg =>
args.foreach { arg =>
clearQueues += hash(tokens.getHead(arg).left)
}
case _ =>
Expand Down Expand Up @@ -1483,14 +1483,15 @@ class FormatOps(
}
}

def opensImplicitParamList(ft: FormatToken): Option[Seq[Term.Param]] = {
val paramsOpt = splitDefnIntoParts.lift(ft.meta.leftOwner).flatMap {
case (_, _, _, paramss) =>
def opensImplicitParamList(ft: FormatToken): Option[Seq[Tree]] =
ft.meta.leftOwner match {
case t: Term.ApplyUsing => Some(t.args)
case SplitDefnIntoParts(_, _, _, paramss) =>
findArgsFor(ft.left, paramss)
// make sure there's no other param with implicit
.filter(!_.exists(TreeOps.hasExplicitImplicit))
case _ => None
}
// make sure there's no other param with implicit
paramsOpt.filter(!_.exists(TreeOps.hasExplicitImplicit))
}

/** Works for `using` as well */
def opensImplicitParamList(ft: FormatToken, args: Seq[Tree]): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.scalameta.FileLine

import scala.annotation.tailrec
import scala.language.implicitConversions
import scala.meta.Term.ApplyUsing
import scala.meta.classifiers.Classifier
import scala.meta.tokens.{Token => T}
import scala.meta.{
Expand Down Expand Up @@ -2336,12 +2335,7 @@ class Router(formatOps: FormatOps) {
if style.binPack.unsafeDefnSite.isNever &&
!style.verticalMultiline.atDefnSite &&
isRightImplicitOrUsingSoftKw(formatToken, soft) =>
val argsOrParamsOpt = formatToken.meta.leftOwner match {
// for the using argument list
case _: ApplyUsing => Some(getApplyArgs(formatToken, false).args)
case _ => opensImplicitParamList(prevNonCommentBefore(formatToken))
}
argsOrParamsOpt.fold {
opensImplicitParamList(prevNonCommentBefore(formatToken)).fold {
Seq(Split(Space, 0))
} { params =>
val spaceSplit = Split(Space, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@ object TreeOps {
splitCallIntoParts.lift(tree)
}

object CallArgsForConfigStyle {
def unapply(tree: Tree): Option[Seq[Tree]] = Some(tree match {
case t: Term.Apply => t.args
case t: Init => t.argss.flatten
case t: Term.ApplyUsing => t.args
case _ => Seq.empty
}).filter(_.nonEmpty)
}

type DefnParts = (Seq[Mod], Name, Seq[Type.Param], Seq[Seq[Term.Param]])
val splitDefnIntoParts: PartialFunction[Tree, DefnParts] = {
// types
Expand Down
86 changes: 86 additions & 0 deletions scalafmt-tests/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1810,3 +1810,89 @@ object a {
}
}
}
<<< #3274
object a {
def createFoo(rs: ResultSet): Foo = {
new Foo(
rs.getDouble(1),
rs.getDouble(2),
rs.getDouble(3),
rs.getDouble(4),
rs.getDouble(5),
rs.getDouble(6),
rs.getDouble(7),
rs.getDouble(8),
rs.getDouble(9),
rs.getDouble(10),
rs.getDouble(11),
rs.getDouble(12),
rs.getDouble(13),
rs.getDouble(14),
rs.getDouble(15),
rs.getDouble(16),
rs.getDouble(17),
rs.getDouble(18),
rs.getDouble(19),
rs.getDouble(20),
rs.getDouble(21),
rs.getDouble(22),
rs.getDouble(23),
rs.getDouble(24),
rs.getDouble(25),
rs.getDouble(26),
rs.getDouble(27),
rs.getDouble(28),
rs.getDouble(29),
rs.getDouble(30),
rs.getDouble(31),
rs.getDouble(32),
rs.getDouble(33),
rs.getDouble(34),
rs.getDouble(35),
rs.getDouble(36)
)
}
}
>>>
object a {
def createFoo(rs: ResultSet): Foo = {
new Foo(
rs.getDouble(1),
rs.getDouble(2),
rs.getDouble(3),
rs.getDouble(4),
rs.getDouble(5),
rs.getDouble(6),
rs.getDouble(7),
rs.getDouble(8),
rs.getDouble(9),
rs.getDouble(10),
rs.getDouble(11),
rs.getDouble(12),
rs.getDouble(13),
rs.getDouble(14),
rs.getDouble(15),
rs.getDouble(16),
rs.getDouble(17),
rs.getDouble(18),
rs.getDouble(19),
rs.getDouble(20),
rs.getDouble(21),
rs.getDouble(22),
rs.getDouble(23),
rs.getDouble(24),
rs.getDouble(25),
rs.getDouble(26),
rs.getDouble(27),
rs.getDouble(28),
rs.getDouble(29),
rs.getDouble(30),
rs.getDouble(31),
rs.getDouble(32),
rs.getDouble(33),
rs.getDouble(34),
rs.getDouble(35),
rs.getDouble(36)
)
}
}