1
1
/* @internal */
2
2
namespace ts . OutliningElementsCollector {
3
+ const collapseText = "..." ;
4
+ const maxDepth = 20 ;
5
+
3
6
export function collectElements ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : OutliningSpan [ ] {
4
7
const elements : OutliningSpan [ ] = [ ] ;
5
- const collapseText = "..." ;
6
8
let depth = 0 ;
7
- const maxDepth = 20 ;
8
9
9
10
walk ( sourceFile ) ;
10
11
return elements ;
11
12
12
- // If useFullStart is true, then the collapsing span includes leading whitespace, including linebreaks.
13
+ /** If useFullStart is true, then the collapsing span includes leading whitespace, including linebreaks. */
13
14
function addOutliningSpan ( hintSpanNode : Node , startElement : Node , endElement : Node , autoCollapse : boolean , useFullStart : boolean ) {
14
15
if ( hintSpanNode && startElement && endElement ) {
15
16
const span : OutliningSpan = {
16
- textSpan : createTextSpanFromBounds ( useFullStart ? startElement . pos : startElement . getStart ( ) , endElement . end ) ,
17
- hintSpan : createTextSpanFromBounds ( startElement . getStart ( ) , endElement . end ) ,
17
+ textSpan : createTextSpanFromBounds ( useFullStart ? startElement . getFullStart ( ) : startElement . getStart ( ) , endElement . getEnd ( ) ) ,
18
+ hintSpan : createTextSpanFromNode ( hintSpanNode , sourceFile ) ,
18
19
bannerText : collapseText ,
19
20
autoCollapse,
20
21
} ;
@@ -117,21 +118,21 @@ namespace ts.OutliningElementsCollector {
117
118
parent . kind === SyntaxKind . WithStatement ||
118
119
parent . kind === SyntaxKind . CatchClause ) {
119
120
120
- addOutliningSpan ( parent , openBrace , closeBrace , autoCollapse ( n ) , /* fullStart */ true ) ;
121
+ addOutliningSpan ( parent , openBrace , closeBrace , autoCollapse ( n ) , /*useFullStart */ true ) ;
121
122
break ;
122
123
}
123
124
124
125
if ( parent . kind === SyntaxKind . TryStatement ) {
125
126
// Could be the try-block, or the finally-block.
126
127
const tryStatement = < TryStatement > parent ;
127
128
if ( tryStatement . tryBlock === n ) {
128
- addOutliningSpan ( parent , openBrace , closeBrace , autoCollapse ( n ) , /* fullStart */ true ) ;
129
+ addOutliningSpan ( parent , openBrace , closeBrace , autoCollapse ( n ) , /*useFullStart */ true ) ;
129
130
break ;
130
131
}
131
132
else if ( tryStatement . finallyBlock === n ) {
132
133
const finallyKeyword = findChildOfKind ( tryStatement , SyntaxKind . FinallyKeyword , sourceFile ) ;
133
134
if ( finallyKeyword ) {
134
- addOutliningSpan ( finallyKeyword , openBrace , closeBrace , autoCollapse ( n ) , /* fullStart */ true ) ;
135
+ addOutliningSpan ( finallyKeyword , openBrace , closeBrace , autoCollapse ( n ) , /*useFullStart */ true ) ;
135
136
break ;
136
137
}
137
138
}
@@ -155,7 +156,7 @@ namespace ts.OutliningElementsCollector {
155
156
case SyntaxKind . ModuleBlock : {
156
157
const openBrace = findChildOfKind ( n , SyntaxKind . OpenBraceToken , sourceFile ) ;
157
158
const closeBrace = findChildOfKind ( n , SyntaxKind . CloseBraceToken , sourceFile ) ;
158
- addOutliningSpan ( n . parent , openBrace , closeBrace , autoCollapse ( n ) , /* fullStart */ true ) ;
159
+ addOutliningSpan ( n . parent , openBrace , closeBrace , autoCollapse ( n ) , /*useFullStart */ true ) ;
159
160
break ;
160
161
}
161
162
case SyntaxKind . ClassDeclaration :
@@ -164,21 +165,21 @@ namespace ts.OutliningElementsCollector {
164
165
case SyntaxKind . CaseBlock : {
165
166
const openBrace = findChildOfKind ( n , SyntaxKind . OpenBraceToken , sourceFile ) ;
166
167
const closeBrace = findChildOfKind ( n , SyntaxKind . CloseBraceToken , sourceFile ) ;
167
- addOutliningSpan ( n , openBrace , closeBrace , autoCollapse ( n ) , /* fullStart */ true ) ;
168
+ addOutliningSpan ( n , openBrace , closeBrace , autoCollapse ( n ) , /*useFullStart */ true ) ;
168
169
break ;
169
170
}
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.
171
+ // If the block has no leading keywords and is inside an array literal,
172
+ // we only want to collapse the span of the block.
172
173
// Otherwise, the collapsed section will include the end of the previous line.
173
174
case SyntaxKind . ObjectLiteralExpression :
174
175
const openBrace = findChildOfKind ( n , SyntaxKind . OpenBraceToken , sourceFile ) ;
175
176
const closeBrace = findChildOfKind ( n , SyntaxKind . CloseBraceToken , sourceFile ) ;
176
- addOutliningSpan ( n , openBrace , closeBrace , autoCollapse ( n ) , /* fullStart */ n . parent . kind !== SyntaxKind . ArrayLiteralExpression ) ;
177
+ addOutliningSpan ( n , openBrace , closeBrace , autoCollapse ( n ) , /*useFullStart */ ! isArrayLiteralExpression ( n . parent ) ) ;
177
178
break ;
178
179
case SyntaxKind . ArrayLiteralExpression :
179
180
const openBracket = findChildOfKind ( n , SyntaxKind . OpenBracketToken , sourceFile ) ;
180
181
const closeBracket = findChildOfKind ( n , SyntaxKind . CloseBracketToken , sourceFile ) ;
181
- addOutliningSpan ( n , openBracket , closeBracket , autoCollapse ( n ) , /* fullStart */ n . parent . kind !== SyntaxKind . ArrayLiteralExpression ) ;
182
+ addOutliningSpan ( n , openBracket , closeBracket , autoCollapse ( n ) , /*useFullStart */ ! isArrayLiteralExpression ( n . parent ) ) ;
182
183
break ;
183
184
}
184
185
depth ++ ;
0 commit comments