Skip to content

Commit

Permalink
FormatWriter: fix alignment for incorrect // pos
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 13, 2021
1 parent 8fa0b38 commit 6343315
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -990,28 +990,34 @@ class FormatWriter(formatOps: FormatOps) {
columnShift = 0
}
val floc = locations(idx)
val ft = floc.formatToken
idx += 1
columnShift += floc.shift
if (floc.hasBreakAfter || floc.formatToken.leftHasNewline) floc
if (floc.hasBreakAfter || ft.leftHasNewline) floc
else {
getAlignContainer(floc).foreach { container =>
def appendCandidate() =
columnCandidates += new AlignStop(
getAlignColumn(floc) + columnShift,
floc,
alignContainer,
getAlignHashKey(floc)
)
if (alignContainer eq null)
alignContainer = container
else if (alignContainer ne container) {
val pos1 = alignContainer.pos
val pos2 = container.pos
if (pos2.start <= pos1.start && pos2.end >= pos1.end) {
if (isSingleLineComment(ft.right)) {
if (pos1.end >= tokens.prevNonCommentSameLine(ft).left.end)
appendCandidate()
} else if (pos2.start <= pos1.start && pos2.end >= pos1.end) {
alignContainer = container
columnCandidates.clear()
}
}
if (alignContainer eq container)
columnCandidates += new AlignStop(
getAlignColumn(floc) + columnShift,
floc,
container,
getAlignHashKey(floc)
)
appendCandidate()
}
if (idx < locations.length) processLine else floc
}
Expand Down
6 changes: 3 additions & 3 deletions scalafmt-tests/src/test/resources/align/DefaultWithAlign.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ val (xTranslation, yTranslation) = (isHMirror, isVMirror) match
case (false, false) => (-(rotationWidth / 2).toInt, -(rotationHeight / 2).toInt) /* c */ // BR
>>>
val (xTranslation, yTranslation) = (isHMirror, isVMirror) match
case (true, true) => ((rotationWidth / 2).toInt, (rotationHeight / 2).toInt) /* c */ // TL
case (true, false) => ((rotationHeight / 2).toInt, -(rotationWidth / 2).toInt) /* c */ // BL
case (false, true) => (-(rotationHeight / 2).toInt, (rotationWidth / 2).toInt) /* c */ // TR
case (true, true) => ((rotationWidth / 2).toInt, (rotationHeight / 2).toInt) /* c */ // TL
case (true, false) => ((rotationHeight / 2).toInt, -(rotationWidth / 2).toInt) /* c */ // BL
case (false, true) => (-(rotationHeight / 2).toInt, (rotationWidth / 2).toInt) /* c */ // TR
case (false, false) => (-(rotationWidth / 2).toInt, -(rotationHeight / 2).toInt) /* c */ // BR

0 comments on commit 6343315

Please sign in to comment.