Skip to content

Commit

Permalink
Router: SLB exclude On close delim in apply/select
Browse files Browse the repository at this point in the history
Instead of After.
  • Loading branch information
kitbellew committed Nov 8, 2024
1 parent 5b6ccb4 commit 13ddbcf
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ class Router(formatOps: FormatOps) {
else {
def getSlb(implicit l: FileLine) = SingleLineBlock(
close,
exclude = excludeBlocks,
exclude = excludeBlocks.excludeCloseDelim,
noSyntaxNL = multipleArgs,
)
val needDifferentFromOneArgPerLine = newlinePolicy.nonEmpty &&
Expand Down Expand Up @@ -1960,6 +1960,7 @@ class Router(formatOps: FormatOps) {
val end = nextSelect
.fold(expire)(x => getLastNonTrivialToken(x.qual))
val exclude = insideBracesBlock(ft, end, parensToo = true)
.excludeCloseDelim
Split(modSpace, 0).withSingleLine(end, exclude = exclude)
}
Seq(noSplit, nlSplitBase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class TokenRanges private (val ranges: Seq[TokenRange]) extends AnyVal {
def filter(f: TokenRange => Boolean): TokenRanges =
new TokenRanges(ranges.filter(f))

def map(f: TokenRange => TokenRange): TokenRanges =
new TokenRanges(ranges.map(f))

def excludeCloseDelim(implicit ftoks: FormatTokens): TokenRanges =
new TokenRanges(ranges.flatMap { x =>
if (!x.lt.left.is[Token.OpenDelim]) Some(x)
else TokenRange.opt(x.lt, ftoks.prev(x.rt))
})

def startOfFirstRange(): Option[Token] = ranges.lastOption.map(_.lt.left)
}

Expand All @@ -31,6 +40,11 @@ object TokenRange {
def apply(lt: FormatToken, rt: FormatToken): TokenRange =
if (lt.idx < rt.idx) new TokenRange(lt, rt) else new TokenRange(rt, lt)

def opt(lt: FormatToken, rt: FormatToken): Option[TokenRange] =
if (lt.idx < rt.idx) Some(new TokenRange(lt, rt))
else if (lt.idx > rt.idx) Some(new TokenRange(rt, lt))
else None

}

object TokenRanges {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class CommunityIntellijScalaSuite(name: String)
class CommunityIntellijScala_2024_2_Suite
extends CommunityIntellijScalaSuite("intellij-scala-2024.2") {

override protected def totalStatesVisited: Option[Int] = Some(47255098)
override protected def totalStatesVisited: Option[Int] = Some(47100766)

override protected def builds = Seq(getBuild(
"2024.2.28",
Expand Down Expand Up @@ -51,7 +51,7 @@ class CommunityIntellijScala_2024_2_Suite
class CommunityIntellijScala_2024_3_Suite
extends CommunityIntellijScalaSuite("intellij-scala-2024.3") {

override protected def totalStatesVisited: Option[Int] = Some(47432293)
override protected def totalStatesVisited: Option[Int] = Some(47277877)

override protected def builds = Seq(getBuild(
"2024.3.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class CommunityScala2Suite(name: String)

class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {

override protected def totalStatesVisited: Option[Int] = Some(34661420)
override protected def totalStatesVisited: Option[Int] = Some(34655844)

override protected def builds =
Seq(getBuild("v2.12.20", dialects.Scala212, 1277))
Expand All @@ -18,7 +18,7 @@ class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {

class CommunityScala2_13Suite extends CommunityScala2Suite("scala-2.13") {

override protected def totalStatesVisited: Option[Int] = Some(43185150)
override protected def totalStatesVisited: Option[Int] = Some(43180047)

override protected def builds =
Seq(getBuild("v2.13.14", dialects.Scala213, 1287))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ abstract class CommunityScala3Suite(name: String)

class CommunityScala3_2Suite extends CommunityScala3Suite("scala-3.2") {

override protected def totalStatesVisited: Option[Int] = Some(32287892)
override protected def totalStatesVisited: Option[Int] = Some(32272482)

override protected def builds = Seq(getBuild("3.2.2", dialects.Scala32, 791))

}

class CommunityScala3_3Suite extends CommunityScala3Suite("scala-3.3") {

override protected def totalStatesVisited: Option[Int] = Some(34858763)
override protected def totalStatesVisited: Option[Int] = Some(34839825)

override protected def builds = Seq(getBuild("3.3.3", dialects.Scala33, 861))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class CommunitySparkSuite(name: String)

class CommunitySpark3_4Suite extends CommunitySparkSuite("spark-3.4") {

override protected def totalStatesVisited: Option[Int] = Some(70715816)
override protected def totalStatesVisited: Option[Int] = Some(70297920)

override protected def builds =
Seq(getBuild("v3.4.1", dialects.Scala213, 2585))
Expand All @@ -18,7 +18,7 @@ class CommunitySpark3_4Suite extends CommunitySparkSuite("spark-3.4") {

class CommunitySpark3_5Suite extends CommunitySparkSuite("spark-3.5") {

override protected def totalStatesVisited: Option[Int] = Some(74808431)
override protected def totalStatesVisited: Option[Int] = Some(74388417)

override protected def builds =
Seq(getBuild("v3.5.3", dialects.Scala213, 2756))
Expand Down
18 changes: 7 additions & 11 deletions scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9578,7 +9578,7 @@ object a {
.map(_.filterNot(_.getCanonicalPath.contains("SSLOptions")))
}
}
>>> { stateVisits = 187751, stateVisits2 = 187751 }
>>> { stateVisits = 3833, stateVisits2 = 3833 }
object a {
private def ignoreUndocumentedPackages(
packages: Seq[Seq[File]]
Expand Down Expand Up @@ -10356,13 +10356,9 @@ object a {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
object a {
- def encodeCookieHeader(cookies: Seq[Cookie]): String = encoder.encode(
- cookies.map(cookie => new DefaultCookie(cookie.name, cookie.value)).asJava
- )
+ def encodeCookieHeader(cookies: Seq[Cookie]): String = encoder
+ .encode(cookies.map(cookie => new DefaultCookie(cookie.name, cookie.value))
+ .asJava)
}
object a {
def encodeCookieHeader(cookies: Seq[Cookie]): String = encoder
.encode(cookies.map { cookie =>
new DefaultCookie(cookie.name, cookie.value)
}.asJava)
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
val explored = Debug.explored.get()
logger.debug(s"Total explored: $explored")
if (!onlyUnit && !onlyManual)
assertEquals(explored, 1503703, "total explored")
assertEquals(explored, 1114863, "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 13ddbcf

Please sign in to comment.