@@ -3,11 +3,17 @@ namespace ts.OutliningElementsCollector {
3
3
export function collectElements ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : OutliningSpan [ ] {
4
4
const elements : OutliningSpan [ ] = [ ] ;
5
5
const collapseText = "..." ;
6
+ let depth = 0 ;
7
+ const maxDepth = 20 ;
8
+
9
+ walk ( sourceFile ) ;
10
+ return elements ;
6
11
7
- function addOutliningSpan ( hintSpanNode : Node , startElement : Node , endElement : Node , autoCollapse : boolean , fullStart : boolean ) {
12
+ // If useFullStart is true, then the collapsing span includes leading whitespace, including linebreaks.
13
+ function addOutliningSpan ( hintSpanNode : Node , startElement : Node , endElement : Node , autoCollapse : boolean , useFullStart : boolean ) {
8
14
if ( hintSpanNode && startElement && endElement ) {
9
15
const span : OutliningSpan = {
10
- textSpan : createTextSpanFromBounds ( fullStart ? startElement . pos : startElement . getStart ( ) , endElement . end ) ,
16
+ textSpan : createTextSpanFromBounds ( useFullStart ? startElement . pos : startElement . getStart ( ) , endElement . end ) ,
11
17
hintSpan : createTextSpanFromBounds ( startElement . getStart ( ) , endElement . end ) ,
12
18
bannerText : collapseText ,
13
19
autoCollapse,
@@ -82,8 +88,6 @@ namespace ts.OutliningElementsCollector {
82
88
return isFunctionBlock ( node ) && node . parent . kind !== SyntaxKind . ArrowFunction ;
83
89
}
84
90
85
- let depth = 0 ;
86
- const maxDepth = 20 ;
87
91
function walk ( n : Node ) : void {
88
92
cancellationToken . throwIfCancellationRequested ( ) ;
89
93
if ( depth > maxDepth ) {
@@ -163,6 +167,9 @@ namespace ts.OutliningElementsCollector {
163
167
addOutliningSpan ( n , openBrace , closeBrace , autoCollapse ( n ) , /* fullStart */ true ) ;
164
168
break ;
165
169
}
170
+ // If the block has no leading keywords and is a member of an array literal,
171
+ // we again want to only collapse the span of the block.
172
+ // Otherwise, the collapsed section will include the end of the previous line.
166
173
case SyntaxKind . ObjectLiteralExpression :
167
174
const openBrace = findChildOfKind ( n , SyntaxKind . OpenBraceToken , sourceFile ) ;
168
175
const closeBrace = findChildOfKind ( n , SyntaxKind . CloseBraceToken , sourceFile ) ;
@@ -178,8 +185,5 @@ namespace ts.OutliningElementsCollector {
178
185
forEachChild ( n , walk ) ;
179
186
depth -- ;
180
187
}
181
-
182
- walk ( sourceFile ) ;
183
- return elements ;
184
188
}
185
189
}
0 commit comments