From f1713c92d34435d59ce089c5e383c91479bd9ee1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 4 May 2018 10:39:47 -0700 Subject: [PATCH 1/9] Add outlining spans for import declarations --- src/harness/fourslash.ts | 4 +- src/services/outliningElementsCollector.ts | 43 ++++++++++++++++--- src/services/types.ts | 3 +- .../fourslash/getOutliningSpansForImports.ts | 20 +++++++++ 4 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 tests/cases/fourslash/getOutliningSpansForImports.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8b9929161e2..2c2d921eebf 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2467,7 +2467,7 @@ Actual: ${stringify(fullActual)}`); Harness.IO.log(stringify(spans)); } - public verifyOutliningSpans(spans: Range[], kind?: "comment" | "region" | "code") { + public verifyOutliningSpans(spans: Range[], kind?: "comment" | "region" | "code" | "import") { const actual = this.languageService.getOutliningSpans(this.activeFile.fileName); if (actual.length !== spans.length) { @@ -4299,7 +4299,7 @@ namespace FourSlashInterface { this.state.verifyCurrentNameOrDottedNameSpanText(text); } - public outliningSpansInCurrentFile(spans: FourSlash.Range[], kind?: "comment" | "region" | "code") { + public outliningSpansInCurrentFile(spans: FourSlash.Range[], kind?: "comment" | "region" | "code" | "import") { this.state.verifyOutliningSpans(spans, kind); } diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 10684c268be..cca5f843938 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -9,7 +9,35 @@ namespace ts.OutliningElementsCollector { function addNodeOutliningSpans(sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push): void { let depthRemaining = 40; - sourceFile.forEachChild(function walk(n) { + let current = 0; + const statements = sourceFile.statements; + const n = statements.length; + while (current < n) { + while (current < n && !isAnyImportSyntax(statements[current])) { + visitNonImportNode(statements[current]); + current++; + } + if (current === n) break; + const firstImport = statements[current]; + while (current < n && isAnyImportSyntax(statements[current])) { + visitImportNode(statements[current] as AnyImportSyntax, sourceFile, cancellationToken, out); + current++; + } + const lastImport = current < n ? statements[current - 1] : statements[n - 1]; + if (lastImport !== firstImport) { + out.push(createOutliningSpanFromBounds(findChildOfKind(firstImport, SyntaxKind.ImportKeyword, sourceFile)!.getStart(sourceFile), lastImport.getEnd(), OutliningSpanKind.Import)); + } + } + + function visitImportNode(node: AnyImportSyntax, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push) { + // Add outlining spans for comments if they exist + addOutliningForLeadingCommentsForNode(node, sourceFile, cancellationToken, out); + // Add outlining spans for the import statement itself if applicable + const span = getOutliningSpanForNode(node, sourceFile); + if (span) out.push(span); + } + + function visitNonImportNode(n: Node) { if (depthRemaining === 0) return; cancellationToken.throwIfCancellationRequested(); @@ -23,17 +51,17 @@ namespace ts.OutliningElementsCollector { depthRemaining--; if (isIfStatement(n) && n.elseStatement && isIfStatement(n.elseStatement)) { // Consider an 'else if' to be on the same depth as the 'if'. - walk(n.expression); - walk(n.thenStatement); + visitNonImportNode(n.expression); + visitNonImportNode(n.thenStatement); depthRemaining++; - walk(n.elseStatement); + visitNonImportNode(n.elseStatement); depthRemaining--; } else { - n.forEachChild(walk); + n.forEachChild(visitNonImportNode); } depthRemaining++; - }); + } } function addRegionOutliningSpans(sourceFile: SourceFile, out: Push): void { @@ -149,6 +177,9 @@ namespace ts.OutliningElementsCollector { return spanForObjectOrArrayLiteral(n); case SyntaxKind.ArrayLiteralExpression: return spanForObjectOrArrayLiteral(n, SyntaxKind.OpenBracketToken); + case SyntaxKind.ImportDeclaration: + const importClause = (n as ImportDeclaration).importClause; + return importClause && importClause.namedBindings && importClause.namedBindings.kind !== SyntaxKind.NamespaceImport ? spanForNode(importClause.namedBindings) : undefined; } function spanForObjectOrArrayLiteral(node: Node, open: SyntaxKind.OpenBraceToken | SyntaxKind.OpenBracketToken = SyntaxKind.OpenBraceToken): OutliningSpan | undefined { diff --git a/src/services/types.ts b/src/services/types.ts index 31baf7df399..48eb25f8a3e 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -826,7 +826,8 @@ namespace ts { export const enum OutliningSpanKind { Comment = "comment", Region = "region", - Code = "code" + Code = "code", + Import = "import" } export const enum OutputFileType { diff --git a/tests/cases/fourslash/getOutliningSpansForImports.ts b/tests/cases/fourslash/getOutliningSpansForImports.ts new file mode 100644 index 00000000000..23b625059c5 --- /dev/null +++ b/tests/cases/fourslash/getOutliningSpansForImports.ts @@ -0,0 +1,20 @@ +/// + + +////[|import * as ns from "mod"; +//// +////import d from "mod"; +////import { a, b, c } from "mod"; +//// +////import r = require("mod");|] +//// +////// statement +////var x = 0; +//// +////// another set of imports +////[|import * as ns from "mod"; +////import d from "mod"; +////import { a, b, c } from "mod"; +////import r = require("mod");|] + +verify.outliningSpansInCurrentFile(test.ranges(), "import"); From 2d725feb51a317905daea8b5abc7b36edd260211 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 4 May 2018 11:26:03 -0700 Subject: [PATCH 2/9] Add outlining span for named bindings in import declarations --- src/services/outliningElementsCollector.ts | 17 +++++++++++------ .../fourslash/getOutliningSpansForImports.ts | 4 ++-- ...OutliningSpansForImportsWithNamedBindings.ts | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 tests/cases/fourslash/getOutliningSpansForImportsWithNamedBindings.ts diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index cca5f843938..c58e122356a 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -33,8 +33,16 @@ namespace ts.OutliningElementsCollector { // Add outlining spans for comments if they exist addOutliningForLeadingCommentsForNode(node, sourceFile, cancellationToken, out); // Add outlining spans for the import statement itself if applicable - const span = getOutliningSpanForNode(node, sourceFile); - if (span) out.push(span); + if (isImportDeclaration(node) && node.importClause && node.importClause.namedBindings && + node.importClause.namedBindings.kind !== SyntaxKind.NamespaceImport && node.importClause.namedBindings.elements.length) { + const openToken = findChildOfKind(node.importClause.namedBindings, SyntaxKind.OpenBraceToken, sourceFile); + const closeToken = findChildOfKind(node.importClause.namedBindings, SyntaxKind.CloseBraceToken, sourceFile); + if (openToken && closeToken) { + out.push(createOutliningSpan( + createTextSpanFromBounds(openToken.getStart(sourceFile), closeToken.getEnd()), + OutliningSpanKind.Import, createTextSpanFromNode(node, sourceFile))); + } + } } function visitNonImportNode(n: Node) { @@ -177,10 +185,7 @@ namespace ts.OutliningElementsCollector { return spanForObjectOrArrayLiteral(n); case SyntaxKind.ArrayLiteralExpression: return spanForObjectOrArrayLiteral(n, SyntaxKind.OpenBracketToken); - case SyntaxKind.ImportDeclaration: - const importClause = (n as ImportDeclaration).importClause; - return importClause && importClause.namedBindings && importClause.namedBindings.kind !== SyntaxKind.NamespaceImport ? spanForNode(importClause.namedBindings) : undefined; - } + } function spanForObjectOrArrayLiteral(node: Node, open: SyntaxKind.OpenBraceToken | SyntaxKind.OpenBracketToken = SyntaxKind.OpenBraceToken): OutliningSpan | undefined { // If the block has no leading keywords and is inside an array literal, diff --git a/tests/cases/fourslash/getOutliningSpansForImports.ts b/tests/cases/fourslash/getOutliningSpansForImports.ts index 23b625059c5..198adc9c551 100644 --- a/tests/cases/fourslash/getOutliningSpansForImports.ts +++ b/tests/cases/fourslash/getOutliningSpansForImports.ts @@ -4,7 +4,7 @@ ////[|import * as ns from "mod"; //// ////import d from "mod"; -////import { a, b, c } from "mod"; +////import [|{ a, b, c }|] from "mod"; //// ////import r = require("mod");|] //// @@ -14,7 +14,7 @@ ////// another set of imports ////[|import * as ns from "mod"; ////import d from "mod"; -////import { a, b, c } from "mod"; +////import [|{ a, b, c }|] from "mod"; ////import r = require("mod");|] verify.outliningSpansInCurrentFile(test.ranges(), "import"); diff --git a/tests/cases/fourslash/getOutliningSpansForImportsWithNamedBindings.ts b/tests/cases/fourslash/getOutliningSpansForImportsWithNamedBindings.ts new file mode 100644 index 00000000000..4e5336ba3b0 --- /dev/null +++ b/tests/cases/fourslash/getOutliningSpansForImportsWithNamedBindings.ts @@ -0,0 +1,17 @@ +/// + + +////[|import [|{ +//// a, +//// b as B, +//// c +////}|] from "mod"; +//// +//// +////import { } from "mod"; +////import * as ns from "mod"; +////import d from "mod";|] + +verify.outliningSpansInCurrentFile(test.ranges(), "import"); + + From dae112668045b01771673812b9cde544f5229437 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 4 May 2018 11:27:10 -0700 Subject: [PATCH 3/9] Accept baselines --- tests/baselines/reference/api/tsserverlibrary.d.ts | 3 ++- tests/baselines/reference/api/typescript.d.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index c52960b574b..5e99f782526 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4880,7 +4880,8 @@ declare namespace ts { enum OutliningSpanKind { Comment = "comment", Region = "region", - Code = "code" + Code = "code", + Import = "import" } enum OutputFileType { JavaScript = 0, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 9c2639305df..59dcc58e187 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4880,7 +4880,8 @@ declare namespace ts { enum OutliningSpanKind { Comment = "comment", Region = "region", - Code = "code" + Code = "code", + Import = "import" } enum OutputFileType { JavaScript = 0, From a59ac8fd33f62a9519fa5dfb50e341995145f7ca Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 4 May 2018 11:29:54 -0700 Subject: [PATCH 4/9] Update test --- tests/cases/fourslash/incrementalParsingWithJsDoc.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/fourslash/incrementalParsingWithJsDoc.ts b/tests/cases/fourslash/incrementalParsingWithJsDoc.ts index cd709530f9c..324cc0608ab 100644 --- a/tests/cases/fourslash/incrementalParsingWithJsDoc.ts +++ b/tests/cases/fourslash/incrementalParsingWithJsDoc.ts @@ -1,8 +1,8 @@ /// -////import a from 'a/aaaaaaa/aaaaaaa/aaaaaa/aaaaaaa'; +////[|import a from 'a/aaaaaaa/aaaaaaa/aaaaaa/aaaaaaa'; /////**/import b from 'b'; -////import c from 'c'; +////import c from 'c';|] //// ////[|/** @internal */|] ////export class LanguageIdentifier[| { }|] From ea966387012291a9dec2f8ecf1703fb79674580d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 4 May 2018 15:59:55 -0700 Subject: [PATCH 5/9] Fix indentation --- src/services/outliningElementsCollector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index c58e122356a..eb5bfa4c0d5 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -185,7 +185,7 @@ namespace ts.OutliningElementsCollector { return spanForObjectOrArrayLiteral(n); case SyntaxKind.ArrayLiteralExpression: return spanForObjectOrArrayLiteral(n, SyntaxKind.OpenBracketToken); - } + } function spanForObjectOrArrayLiteral(node: Node, open: SyntaxKind.OpenBraceToken | SyntaxKind.OpenBracketToken = SyntaxKind.OpenBraceToken): OutliningSpan | undefined { // If the block has no leading keywords and is inside an array literal, From 8072dae16bd0bf86f4ca4a0cbea1213a315340e4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sat, 5 May 2018 12:02:29 -0700 Subject: [PATCH 6/9] Change kind name to `imports` --- src/harness/fourslash.ts | 4 ++-- src/services/types.ts | 2 +- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 6c6d95c0682..6464f4a5f82 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2470,7 +2470,7 @@ Actual: ${stringify(fullActual)}`); Harness.IO.log(stringify(spans)); } - public verifyOutliningSpans(spans: Range[], kind?: "comment" | "region" | "code" | "import") { + public verifyOutliningSpans(spans: Range[], kind?: "comment" | "region" | "code" | "imports") { const actual = this.languageService.getOutliningSpans(this.activeFile.fileName); if (actual.length !== spans.length) { @@ -4302,7 +4302,7 @@ namespace FourSlashInterface { this.state.verifyCurrentNameOrDottedNameSpanText(text); } - public outliningSpansInCurrentFile(spans: FourSlash.Range[], kind?: "comment" | "region" | "code" | "import") { + public outliningSpansInCurrentFile(spans: FourSlash.Range[], kind?: "comment" | "region" | "code" | "imports") { this.state.verifyOutliningSpans(spans, kind); } diff --git a/src/services/types.ts b/src/services/types.ts index 48eb25f8a3e..d832bca7ce7 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -827,7 +827,7 @@ namespace ts { Comment = "comment", Region = "region", Code = "code", - Import = "import" + Imports = "imports" } export const enum OutputFileType { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 778bc0e51fd..7532c6779fb 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4893,7 +4893,7 @@ declare namespace ts { Comment = "comment", Region = "region", Code = "code", - Import = "import" + Imports = "imports" } enum OutputFileType { JavaScript = 0, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index deabfc15441..33e9347f481 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4893,7 +4893,7 @@ declare namespace ts { Comment = "comment", Region = "region", Code = "code", - Import = "import" + Imports = "imports" } enum OutputFileType { JavaScript = 0, From 12ed49bada77c43a4319249813cef00a9a11bf84 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sat, 5 May 2018 12:04:12 -0700 Subject: [PATCH 7/9] Revert adding named import binding list outlining spans --- src/services/outliningElementsCollector.ts | 20 ++----------------- .../fourslash/getOutliningSpansForImports.ts | 4 ++-- ...tliningSpansForImportsWithNamedBindings.ts | 17 ---------------- 3 files changed, 4 insertions(+), 37 deletions(-) delete mode 100644 tests/cases/fourslash/getOutliningSpansForImportsWithNamedBindings.ts diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index eb5bfa4c0d5..0d13a3c33a4 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -20,28 +20,12 @@ namespace ts.OutliningElementsCollector { if (current === n) break; const firstImport = statements[current]; while (current < n && isAnyImportSyntax(statements[current])) { - visitImportNode(statements[current] as AnyImportSyntax, sourceFile, cancellationToken, out); + addOutliningForLeadingCommentsForNode(statements[current], sourceFile, cancellationToken, out); current++; } const lastImport = current < n ? statements[current - 1] : statements[n - 1]; if (lastImport !== firstImport) { - out.push(createOutliningSpanFromBounds(findChildOfKind(firstImport, SyntaxKind.ImportKeyword, sourceFile)!.getStart(sourceFile), lastImport.getEnd(), OutliningSpanKind.Import)); - } - } - - function visitImportNode(node: AnyImportSyntax, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push) { - // Add outlining spans for comments if they exist - addOutliningForLeadingCommentsForNode(node, sourceFile, cancellationToken, out); - // Add outlining spans for the import statement itself if applicable - if (isImportDeclaration(node) && node.importClause && node.importClause.namedBindings && - node.importClause.namedBindings.kind !== SyntaxKind.NamespaceImport && node.importClause.namedBindings.elements.length) { - const openToken = findChildOfKind(node.importClause.namedBindings, SyntaxKind.OpenBraceToken, sourceFile); - const closeToken = findChildOfKind(node.importClause.namedBindings, SyntaxKind.CloseBraceToken, sourceFile); - if (openToken && closeToken) { - out.push(createOutliningSpan( - createTextSpanFromBounds(openToken.getStart(sourceFile), closeToken.getEnd()), - OutliningSpanKind.Import, createTextSpanFromNode(node, sourceFile))); - } + out.push(createOutliningSpanFromBounds(findChildOfKind(firstImport, SyntaxKind.ImportKeyword, sourceFile)!.getStart(sourceFile), lastImport.getEnd(), OutliningSpanKind.Imports)); } } diff --git a/tests/cases/fourslash/getOutliningSpansForImports.ts b/tests/cases/fourslash/getOutliningSpansForImports.ts index 198adc9c551..23b625059c5 100644 --- a/tests/cases/fourslash/getOutliningSpansForImports.ts +++ b/tests/cases/fourslash/getOutliningSpansForImports.ts @@ -4,7 +4,7 @@ ////[|import * as ns from "mod"; //// ////import d from "mod"; -////import [|{ a, b, c }|] from "mod"; +////import { a, b, c } from "mod"; //// ////import r = require("mod");|] //// @@ -14,7 +14,7 @@ ////// another set of imports ////[|import * as ns from "mod"; ////import d from "mod"; -////import [|{ a, b, c }|] from "mod"; +////import { a, b, c } from "mod"; ////import r = require("mod");|] verify.outliningSpansInCurrentFile(test.ranges(), "import"); diff --git a/tests/cases/fourslash/getOutliningSpansForImportsWithNamedBindings.ts b/tests/cases/fourslash/getOutliningSpansForImportsWithNamedBindings.ts deleted file mode 100644 index 4e5336ba3b0..00000000000 --- a/tests/cases/fourslash/getOutliningSpansForImportsWithNamedBindings.ts +++ /dev/null @@ -1,17 +0,0 @@ -/// - - -////[|import [|{ -//// a, -//// b as B, -//// c -////}|] from "mod"; -//// -//// -////import { } from "mod"; -////import * as ns from "mod"; -////import d from "mod";|] - -verify.outliningSpansInCurrentFile(test.ranges(), "import"); - - From 3bc3f2d4041da90eee0c0e06f7cd45a3aa66e29b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sat, 5 May 2018 12:38:59 -0700 Subject: [PATCH 8/9] Add comments to kinds --- src/services/types.ts | 7 +++++++ tests/baselines/reference/api/tsserverlibrary.d.ts | 4 ++++ tests/baselines/reference/api/typescript.d.ts | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/services/types.ts b/src/services/types.ts index d832bca7ce7..69e33ce6732 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -824,9 +824,16 @@ namespace ts { } export const enum OutliningSpanKind { + /** Single or multi-line comments */ Comment = "comment", + + /** Sections marked by '// #region' and '// #endregion' comments */ Region = "region", + + /** Declarations and expressions */ Code = "code", + + /** Contiguous blocks of import declarations */ Imports = "imports" } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 7532c6779fb..5d1ef5e7a75 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4890,9 +4890,13 @@ declare namespace ts { kind: OutliningSpanKind; } enum OutliningSpanKind { + /** Single or multi-line comments */ Comment = "comment", + /** Sections marked by '// #region' and '// #endregion' comments */ Region = "region", + /** Declarations and expressions */ Code = "code", + /** Contiguous blocks of import declarations */ Imports = "imports" } enum OutputFileType { diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 33e9347f481..211c2fbbdf4 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4890,9 +4890,13 @@ declare namespace ts { kind: OutliningSpanKind; } enum OutliningSpanKind { + /** Single or multi-line comments */ Comment = "comment", + /** Sections marked by '// #region' and '// #endregion' comments */ Region = "region", + /** Declarations and expressions */ Code = "code", + /** Contiguous blocks of import declarations */ Imports = "imports" } enum OutputFileType { From 64d6b24c87cd39e7e0cede6391190e10e022a3c9 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sat, 5 May 2018 13:22:48 -0700 Subject: [PATCH 9/9] Code review comments --- src/services/outliningElementsCollector.ts | 6 +++--- tests/cases/fourslash/getOutliningSpansForImports.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 0d13a3c33a4..91754e2ac76 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -18,14 +18,14 @@ namespace ts.OutliningElementsCollector { current++; } if (current === n) break; - const firstImport = statements[current]; + const firstImport = current; while (current < n && isAnyImportSyntax(statements[current])) { addOutliningForLeadingCommentsForNode(statements[current], sourceFile, cancellationToken, out); current++; } - const lastImport = current < n ? statements[current - 1] : statements[n - 1]; + const lastImport = current - 1; if (lastImport !== firstImport) { - out.push(createOutliningSpanFromBounds(findChildOfKind(firstImport, SyntaxKind.ImportKeyword, sourceFile)!.getStart(sourceFile), lastImport.getEnd(), OutliningSpanKind.Imports)); + out.push(createOutliningSpanFromBounds(findChildOfKind(statements[firstImport], SyntaxKind.ImportKeyword, sourceFile)!.getStart(sourceFile), statements[lastImport].getEnd(), OutliningSpanKind.Imports)); } } diff --git a/tests/cases/fourslash/getOutliningSpansForImports.ts b/tests/cases/fourslash/getOutliningSpansForImports.ts index 23b625059c5..703c4f5891c 100644 --- a/tests/cases/fourslash/getOutliningSpansForImports.ts +++ b/tests/cases/fourslash/getOutliningSpansForImports.ts @@ -17,4 +17,4 @@ ////import { a, b, c } from "mod"; ////import r = require("mod");|] -verify.outliningSpansInCurrentFile(test.ranges(), "import"); +verify.outliningSpansInCurrentFile(test.ranges(), "imports");