diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 7248133ec8ca7..84dab4062ab66 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -67,8 +67,7 @@ export function collectElements(sourceFile: SourceFile, cancellationToken: Cance function addNodeOutliningSpans(sourceFile: SourceFile, cancellationToken: CancellationToken, out: OutliningSpan[]): void { let depthRemaining = 40; let current = 0; - // Includes the EOF Token so that comments which aren't attached to statements are included - const statements = [...sourceFile.statements, sourceFile.endOfFileToken]; + const statements = sourceFile.statements; const n = statements.length; while (current < n) { while (current < n && !isAnyImportSyntax(statements[current])) { @@ -87,6 +86,9 @@ function addNodeOutliningSpans(sourceFile: SourceFile, cancellationToken: Cancel } } + // Visit the EOF Token so that comments which aren't attached to statements are included. + visitNode(sourceFile.endOfFileToken); + function visitNode(n: Node) { if (depthRemaining === 0) return; cancellationToken.throwIfCancellationRequested();