@@ -56,7 +56,7 @@ namespace ts.NavigationBar {
56
56
curCancellationToken = cancellationToken ;
57
57
curSourceFile = sourceFile ;
58
58
try {
59
- return map ( topLevelItems ( rootNavigationBarNode ( sourceFile ) ) , convertToTopLevelItem ) ;
59
+ return map ( primaryNavBarMenuItems ( rootNavigationBarNode ( sourceFile ) ) , convertToPrimaryNavBarMenuItem ) ;
60
60
}
61
61
finally {
62
62
reset ( ) ;
@@ -111,8 +111,8 @@ namespace ts.NavigationBar {
111
111
return root ;
112
112
}
113
113
114
- function addLeafNode ( node : Node ) : void {
115
- pushChild ( parent , emptyNavigationBarNode ( node ) ) ;
114
+ function addLeafNode ( node : Node , name ?: DeclarationName ) : void {
115
+ pushChild ( parent , emptyNavigationBarNode ( node , name ) ) ;
116
116
}
117
117
118
118
function emptyNavigationBarNode ( node : Node , name ?: DeclarationName ) : NavigationBarNode {
@@ -243,23 +243,26 @@ namespace ts.NavigationBar {
243
243
}
244
244
break ;
245
245
246
+ case SyntaxKind . ShorthandPropertyAssignment :
247
+ addNodeWithRecursiveChild ( node , ( < ShorthandPropertyAssignment > node ) . name ) ;
248
+ break ;
249
+ case SyntaxKind . SpreadAssignment :
250
+ const { expression } = < SpreadAssignment > node ;
251
+ // Use the expression as the name of the SpreadAssignment, otherwise show as <unknown>.
252
+ isIdentifier ( expression ) ? addLeafNode ( node , expression ) : addLeafNode ( node ) ;
253
+ break ;
246
254
case SyntaxKind . BindingElement :
255
+ case SyntaxKind . PropertyAssignment :
247
256
case SyntaxKind . VariableDeclaration :
248
- const { name, initializer } = < VariableDeclaration | BindingElement > node ;
257
+ const { name, initializer } = < VariableDeclaration | PropertyAssignment | BindingElement > node ;
249
258
if ( isBindingPattern ( name ) ) {
250
259
addChildrenRecursively ( name ) ;
251
260
}
252
261
else if ( initializer && isFunctionOrClassExpression ( initializer ) ) {
253
- if ( initializer . name ) {
254
- // Don't add a node for the VariableDeclaration, just for the initializer.
255
- addChildrenRecursively ( initializer ) ;
256
- }
257
- else {
258
- // Add a node for the VariableDeclaration, but not for the initializer.
259
- startNode ( node ) ;
260
- forEachChild ( initializer , addChildrenRecursively ) ;
261
- endNode ( ) ;
262
- }
262
+ // Add a node for the VariableDeclaration, but not for the initializer.
263
+ startNode ( node ) ;
264
+ forEachChild ( initializer , addChildrenRecursively ) ;
265
+ endNode ( ) ;
263
266
}
264
267
else {
265
268
addNodeWithRecursiveChild ( node , initializer ) ;
@@ -699,12 +702,15 @@ namespace ts.NavigationBar {
699
702
}
700
703
}
701
704
702
- /** Flattens the NavNode tree to a list, keeping only the top-level items. */
703
- function topLevelItems ( root : NavigationBarNode ) : NavigationBarNode [ ] {
704
- const topLevel : NavigationBarNode [ ] = [ ] ;
705
+ /** Flattens the NavNode tree to a list of items to appear in the primary navbar menu. */
706
+ function primaryNavBarMenuItems ( root : NavigationBarNode ) : NavigationBarNode [ ] {
707
+ // The primary (middle) navbar menu displays the general code navigation hierarchy, similar to the navtree.
708
+ // The secondary (right) navbar menu displays the child items of whichever primary item is selected.
709
+ // Some less interesting items without their own child navigation items (e.g. a local variable declaration) only show up in the secondary menu.
710
+ const primaryNavBarMenuItems : NavigationBarNode [ ] = [ ] ;
705
711
function recur ( item : NavigationBarNode ) {
706
- if ( isTopLevel ( item ) ) {
707
- topLevel . push ( item ) ;
712
+ if ( shouldAppearInPrimaryNavBarMenu ( item ) ) {
713
+ primaryNavBarMenuItems . push ( item ) ;
708
714
if ( item . children ) {
709
715
for ( const child of item . children ) {
710
716
recur ( child ) ;
@@ -713,9 +719,16 @@ namespace ts.NavigationBar {
713
719
}
714
720
}
715
721
recur ( root ) ;
716
- return topLevel ;
722
+ return primaryNavBarMenuItems ;
717
723
718
- function isTopLevel ( item : NavigationBarNode ) : boolean {
724
+ /** Determines if a node should appear in the primary navbar menu. */
725
+ function shouldAppearInPrimaryNavBarMenu ( item : NavigationBarNode ) : boolean {
726
+ // Items with children should always appear in the primary navbar menu.
727
+ if ( item . children ) {
728
+ return true ;
729
+ }
730
+
731
+ // Some nodes are otherwise important enough to always include in the primary navigation menu.
719
732
switch ( navigationBarNodeKind ( item ) ) {
720
733
case SyntaxKind . ClassDeclaration :
721
734
case SyntaxKind . ClassExpression :
@@ -728,13 +741,6 @@ namespace ts.NavigationBar {
728
741
case SyntaxKind . JSDocCallbackTag :
729
742
return true ;
730
743
731
- case SyntaxKind . Constructor :
732
- case SyntaxKind . MethodDeclaration :
733
- case SyntaxKind . GetAccessor :
734
- case SyntaxKind . SetAccessor :
735
- case SyntaxKind . VariableDeclaration :
736
- return hasSomeImportantChild ( item ) ;
737
-
738
744
case SyntaxKind . ArrowFunction :
739
745
case SyntaxKind . FunctionDeclaration :
740
746
case SyntaxKind . FunctionExpression :
@@ -755,15 +761,9 @@ namespace ts.NavigationBar {
755
761
case SyntaxKind . Constructor :
756
762
return true ;
757
763
default :
758
- return hasSomeImportantChild ( item ) ;
764
+ return false ;
759
765
}
760
766
}
761
- function hasSomeImportantChild ( item : NavigationBarNode ) : boolean {
762
- return some ( item . children , child => {
763
- const childKind = navigationBarNodeKind ( child ) ;
764
- return childKind !== SyntaxKind . VariableDeclaration && childKind !== SyntaxKind . BindingElement ;
765
- } ) ;
766
- }
767
767
}
768
768
}
769
769
@@ -778,19 +778,19 @@ namespace ts.NavigationBar {
778
778
} ;
779
779
}
780
780
781
- function convertToTopLevelItem ( n : NavigationBarNode ) : NavigationBarItem {
781
+ function convertToPrimaryNavBarMenuItem ( n : NavigationBarNode ) : NavigationBarItem {
782
782
return {
783
783
text : getItemName ( n . node , n . name ) ,
784
784
kind : getNodeKind ( n . node ) ,
785
785
kindModifiers : getModifiers ( n . node ) ,
786
786
spans : getSpans ( n ) ,
787
- childItems : map ( n . children , convertToChildItem ) || emptyChildItemArray ,
787
+ childItems : map ( n . children , convertToSecondaryNavBarMenuItem ) || emptyChildItemArray ,
788
788
indent : n . indent ,
789
789
bolded : false ,
790
790
grayed : false
791
791
} ;
792
792
793
- function convertToChildItem ( n : NavigationBarNode ) : NavigationBarItem {
793
+ function convertToSecondaryNavBarMenuItem ( n : NavigationBarNode ) : NavigationBarItem {
794
794
return {
795
795
text : getItemName ( n . node , n . name ) ,
796
796
kind : getNodeKind ( n . node ) ,
0 commit comments