From 8900d644e4c68a876bf4c8d3055b21015f83ceee Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 1 Jul 2025 22:16:51 -0700 Subject: [PATCH] Just add a trailing call to `visitNode` instead of creating a new array. --- src/services/outliningElementsCollector.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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();