@@ -63,7 +63,7 @@ namespace ts.OutliningElementsCollector {
63
63
const currentLineStart = lineStarts [ i ] ;
64
64
const lineEnd = i + 1 === lineStarts . length ? sourceFile . getEnd ( ) : lineStarts [ i + 1 ] - 1 ;
65
65
const lineText = sourceFile . text . substring ( currentLineStart , lineEnd ) ;
66
- const result = lineText . match ( / ^ \s * \/ \/ \s * # ( e n d ) ? r e g i o n (?: \s + ( . * ) ) ? (?: \r ) ? $ / ) ;
66
+ const result = isRegionDelimiter ( lineText ) ;
67
67
if ( ! result || isInComment ( sourceFile , currentLineStart ) ) {
68
68
continue ;
69
69
}
@@ -83,16 +83,30 @@ namespace ts.OutliningElementsCollector {
83
83
}
84
84
}
85
85
86
+ const regionDelimiterRegExp = / ^ \s * \/ \/ \s * # ( e n d ) ? r e g i o n (?: \s + ( .* ) ) ? (?: \r ) ? $ / ;
87
+ function isRegionDelimiter ( lineText : string ) {
88
+ return regionDelimiterRegExp . exec ( lineText ) ;
89
+ }
90
+
86
91
function addOutliningForLeadingCommentsForNode ( n : Node , sourceFile : SourceFile , cancellationToken : CancellationToken , out : Push < OutliningSpan > ) : void {
87
92
const comments = getLeadingCommentRangesOfNode ( n , sourceFile ) ;
88
93
if ( ! comments ) return ;
89
94
let firstSingleLineCommentStart = - 1 ;
90
95
let lastSingleLineCommentEnd = - 1 ;
91
96
let singleLineCommentCount = 0 ;
97
+ const sourceText = sourceFile . getFullText ( ) ;
92
98
for ( const { kind, pos, end } of comments ) {
93
99
cancellationToken . throwIfCancellationRequested ( ) ;
94
100
switch ( kind ) {
95
101
case SyntaxKind . SingleLineCommentTrivia :
102
+ // never fold region delimiters into single-line comment regions
103
+ const commentText = sourceText . slice ( pos , end ) ;
104
+ if ( isRegionDelimiter ( commentText ) ) {
105
+ combineAndAddMultipleSingleLineComments ( ) ;
106
+ singleLineCommentCount = 0 ;
107
+ break ;
108
+ }
109
+
96
110
// For single line comments, combine consecutive ones (2 or more) into
97
111
// a single span from the start of the first till the end of the last
98
112
if ( singleLineCommentCount === 0 ) {
0 commit comments