Skip to content

Commit

Permalink
FormatTokensRewrite: claim implicit FormatToken
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 27, 2024
1 parent d749bac commit 937eef7
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ class FormatTokensRewrite(
replacement match {
case None =>
tokens(ldelimIdx) = null
session.claim(ft.meta.idx, null)
session.claim(null)
case Some((ltRepl, rtRepl)) =>
tokens(ldelimIdx) = ltRepl
session.claim(ft.meta.idx, rtRepl)
session.claim(rtRepl)
}
}

Expand Down Expand Up @@ -337,6 +337,12 @@ object FormatTokensRewrite {
}
}

@inline
private[rewrite] def claim(repl: Replacement)(implicit
ft: FormatToken
): Int =
claim(ft.meta.idx, repl)

private def justClaim(ftIdx: Int)(repl: Replacement): Int = {
val idx = tokens.length
val claimedIdx = claimed.getOrElseUpdate(ftIdx, idx)
Expand All @@ -361,7 +367,7 @@ object FormatTokensRewrite {
attemptedRule: Rule
)(implicit ft: FormatToken, style: ScalafmtConfig): Option[Rule] =
if (attemptedRule.enabled) attemptedRule.onToken.map { repl =>
val idx = claim(ft.meta.idx, repl)
val idx = claim(repl)
repl.claim.foreach { claimed.getOrElseUpdate(_, idx) }
repl.rule
}
Expand Down

0 comments on commit 937eef7

Please sign in to comment.