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

FormatOps: use new Tokens methods #4562

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
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 @@ -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
Loading