@@ -4,6 +4,7 @@ namespace ts.OutliningElementsCollector {
4
4
const res : OutliningSpan [ ] = [ ] ;
5
5
addNodeOutliningSpans ( sourceFile , cancellationToken , res ) ;
6
6
addRegionOutliningSpans ( sourceFile , res ) ;
7
+ addTopLevelUnattachedCommentSpans ( sourceFile , res ) ;
7
8
return res . sort ( ( span1 , span2 ) => span1 . textSpan . start - span2 . textSpan . start ) ;
8
9
}
9
10
@@ -106,6 +107,23 @@ namespace ts.OutliningElementsCollector {
106
107
return regionDelimiterRegExp . exec ( lineText ) ;
107
108
}
108
109
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
+
109
127
function addOutliningForLeadingCommentsForNode ( n : Node , sourceFile : SourceFile , cancellationToken : CancellationToken , out : Push < OutliningSpan > ) : void {
110
128
const comments = getLeadingCommentRangesOfNode ( n , sourceFile ) ;
111
129
if ( ! comments ) return ;
0 commit comments