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

BestFirstSearch: arg clause an opt-zone for keep #4354

Merged
merged 2 commits into from
Sep 28, 2024
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 @@ -332,15 +332,15 @@ object BestFirstSearch {
private def hasSlbAfter(state: State)(ft: FormatToken): Boolean = state.policy
.exists(_.appliesUntil(ft)(_.isInstanceOf[PolicyOps.SingleLineBlock]))

private def getNoOptZones(tokens: FormatTokens) = {
private def getNoOptZones(tokens: FormatTokens)(implicit styleMap: StyleMap) = {
val result = Set.newBuilder[Token]
var expire: Token = null
tokens.foreach {
case FormatToken(x, _, _) if expire ne null =>
if (x eq expire) expire = null else result += x
case FormatToken(t: Token.LeftParen, _, m) if (m.leftOwner match {
// TODO(olafur) https://github.com/scalameta/scalameta/issues/345
case lo: Term.ArgClause => !lo.parent.is[Term.ApplyInfix]
case lo: Term.ArgClause => !lo.parent.is[Term.ApplyInfix] &&
!styleMap.at(t).newlines.keep
case _: Term.Apply => true // legacy: when enclosed in parens
case _ => false
}) => expire = tokens.matching(t)
Expand Down
289 changes: 289 additions & 0 deletions scalafmt-tests/shared/src/test/resources/newlines/source_classic.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9343,3 +9343,292 @@ trait Infer {
}
}
}
<<< #4133 very long one-liner with chain of infixes, full method
class UDFRegistration private[sql] (functionRegistry: FunctionRegistry) extends Logging {
def register[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4: TypeTag, A5: TypeTag, A6: TypeTag, A7: TypeTag, A8: TypeTag, A9: TypeTag, A10: TypeTag, A11: TypeTag, A12: TypeTag, A13: TypeTag, A14: TypeTag, A15: TypeTag, A16: TypeTag, A17: TypeTag, A18: TypeTag, A19: TypeTag, A20: TypeTag, A21: TypeTag, A22: TypeTag](name: String, func: Function22[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, RT]): UserDefinedFunction = {
val inputEncoders: Seq[Option[ExpressionEncoder[_]]] = Try(ExpressionEncoder[A1]()).toOption :: Try(ExpressionEncoder[A2]()).toOption :: Try(ExpressionEncoder[A3]()).toOption :: Try(ExpressionEncoder[A4]()).toOption :: Try(ExpressionEncoder[A5]()).toOption :: Try(ExpressionEncoder[A6]()).toOption :: Try(ExpressionEncoder[A7]()).toOption :: Try(ExpressionEncoder[A8]()).toOption :: Try(ExpressionEncoder[A9]()).toOption :: Try(ExpressionEncoder[A10]()).toOption :: Try(ExpressionEncoder[A11]()).toOption :: Try(ExpressionEncoder[A12]()).toOption :: Try(ExpressionEncoder[A13]()).toOption :: Try(ExpressionEncoder[A14]()).toOption :: Try(ExpressionEncoder[A15]()).toOption :: Try(ExpressionEncoder[A16]()).toOption :: Try(ExpressionEncoder[A17]()).toOption :: Try(ExpressionEncoder[A18]()).toOption :: Try(ExpressionEncoder[A19]()).toOption :: Try(ExpressionEncoder[A20]()).toOption :: Try(ExpressionEncoder[A21]()).toOption :: Try(ExpressionEncoder[A22]()).toOption :: Nil
}
}
>>>
class UDFRegistration private[sql] (
functionRegistry: FunctionRegistry
) extends Logging {
def register[
RT: TypeTag,
A1: TypeTag,
A2: TypeTag,
A3: TypeTag,
A4: TypeTag,
A5: TypeTag,
A6: TypeTag,
A7: TypeTag,
A8: TypeTag,
A9: TypeTag,
A10: TypeTag,
A11: TypeTag,
A12: TypeTag,
A13: TypeTag,
A14: TypeTag,
A15: TypeTag,
A16: TypeTag,
A17: TypeTag,
A18: TypeTag,
A19: TypeTag,
A20: TypeTag,
A21: TypeTag,
A22: TypeTag
](
name: String,
func: Function22[
A1,
A2,
A3,
A4,
A5,
A6,
A7,
A8,
A9,
A10,
A11,
A12,
A13,
A14,
A15,
A16,
A17,
A18,
A19,
A20,
A21,
A22,
RT
]
): UserDefinedFunction = {
val inputEncoders: Seq[
Option[ExpressionEncoder[_]]
] = Try(
ExpressionEncoder[A1]()
).toOption :: Try(
ExpressionEncoder[A2]()
).toOption :: Try(
ExpressionEncoder[A3]()
).toOption :: Try(
ExpressionEncoder[A4]()
).toOption :: Try(
ExpressionEncoder[A5]()
).toOption :: Try(
ExpressionEncoder[A6]()
).toOption :: Try(
ExpressionEncoder[A7]()
).toOption :: Try(
ExpressionEncoder[A8]()
).toOption :: Try(
ExpressionEncoder[A9]()
).toOption :: Try(
ExpressionEncoder[A10]()
).toOption :: Try(
ExpressionEncoder[A11]()
).toOption :: Try(
ExpressionEncoder[A12]()
).toOption :: Try(
ExpressionEncoder[A13]()
).toOption :: Try(
ExpressionEncoder[A14]()
).toOption :: Try(
ExpressionEncoder[A15]()
).toOption :: Try(
ExpressionEncoder[A16]()
).toOption :: Try(
ExpressionEncoder[A17]()
).toOption :: Try(
ExpressionEncoder[A18]()
).toOption :: Try(
ExpressionEncoder[A19]()
).toOption :: Try(
ExpressionEncoder[A20]()
).toOption :: Try(
ExpressionEncoder[A21]()
).toOption :: Try(
ExpressionEncoder[A22]()
).toOption :: Nil
}
}
<<< #4133 very long one-liner with chain of infixes
runner.maxStateVisits = 1000
===
class UDFRegistration {
def foo = {
val inputEncoders: Seq_Option_ExpressionEncoder_____ = Try(ExpressionEncoder_A1_) :: Try(ExpressionEncoder_A2_) :: Try(ExpressionEncoder_A3_) :: Try(ExpressionEncoder_A4_) :: Try(ExpressionEncoder_A5_) :: Try(ExpressionEncoder_A6_) :: Try(ExpressionEncoder_A7_) :: Try(ExpressionEncoder_A8_) :: Try(ExpressionEncoder_A9_) :: Try(ExpressionEncoder_A10_) :: Try(ExpressionEncoder_A11_) :: Try(ExpressionEncoder_A12_) :: Try(ExpressionEncoder_A13_) :: Try(ExpressionEncoder_A14_) :: Try(ExpressionEncoder_A15_) :: Try(ExpressionEncoder_A16_) :: Try(ExpressionEncoder_A17_) :: Try(ExpressionEncoder_A18_) :: Try(ExpressionEncoder_A19_) :: Try(ExpressionEncoder_A20_) :: Try(ExpressionEncoder_A21_) :: Try(ExpressionEncoder_A22_) :: Nil
}
}
>>>
class UDFRegistration {
def foo = {
val inputEncoders
: Seq_Option_ExpressionEncoder_____ =
Try(ExpressionEncoder_A1_) :: Try(
ExpressionEncoder_A2_
) :: Try(
ExpressionEncoder_A3_
) :: Try(
ExpressionEncoder_A4_
) :: Try(
ExpressionEncoder_A5_
) :: Try(
ExpressionEncoder_A6_
) :: Try(
ExpressionEncoder_A7_
) :: Try(
ExpressionEncoder_A8_
) :: Try(
ExpressionEncoder_A9_
) :: Try(
ExpressionEncoder_A10_
) :: Try(
ExpressionEncoder_A11_
) :: Try(
ExpressionEncoder_A12_
) :: Try(
ExpressionEncoder_A13_
) :: Try(
ExpressionEncoder_A14_
) :: Try(
ExpressionEncoder_A15_
) :: Try(
ExpressionEncoder_A16_
) :: Try(
ExpressionEncoder_A17_
) :: Try(
ExpressionEncoder_A18_
) :: Try(
ExpressionEncoder_A19_
) :: Try(
ExpressionEncoder_A20_
) :: Try(
ExpressionEncoder_A21_
) :: Try(
ExpressionEncoder_A22_
) :: Nil
}
}
<<< #4133 very long one-liner with chain of infixes, with selects
runner.maxStateVisits = 5000
===
class UDFRegistration {
def foo = {
val inputEncoders: Seq_Option_ExpressionEncoder_____ = Try(ExpressionEncoder_A1_).toOption :: Try(ExpressionEncoder_A2_).toOption :: Try(ExpressionEncoder_A3_).toOption :: Try(ExpressionEncoder_A4_).toOption :: Try(ExpressionEncoder_A5_).toOption :: Try(ExpressionEncoder_A6_).toOption :: Try(ExpressionEncoder_A7_).toOption :: Try(ExpressionEncoder_A8_).toOption :: Try(ExpressionEncoder_A9_).toOption :: Try(ExpressionEncoder_A10_).toOption :: Try(ExpressionEncoder_A11_).toOption :: Try(ExpressionEncoder_A12_).toOption :: Try(ExpressionEncoder_A13_).toOption :: Try(ExpressionEncoder_A14_).toOption :: Try(ExpressionEncoder_A15_).toOption :: Try(ExpressionEncoder_A16_).toOption :: Try(ExpressionEncoder_A17_).toOption :: Try(ExpressionEncoder_A18_).toOption :: Try(ExpressionEncoder_A19_).toOption :: Try(ExpressionEncoder_A20_).toOption :: Try(ExpressionEncoder_A21_).toOption :: Try(ExpressionEncoder_A22_).toOption :: Nil
}
}
>>>
class UDFRegistration {
def foo = {
val inputEncoders
: Seq_Option_ExpressionEncoder_____ =
Try(
ExpressionEncoder_A1_
).toOption :: Try(
ExpressionEncoder_A2_
).toOption :: Try(
ExpressionEncoder_A3_
).toOption :: Try(
ExpressionEncoder_A4_
).toOption :: Try(
ExpressionEncoder_A5_
).toOption :: Try(
ExpressionEncoder_A6_
).toOption :: Try(
ExpressionEncoder_A7_
).toOption :: Try(
ExpressionEncoder_A8_
).toOption :: Try(
ExpressionEncoder_A9_
).toOption :: Try(
ExpressionEncoder_A10_
).toOption :: Try(
ExpressionEncoder_A11_
).toOption :: Try(
ExpressionEncoder_A12_
).toOption :: Try(
ExpressionEncoder_A13_
).toOption :: Try(
ExpressionEncoder_A14_
).toOption :: Try(
ExpressionEncoder_A15_
).toOption :: Try(
ExpressionEncoder_A16_
).toOption :: Try(
ExpressionEncoder_A17_
).toOption :: Try(
ExpressionEncoder_A18_
).toOption :: Try(
ExpressionEncoder_A19_
).toOption :: Try(
ExpressionEncoder_A20_
).toOption :: Try(
ExpressionEncoder_A21_
).toOption :: Try(
ExpressionEncoder_A22_
).toOption :: Nil
}
}
<<< #4133 very long one-liner with chain of infixes, with select and types
runner.maxStateVisits = 100000
===
class UDFRegistration {
def foo = {
val inputEncoders: Seq[Option[ExpressionEncoder[_]]] = Try(ExpressionEncoder[A1]).toOption :: Try(ExpressionEncoder[A2]).toOption :: Try(ExpressionEncoder[A3]).toOption :: Try(ExpressionEncoder[A4]).toOption :: Try(ExpressionEncoder[A5]).toOption :: Try(ExpressionEncoder[A6]).toOption :: Try(ExpressionEncoder[A7]).toOption :: Try(ExpressionEncoder[A8]).toOption :: Try(ExpressionEncoder[A9]).toOption :: Try(ExpressionEncoder[A10]).toOption :: Try(ExpressionEncoder[A11]).toOption :: Try(ExpressionEncoder[A12]).toOption :: Try(ExpressionEncoder[A13]).toOption :: Try(ExpressionEncoder[A14]).toOption :: Try(ExpressionEncoder[A15]).toOption :: Try(ExpressionEncoder[A16]).toOption :: Try(ExpressionEncoder[A17]).toOption :: Try(ExpressionEncoder[A18]).toOption :: Try(ExpressionEncoder[A19]).toOption :: Try(ExpressionEncoder[A20]).toOption :: Try(ExpressionEncoder[A21]).toOption :: Try(ExpressionEncoder[A22]).toOption :: Nil
}
}
>>>
class UDFRegistration {
def foo = {
val inputEncoders: Seq[
Option[ExpressionEncoder[_]]
] = Try(
ExpressionEncoder[A1]
).toOption :: Try(
ExpressionEncoder[A2]
).toOption :: Try(
ExpressionEncoder[A3]
).toOption :: Try(
ExpressionEncoder[A4]
).toOption :: Try(
ExpressionEncoder[A5]
).toOption :: Try(
ExpressionEncoder[A6]
).toOption :: Try(
ExpressionEncoder[A7]
).toOption :: Try(
ExpressionEncoder[A8]
).toOption :: Try(
ExpressionEncoder[A9]
).toOption :: Try(
ExpressionEncoder[A10]
).toOption :: Try(
ExpressionEncoder[A11]
).toOption :: Try(
ExpressionEncoder[A12]
).toOption :: Try(
ExpressionEncoder[A13]
).toOption :: Try(
ExpressionEncoder[A14]
).toOption :: Try(
ExpressionEncoder[A15]
).toOption :: Try(
ExpressionEncoder[A16]
).toOption :: Try(
ExpressionEncoder[A17]
).toOption :: Try(
ExpressionEncoder[A18]
).toOption :: Try(
ExpressionEncoder[A19]
).toOption :: Try(
ExpressionEncoder[A20]
).toOption :: Try(
ExpressionEncoder[A21]
).toOption :: Try(
ExpressionEncoder[A22]
).toOption :: Nil
}
}
Loading
Loading