From 3ccc6fa8fef623a5adc4d20fb9e8bd06a65206d6 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:04:00 -0700 Subject: [PATCH] FormatTokensRewrite: `claim` implicit FormatToken --- .../org/scalafmt/rewrite/FormatTokensRewrite.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/FormatTokensRewrite.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/FormatTokensRewrite.scala index 7a719fd8f8..959bfd82ec 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/FormatTokensRewrite.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/FormatTokensRewrite.scala @@ -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) } } @@ -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) @@ -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 }