File tree 3 files changed +20
-3
lines changed
3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -601,6 +601,20 @@ object Scanners {
601
601
lastWidth = r.knownWidth
602
602
newlineIsSeparating = r.isInstanceOf [InBraces ]
603
603
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
+
604
618
if newlineIsSeparating
605
619
&& canEndStatTokens.contains(lastToken)
606
620
&& canStartStatTokens.contains(token)
@@ -613,9 +627,8 @@ object Scanners {
613
627
|| nextWidth == lastWidth && (indentPrefix == MATCH || indentPrefix == CATCH ) && token != CASE then
614
628
if currentRegion.isOutermost then
615
629
if nextWidth < lastWidth then currentRegion = topLevelRegion(nextWidth)
616
- else if ! isLeadingInfixOperator(nextWidth) && ! statCtdTokens.contains(lastToken) && lastToken != INDENT then
630
+ else if canDedent then
617
631
currentRegion match
618
- case _ if token == EOF => // no OUTDENT at EOF
619
632
case r : Indented =>
620
633
insert(OUTDENT , offset)
621
634
handleNewIndentWidth(r.enclosing, ir =>
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ object Chars:
50
50
}
51
51
52
52
/** Is character a whitespace character (but not a new line)? */
53
- def isWhitespace (c : Char ): Boolean =
53
+ inline def isWhitespace (c : Char ): Boolean =
54
54
c == ' ' || c == '\t ' || c == CR
55
55
56
56
/** Can character form part of a doc comment variable $xxx? */
Original file line number Diff line number Diff line change
1
+ scala> println:
2
+ | "hello"
3
+ |
4
+ hello
You can’t perform that action at this time.
0 commit comments