Skip to content

Commit 6991860

Browse files
author
Benjamin Lichtman
committed
Stop including region delimiter comments in comment fold regions
1 parent 30db300 commit 6991860

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/services/outliningElementsCollector.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace ts.OutliningElementsCollector {
6363
const currentLineStart = lineStarts[i];
6464
const lineEnd = i + 1 === lineStarts.length ? sourceFile.getEnd() : lineStarts[i + 1] - 1;
6565
const lineText = sourceFile.text.substring(currentLineStart, lineEnd);
66-
const result = lineText.match(/^\s*\/\/\s*#(end)?region(?:\s+(.*))?(?:\r)?$/);
66+
const result = isRegionDelimiter(lineText);
6767
if (!result || isInComment(sourceFile, currentLineStart)) {
6868
continue;
6969
}
@@ -83,16 +83,29 @@ namespace ts.OutliningElementsCollector {
8383
}
8484
}
8585

86+
function isRegionDelimiter(lineText: string) {
87+
return lineText.match(/^\s*\/\/\s*#(end)?region(?:\s+(.*))?(?:\r)?$/);
88+
}
89+
8690
function addOutliningForLeadingCommentsForNode(n: Node, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push<OutliningSpan>): void {
8791
const comments = getLeadingCommentRangesOfNode(n, sourceFile);
8892
if (!comments) return;
8993
let firstSingleLineCommentStart = -1;
9094
let lastSingleLineCommentEnd = -1;
9195
let singleLineCommentCount = 0;
96+
const sourceText = sourceFile.getFullText();
9297
for (const { kind, pos, end } of comments) {
9398
cancellationToken.throwIfCancellationRequested();
9499
switch (kind) {
95100
case SyntaxKind.SingleLineCommentTrivia:
101+
// never fold region delimiters into single-line comment regions
102+
const commentText = sourceText.slice(pos, end);
103+
if (isRegionDelimiter(commentText)) {
104+
combineAndAddMultipleSingleLineComments();
105+
singleLineCommentCount = 0;
106+
break;
107+
}
108+
96109
// For single line comments, combine consecutive ones (2 or more) into
97110
// a single span from the start of the first till the end of the last
98111
if (singleLineCommentCount === 0) {

0 commit comments

Comments
 (0)