Skip to content

Commit

Permalink
Router: add dedicated rule for formatOff
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 6, 2024
1 parent 3028bc7 commit c84c136
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ object Policy {
fileLine: FileLine,
): Policy = new Switch(policy, trigger, NoPolicy)

def on(token: Token, prefix: String, noDequeue: Boolean = false)(f: Pf)(
implicit fileLine: FileLine,
): Policy = apply(End == token, prefix, noDequeue)(f)
def on(token: Token, prefix: String, noDequeue: Boolean = false, rank: Int = 0)(
f: Pf,
)(implicit fileLine: FileLine): Policy =
apply(End == token, prefix, noDequeue, rank = rank)(f)

abstract class Clause(implicit val fileLine: FileLine) extends Policy {
val endPolicy: End.WithPos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,17 @@ class Router(formatOps: FormatOps) {
// DefDef
case FormatToken(_: T.KwDef, _: T.Ident, _) => Seq(Split(Space, 0))

case FormatToken(open @ LeftParenOrBracket(), _, _)
if ft.meta.formatOff &&
leftOwner.isAny[Member.SyntaxValuesClause, Member.Tuple] =>
val close = matching(open).left
def splits(xft: FormatToken, policy: Policy)(implicit l: FileLine) =
Seq(Split(Provided(xft), 0, policy = policy))
val policy = Policy.on(close, "(FMT:OFF)", rank = Int.MaxValue) {
case Decision(xft, _) => splits(xft, NoPolicy)
}
splits(ft, policy)

// Parameter opening for one parameter group. This format works
// on the WHOLE defnSite (via policies)
case FormatToken(LeftParenOrBracket(), _, _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ abstract class GeneratedRouter extends Router {

// format: on
}
>>> { stateVisits = 936042, stateVisits2 = 936042 }
>>> { stateVisits = 359, stateVisits2 = 359 }
abstract class GeneratedRouter extends Router {
// format: off

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ object SearchStateExploded {
"""
}

>>> { stateVisits = 353, stateVisits2 = 353 }
>>> { stateVisits = 313, stateVisits2 = 313 }
// format: off
object SearchStateExploded {
val veryLongString =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
override def afterAll(): Unit = {
logger.debug(s"Total explored: ${Debug.explored}")
if (!onlyUnit && !onlyManual)
assertEquals(Debug.explored, 3656127, "total explored")
assertEquals(Debug.explored, 1784375, "total explored")
val results = debugResults.result()
// TODO(olafur) don't block printing out test results.
// I don't want to deal with scalaz's Tasks :'(
Expand Down

0 comments on commit c84c136

Please sign in to comment.