@@ -4,14 +4,14 @@ namespace ts.OutliningElementsCollector {
44 const res : OutliningSpan [ ] = [ ] ;
55 addNodeOutliningSpans ( sourceFile , cancellationToken , res ) ;
66 addRegionOutliningSpans ( sourceFile , res ) ;
7- addTopLevelUnattachedCommentSpans ( sourceFile , res ) ;
87 return res . sort ( ( span1 , span2 ) => span1 . textSpan . start - span2 . textSpan . start ) ;
98 }
109
1110 function addNodeOutliningSpans ( sourceFile : SourceFile , cancellationToken : CancellationToken , out : Push < OutliningSpan > ) : void {
1211 let depthRemaining = 40 ;
1312 let current = 0 ;
14- const statements = sourceFile . statements ;
13+ // Includes the EOF Token so that comments which aren't attached to statements are included
14+ const statements = [ ...sourceFile . statements , sourceFile . endOfFileToken ] ;
1515 const n = statements . length ;
1616 while ( current < n ) {
1717 while ( current < n && ! isAnyImportSyntax ( statements [ current ] ) ) {
@@ -34,7 +34,7 @@ namespace ts.OutliningElementsCollector {
3434 if ( depthRemaining === 0 ) return ;
3535 cancellationToken . throwIfCancellationRequested ( ) ;
3636
37- if ( isDeclaration ( n ) ) {
37+ if ( isDeclaration ( n ) || n . kind === SyntaxKind . EndOfFileToken ) {
3838 addOutliningForLeadingCommentsForNode ( n , sourceFile , cancellationToken , out ) ;
3939 }
4040
@@ -107,23 +107,6 @@ namespace ts.OutliningElementsCollector {
107107 return regionDelimiterRegExp . exec ( lineText ) ;
108108 }
109109
110- function addTopLevelUnattachedCommentSpans ( sourceFile : SourceFile , out : Push < OutliningSpan > ) : void {
111- // Comments which are attached to statements would be included in addNodeOutliningSpans
112- if ( sourceFile . statements . length > 0 ) return ;
113-
114- // This will instead set up spans for the missing ones
115- forEach ( getLeadingCommentRangesOfNode ( sourceFile , sourceFile ) , ( range ) => {
116- // To not mess with // #region support
117- const isMultiline = sourceFile . text . substring ( range . pos , 2 ) === "/*" ;
118- if ( ! isMultiline ) return ;
119-
120- const span = createTextSpanFromBounds ( range . pos , range . end ) ;
121- const comment = sourceFile . text . substring ( range . pos , range . end ) ;
122- const outline = createOutliningSpan ( span , OutliningSpanKind . Comment , span , /*autoCollapse*/ false , comment ) ;
123- out . push ( outline ) ;
124- } ) ;
125- }
126-
127110 function addOutliningForLeadingCommentsForNode ( n : Node , sourceFile : SourceFile , cancellationToken : CancellationToken , out : Push < OutliningSpan > ) : void {
128111 const comments = getLeadingCommentRangesOfNode ( n , sourceFile ) ;
129112 if ( ! comments ) return ;
@@ -289,6 +272,9 @@ namespace ts.OutliningElementsCollector {
289272 }
290273
291274 function createOutliningSpan ( textSpan : TextSpan , kind : OutliningSpanKind , hintSpan : TextSpan = textSpan , autoCollapse = false , bannerText = "..." ) : OutliningSpan {
275+ if ( kind === OutliningSpanKind . Region ) {
276+ debugger ;
277+ }
292278 return { textSpan, kind, hintSpan, bannerText, autoCollapse } ;
293279 }
294280}
0 commit comments