File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -601,6 +601,20 @@ object Scanners {
601601 lastWidth = r.knownWidth
602602 newlineIsSeparating = r.isInstanceOf [InBraces ]
603603
604+ // can emit OUTDENT if line is not non-empty blank line at EOF
605+ inline def isTrailingBlankLine : Boolean =
606+ token == EOF && {
607+ val end = buf.length - 1 // take terminal NL as empty last line
608+ val prev = buf.lastIndexWhere(! isWhitespace(_), end = end)
609+ prev < 0 || end - prev > 0 && isLineBreakChar(buf(prev))
610+ }
611+
612+ inline def canDedent : Boolean =
613+ lastToken != INDENT
614+ && ! isLeadingInfixOperator(nextWidth)
615+ && ! statCtdTokens.contains(lastToken)
616+ && ! isTrailingBlankLine
617+
604618 if newlineIsSeparating
605619 && canEndStatTokens.contains(lastToken)
606620 && canStartStatTokens.contains(token)
@@ -613,9 +627,8 @@ object Scanners {
613627 || nextWidth == lastWidth && (indentPrefix == MATCH || indentPrefix == CATCH ) && token != CASE then
614628 if currentRegion.isOutermost then
615629 if nextWidth < lastWidth then currentRegion = topLevelRegion(nextWidth)
616- else if ! isLeadingInfixOperator(nextWidth) && ! statCtdTokens.contains(lastToken) && lastToken != INDENT then
630+ else if canDedent then
617631 currentRegion match
618- case _ if token == EOF => // no OUTDENT at EOF
619632 case r : Indented =>
620633 insert(OUTDENT , offset)
621634 handleNewIndentWidth(r.enclosing, ir =>
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ object Chars:
5050 }
5151
5252 /** Is character a whitespace character (but not a new line)? */
53- def isWhitespace (c : Char ): Boolean =
53+ inline def isWhitespace (c : Char ): Boolean =
5454 c == ' ' || c == '\t ' || c == CR
5555
5656 /** Can character form part of a doc comment variable $xxx? */
You can’t perform that action at this time.
0 commit comments