Skip to content

Commit

Permalink
Router: to debug, use FileLine in binpack policies
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Apr 12, 2024
1 parent cc06e02 commit 9778a5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,15 @@ class FormatOps(
getOneArgPerLineSplitsAfterComma(right, splits)
}

def splitOneArgPerLineAfterCommaOnBreak(comma: T): Policy =
delayedBreakPolicyBefore(comma) {
Policy.after(comma) {
case Decision(t @ FormatToken(`comma`, right, _), splits)
if !right.is[T.Comment] || t.hasBreak =>
getOneArgPerLineSplitsAfterComma(right, splits)
}
def splitOneArgPerLineAfterCommaOnBreak(
comma: T,
)(implicit fileLine: FileLine): Policy = delayedBreakPolicyBefore(comma) {
Policy.after(comma) {
case Decision(t @ FormatToken(`comma`, right, _), splits)
if !right.is[T.Comment] || t.hasBreak =>
getOneArgPerLineSplitsAfterComma(right, splits)
}
}

private def getOneArgPerLineSplitsAfterComma(r: T, s: Seq[Split]) =
if (r.is[T.LeftBrace]) SplitTag.OneArgPerLine.activateOnly(s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1275,17 +1275,22 @@ class Router(formatOps: FormatOps) {
}

val nlPolicy = {
def newlineBeforeClose = decideNewlinesOnlyBeforeClose(close)
def newlineBeforeClose(implicit fileLine: FileLine) =
decideNewlinesOnlyBeforeClose(close)
def binPackOnelinePolicyOpt =
if (needOnelinePolicy) nextCommaOnelinePolicy else Some(NoPolicy)
def bothPolicies = newlineBeforeClose & binPackOnelinePolicyOpt
def bothPolicies(implicit fileLine: FileLine) = newlineBeforeClose &
binPackOnelinePolicyOpt
def configStylePolicy(implicit fileLine: FileLine) =
splitOneArgOneLine(close, leftOwner) | newlineBeforeClose

if (flags.configStyle != ConfigStyle.None)
if (
(style.newlines.source == Newlines.keep &&
flags.configStyle == ConfigStyle.Source) ||
styleMap.forcedBinPack(leftOwner)
) bothPolicies
else splitOneArgOneLine(close, leftOwner) | newlineBeforeClose
else configStylePolicy
else if (
flags.dangleForTrailingCommas ||
flags.shouldDangle &&
Expand Down

0 comments on commit 9778a5e

Please sign in to comment.