mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #25325 from uniqueiniquity/stopFoldingRegionDelimiters
Stop folding region delimiters
This commit is contained in:
@@ -63,7 +63,7 @@ namespace ts.OutliningElementsCollector {
|
||||
const currentLineStart = lineStarts[i];
|
||||
const lineEnd = i + 1 === lineStarts.length ? sourceFile.getEnd() : lineStarts[i + 1] - 1;
|
||||
const lineText = sourceFile.text.substring(currentLineStart, lineEnd);
|
||||
const result = lineText.match(/^\s*\/\/\s*#(end)?region(?:\s+(.*))?(?:\r)?$/);
|
||||
const result = isRegionDelimiter(lineText);
|
||||
if (!result || isInComment(sourceFile, currentLineStart)) {
|
||||
continue;
|
||||
}
|
||||
@@ -83,16 +83,30 @@ namespace ts.OutliningElementsCollector {
|
||||
}
|
||||
}
|
||||
|
||||
const regionDelimiterRegExp = /^\s*\/\/\s*#(end)?region(?:\s+(.*))?(?:\r)?$/;
|
||||
function isRegionDelimiter(lineText: string) {
|
||||
return regionDelimiterRegExp.exec(lineText);
|
||||
}
|
||||
|
||||
function addOutliningForLeadingCommentsForNode(n: Node, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push<OutliningSpan>): void {
|
||||
const comments = getLeadingCommentRangesOfNode(n, sourceFile);
|
||||
if (!comments) return;
|
||||
let firstSingleLineCommentStart = -1;
|
||||
let lastSingleLineCommentEnd = -1;
|
||||
let singleLineCommentCount = 0;
|
||||
const sourceText = sourceFile.getFullText();
|
||||
for (const { kind, pos, end } of comments) {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
switch (kind) {
|
||||
case SyntaxKind.SingleLineCommentTrivia:
|
||||
// never fold region delimiters into single-line comment regions
|
||||
const commentText = sourceText.slice(pos, end);
|
||||
if (isRegionDelimiter(commentText)) {
|
||||
combineAndAddMultipleSingleLineComments();
|
||||
singleLineCommentCount = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// For single line comments, combine consecutive ones (2 or more) into
|
||||
// a single span from the start of the first till the end of the last
|
||||
if (singleLineCommentCount === 0) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
////[|//#region
|
||||
////function foo()[| {
|
||||
////
|
||||
////}|]
|
||||
////[|//these
|
||||
//////should|]
|
||||
//////#endregion not you|]
|
||||
////[|// be
|
||||
////// together|]
|
||||
////
|
||||
////[|//#region bla bla bla
|
||||
////
|
||||
////function bar()[| { }|]
|
||||
////
|
||||
//////#endregion|]
|
||||
|
||||
verify.outliningSpansInCurrentFile(test.ranges());
|
||||
Reference in New Issue
Block a user