Skip to content

Commit

Permalink
FormatTokensRewrite: token map expects left token
Browse files Browse the repository at this point in the history
Hence, point right token to next index instead.
  • Loading branch information
kitbellew committed Mar 27, 2024
1 parent 87c44c3 commit e4d8ba7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class FormatTokens(leftTok2tok: Map[TokenHash, Int])(
val ft = arr(idx)
if (ft.left eq tok) ft
else if (isBefore) {
if (ft.left.start < tok.start) ft else at(idx - 1)
if (ft.left.start <= tok.start) ft else at(idx - 1)
} else {
if (ft.left.start > tok.start) ft else at(idx + 1)
if (ft.left.start >= tok.start) ft else at(idx + 1)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class FormatTokensRewrite(
tokenMap += FormatTokens.thash(rtOld) -> dstidx
copySlice(idx)
def append(): Unit = {
if (rtOld ne ft.right) mapOld(appended)
appended += 1
result += ft
if (rtOld ne ft.right) mapOld(appended)
}
def remove(dstidx: Int): Unit = {
mapOld(dstidx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
// move right to the end of the function
val rType = new ReplacementType.RemoveAndResurrect(pft.meta.idx - 1)
left -> replaceToken("}", rtype = rType) {
// create a different token so that any child tree wouldn't own it
new Token.RightBrace(rb.input, rb.dialect, rb.start)
// create a shifted token so that any child tree wouldn't own it
new Token.RightBrace(rb.input, rb.dialect, rb.start + 1)
}
} else null // don't know how to Replace
case _ => null
Expand Down

0 comments on commit e4d8ba7

Please # to comment.