From 562d988614e967910f06da72ce9d0f57c7c8a39a Mon Sep 17 00:00:00 2001 From: uniqueiniquity Date: Mon, 21 Aug 2017 11:19:21 -0700 Subject: [PATCH] Exclude region delimiters in multiline comments --- src/services/outliningElementsCollector.ts | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 7c4bf24d580..82ac22e644c 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -107,26 +107,28 @@ namespace ts.OutliningElementsCollector { } function isRegionStart(start: number, end: number) { - const comment = sourceFile.text.substring(start, end); - const result = comment.match(regionStart); + if (!ts.formatting.getRangeOfEnclosingComment(sourceFile, start, /*onlyMultiLine*/ true)) { + const comment = sourceFile.text.substring(start, end); + const result = comment.match(regionStart); - if (result && result.length > 0) { - const sections = result[0].split(" ").filter(function (s) { return s !== ""; }); + if (result && result.length > 0) { + const sections = result[0].split(" ").filter(function (s) { return s !== ""; }); - if (sections[0] === "//") { - if (sections.length > 2) { - return result[0].substring(result[0].indexOf(sections[2])); + if (sections[0] === "//") { + if (sections.length > 2) { + return result[0].substring(result[0].indexOf(sections[2])); + } + else { + return regionText; + } } else { - return regionText; - } - } - else { - if (sections.length > 1) { - return result[0].substring(result[0].indexOf(sections[1])); - } - else { - return regionText; + if (sections.length > 1) { + return result[0].substring(result[0].indexOf(sections[1])); + } + else { + return regionText; + } } } } @@ -134,8 +136,11 @@ namespace ts.OutliningElementsCollector { } function isRegionEnd(start: number, end: number) { - const comment = sourceFile.text.substring(start, end); - return comment.match(regionEnd); + if (!ts.formatting.getRangeOfEnclosingComment(sourceFile, start, /*onlyMultiLine*/ true)) { + const comment = sourceFile.text.substring(start, end); + return comment.match(regionEnd); + } + return undefined; } function gatherRegions(): void {