16
16
///<reference path='references.ts' />
17
17
18
18
module ts {
19
+
20
+ export interface OutliningSpan {
21
+ /**
22
+ * @param textSpan The span of the document to actually collapse.
23
+ * @param hintSpan The span of the document to display when the user hovers over the
24
+ * collapsed span.
25
+ * @param bannerText The text to display in the editor for the collapsed region.
26
+ * @param autoCollapse Whether or not this region should be automatically collapsed when
27
+ * the 'Collapse to Definitions' command is invoked.
28
+ */
29
+ textSpan : TypeScript . TextSpan ;
30
+ hintSpan : TypeScript . TextSpan ;
31
+ bannerText : string ;
32
+ autoCollapse : boolean ;
33
+ }
34
+
19
35
export module OutliningElementsCollector {
20
- export function collectElements ( sourceFile : SourceFile ) : TypeScript . TextSpan [ ] {
21
- var elements : TypeScript . TextSpan [ ] = [ ] ;
36
+ export function collectElements ( sourceFile : SourceFile ) : OutliningSpan [ ] {
37
+ var elements : OutliningSpan [ ] = [ ] ;
22
38
23
- function addOutlineRange ( startElement : Node , endElement : Node ) {
24
- if ( startElement && endElement ) {
25
- // Push the new range
26
- elements . push ( TypeScript . TextSpan . fromBounds ( startElement . pos , endElement . end ) ) ;
39
+ function addOutlineRange ( node : Node , startElement : Node , endElement : Node ) {
40
+ if ( node && startElement && endElement ) {
41
+ var span : OutliningSpan = {
42
+ textSpan : TypeScript . TextSpan . fromBounds ( startElement . pos , endElement . end ) ,
43
+ hintSpan : TypeScript . TextSpan . fromBounds ( node . getFullStart ( ) , node . end ) ,
44
+ bannerText : "..." ,
45
+ autoCollapse : false
46
+ } ;
47
+ elements . push ( span ) ;
27
48
}
28
49
}
29
50
30
- function walk ( n : Node ) {
51
+ var depth = 0 ;
52
+ var maxDepth = 10 ;
53
+ function walk ( n : Node ) : void {
54
+ if ( depth >= maxDepth ) {
55
+ return ;
56
+ }
31
57
switch ( n . kind ) {
32
58
case SyntaxKind . ClassDeclaration :
33
59
case SyntaxKind . InterfaceDeclaration :
@@ -36,7 +62,7 @@ module ts {
36
62
case SyntaxKind . ObjectLiteral :
37
63
var openBrace = forEach ( n . getChildren ( ) , c => c . kind === SyntaxKind . OpenBraceToken && c ) ;
38
64
var closeBrace = forEach ( n . getChildren ( ) , c => c . kind === SyntaxKind . CloseBraceToken && c ) ;
39
- addOutlineRange ( openBrace , closeBrace ) ;
65
+ addOutlineRange ( n , openBrace , closeBrace ) ;
40
66
break ;
41
67
case SyntaxKind . Constructor :
42
68
case SyntaxKind . FunctionDeclaration :
@@ -47,11 +73,13 @@ module ts {
47
73
if ( body ) {
48
74
var openBrace = forEach ( body . getChildren ( ) , c => c . kind === SyntaxKind . OpenBraceToken && c ) ;
49
75
var closeBrace = forEach ( body . getChildren ( ) , c => c . kind === SyntaxKind . CloseBraceToken && c ) ;
50
- addOutlineRange ( openBrace , closeBrace ) ;
76
+ addOutlineRange ( n , openBrace , closeBrace ) ;
51
77
}
52
78
break ;
53
79
}
80
+ depth ++ ;
54
81
forEachChild ( n , walk ) ;
82
+ depth -- ;
55
83
}
56
84
57
85
walk ( sourceFile ) ;
0 commit comments