Skip to content

Commit

Permalink
FormatOps: use new Tokens methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 18, 2024
1 parent 2f7c302 commit 018dd04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,9 @@ class FormatOps(
case Some(p: Case) => p.cond.contains(fullInfix)
case _ => false
}) || { // check if the break was in the original code
val atokens = app.tokens
val ltidx = atokens.indexOf(ft.left)
ltidx >= 0 && {
val rtidx = atokens.skipIf(_.is[T.Trivia], ltidx + 1)
rtidx >= 0 && (atokens(rtidx) eq ft.right) // no rewritten tokens
}
val optokens = app.op.tokens
val idx = optokens.rskipWideIf(_.is[T.Trivia], -1, Int.MinValue)
optokens.getWideOpt(idx).contains(ft.left) // no rewritten tokens
}
val mod =
if (ft.noBreak || !okToBreak) spaceMod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,13 @@ object FormatTokens {
var lmeta: FT.TokenMeta = null
val result = Array.newBuilder[FT]
var ftIdx = 0
var wsIdx = 0
var tokIdx = 0
var prevNonWsIdx = -1
var fmtWasOff = false
val arr = tokens.toArray
def process(right: T): Unit = {
def process(right: T, tokIdx: Int): Unit = if (!right.is[T.Whitespace]) {
val rmeta = FT.TokenMeta(owners(hash(right)), right.text)
if (left eq null) fmtWasOff = isFormatOff(right)
else {
val between = arr.slice(wsIdx, tokIdx)
val between = tokens.arraySlice(prevNonWsIdx + 1, tokIdx)
val fmtIsOff = fmtWasOff || isFormatOff(right)
fmtWasOff = if (fmtWasOff) !isFormatOn(right) else fmtIsOff
val meta = FT.Meta(between, ftIdx, fmtIsOff, lmeta, rmeta)
Expand All @@ -435,15 +433,9 @@ object FormatTokens {
}
left = right
lmeta = rmeta
prevNonWsIdx = tokIdx
}
val tokCnt = arr.length
while (tokIdx < tokCnt) arr(tokIdx) match {
case _: T.Whitespace => tokIdx += 1
case right =>
process(right)
tokIdx += 1
wsIdx = tokIdx
}
tokens.foreachWithIndex(process)

val ftoks = new FormatTokens(result.result)
val styleMap = new StyleMap(ftoks, style)
Expand Down

0 comments on commit 018dd04

Please sign in to comment.