@@ -9,7 +9,27 @@ namespace ts.OutliningElementsCollector {
99
1010 function addNodeOutliningSpans ( sourceFile : SourceFile , cancellationToken : CancellationToken , out : Push < OutliningSpan > ) : void {
1111 let depthRemaining = 40 ;
12- sourceFile . forEachChild ( function walk ( n ) {
12+ let current = 0 ;
13+ const statements = sourceFile . statements ;
14+ const n = statements . length ;
15+ while ( current < n ) {
16+ while ( current < n && ! isAnyImportSyntax ( statements [ current ] ) ) {
17+ visitNonImportNode ( statements [ current ] ) ;
18+ current ++ ;
19+ }
20+ if ( current === n ) break ;
21+ const firstImport = current ;
22+ while ( current < n && isAnyImportSyntax ( statements [ current ] ) ) {
23+ addOutliningForLeadingCommentsForNode ( statements [ current ] , sourceFile , cancellationToken , out ) ;
24+ current ++ ;
25+ }
26+ const lastImport = current - 1 ;
27+ if ( lastImport !== firstImport ) {
28+ out . push ( createOutliningSpanFromBounds ( findChildOfKind ( statements [ firstImport ] , SyntaxKind . ImportKeyword , sourceFile ) ! . getStart ( sourceFile ) , statements [ lastImport ] . getEnd ( ) , OutliningSpanKind . Imports ) ) ;
29+ }
30+ }
31+
32+ function visitNonImportNode ( n : Node ) {
1333 if ( depthRemaining === 0 ) return ;
1434 cancellationToken . throwIfCancellationRequested ( ) ;
1535
@@ -23,17 +43,17 @@ namespace ts.OutliningElementsCollector {
2343 depthRemaining -- ;
2444 if ( isIfStatement ( n ) && n . elseStatement && isIfStatement ( n . elseStatement ) ) {
2545 // Consider an 'else if' to be on the same depth as the 'if'.
26- walk ( n . expression ) ;
27- walk ( n . thenStatement ) ;
46+ visitNonImportNode ( n . expression ) ;
47+ visitNonImportNode ( n . thenStatement ) ;
2848 depthRemaining ++ ;
29- walk ( n . elseStatement ) ;
49+ visitNonImportNode ( n . elseStatement ) ;
3050 depthRemaining -- ;
3151 }
3252 else {
33- n . forEachChild ( walk ) ;
53+ n . forEachChild ( visitNonImportNode ) ;
3454 }
3555 depthRemaining ++ ;
36- } ) ;
56+ }
3757 }
3858
3959 function addRegionOutliningSpans ( sourceFile : SourceFile , out : Push < OutliningSpan > ) : void {
0 commit comments