Skip to content

Commit

Permalink
FormatTokens: add prevNonCommentSameLineBefore
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 7, 2024
1 parent 9ab37c4 commit ad5b870
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ class FormatOps(
final def leadingComment(ft: FormatToken): FormatToken =
if (ft.hasBlankLine || !ft.left.is[T.Comment]) ft
else {
val pft = tokens.prevNonCommentSameLine(prev(ft))
val pft = tokens.prevNonCommentSameLineBefore(ft)
if (pft.noBreak) ft else leadingComment(pft)
}

Expand Down Expand Up @@ -2858,7 +2858,7 @@ class FormatOps(
val beforeClose =
if (!closeFt.left.is[T.Comment]) Some(closeFt.left)
else {
val tok = tokens.prevNonCommentSameLine(prev(closeFt)).left
val tok = tokens.prevNonCommentSameLineBefore(closeFt).left
if (tok.is[T.Comment]) None else Some(tok)
}
beforeClose.exists(rightIsCloseDelimToAddTrailingComma(_, closeFt))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ class FormatTokens(leftTok2tok: Map[TokenOps.TokenHash, Int])(
final def prevNonCommentBefore(curr: FormatToken): FormatToken =
prevNonComment(prev(curr))

@inline
final def prevNonCommentSameLineBefore(curr: FormatToken): FormatToken =
prevNonCommentSameLine(prev(curr))

@tailrec
final def getOnOrBeforeOwned(ft: FormatToken, tree: Tree): FormatToken = {
val prevFt = prevNonCommentBefore(ft)
Expand Down

0 comments on commit ad5b870

Please sign in to comment.