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

FormatTokensRewrite: claim implicit FormatToken #3863

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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 @@ -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
Loading