Skip to content

Commit bf508cb

Browse files
Merge pull request #25325 from uniqueiniquity/stopFoldingRegionDelimiters
Stop folding region delimiters
2 parents 30db300 + ba8bc55 commit bf508cb

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/services/outliningElementsCollector.ts

Lines changed: 15 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,30 @@ namespace ts.OutliningElementsCollector {
8383
}
8484
}
8585

86+
const regionDelimiterRegExp = /^\s*\/\/\s*#(end)?region(?:\s+(.*))?(?:\r)?$/;
87+
function isRegionDelimiter(lineText: string) {
88+
return regionDelimiterRegExp.exec(lineText);
89+
}
90+
8691
function addOutliningForLeadingCommentsForNode(n: Node, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push<OutliningSpan>): void {
8792
const comments = getLeadingCommentRangesOfNode(n, sourceFile);
8893
if (!comments) return;
8994
let firstSingleLineCommentStart = -1;
9095
let lastSingleLineCommentEnd = -1;
9196
let singleLineCommentCount = 0;
97+
const sourceText = sourceFile.getFullText();
9298
for (const { kind, pos, end } of comments) {
9399
cancellationToken.throwIfCancellationRequested();
94100
switch (kind) {
95101
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+
96110
// For single line comments, combine consecutive ones (2 or more) into
97111
// a single span from the start of the first till the end of the last
98112
if (singleLineCommentCount === 0) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
////[|//#region
2+
////function foo()[| {
3+
////
4+
////}|]
5+
////[|//these
6+
//////should|]
7+
//////#endregion not you|]
8+
////[|// be
9+
////// together|]
10+
////
11+
////[|//#region bla bla bla
12+
////
13+
////function bar()[| { }|]
14+
////
15+
//////#endregion|]
16+
17+
verify.outliningSpansInCurrentFile(test.ranges());

0 commit comments

Comments
 (0)