@@ -110,6 +110,8 @@ namespace ts.server {
110
110
export const SyntacticDiagnosticsSync = "syntacticDiagnosticsSync" ;
111
111
export const NavBar = "navbar" ;
112
112
export const NavBarFull = "navbar-full" ;
113
+ export const NavTree = "navtree" ;
114
+ export const NavTreeFull = "navtree-full" ;
113
115
export const Navto = "navto" ;
114
116
export const NavtoFull = "navto-full" ;
115
117
export const Occurrences = "occurrences" ;
@@ -569,7 +571,7 @@ namespace ts.server {
569
571
const scriptInfo = this . projectService . getScriptInfo ( args . file ) ;
570
572
projects = scriptInfo . containingProjects ;
571
573
}
572
- // ts.filter handles case when 'projects' is undefined
574
+ // ts.filter handles case when 'projects' is undefined
573
575
projects = filter ( projects , p => p . languageServiceEnabled ) ;
574
576
if ( ! projects || ! projects . length ) {
575
577
return Errors . ThrowNoProject ( ) ;
@@ -960,15 +962,8 @@ namespace ts.server {
960
962
return completions . entries . reduce ( ( result : protocol . CompletionEntry [ ] , entry : ts . CompletionEntry ) => {
961
963
if ( completions . isMemberCompletion || ( entry . name . toLowerCase ( ) . indexOf ( prefix . toLowerCase ( ) ) === 0 ) ) {
962
964
const { name, kind, kindModifiers, sortText, replacementSpan } = entry ;
963
-
964
- let convertedSpan : protocol . TextSpan = undefined ;
965
- if ( replacementSpan ) {
966
- convertedSpan = {
967
- start : scriptInfo . positionToLineOffset ( replacementSpan . start ) ,
968
- end : scriptInfo . positionToLineOffset ( replacementSpan . start + replacementSpan . length )
969
- } ;
970
- }
971
-
965
+ const convertedSpan : protocol . TextSpan =
966
+ replacementSpan ? this . decorateSpan ( replacementSpan , scriptInfo ) : undefined ;
972
967
result . push ( { name, kind, kindModifiers, sortText, replacementSpan : convertedSpan } ) ;
973
968
}
974
969
return result ;
@@ -1106,38 +1101,54 @@ namespace ts.server {
1106
1101
this . projectService . closeClientFile ( file ) ;
1107
1102
}
1108
1103
1109
- private decorateNavigationBarItem ( project : Project , fileName : NormalizedPath , items : ts . NavigationBarItem [ ] ) : protocol . NavigationBarItem [ ] {
1110
- if ( ! items ) {
1111
- return undefined ;
1112
- }
1113
-
1114
- const scriptInfo = project . getScriptInfoForNormalizedPath ( fileName ) ;
1115
-
1116
- return items . map ( item => ( {
1104
+ private decorateNavigationBarItems ( items : ts . NavigationBarItem [ ] , scriptInfo : ScriptInfo ) : protocol . NavigationBarItem [ ] {
1105
+ return map ( items , item => ( {
1117
1106
text : item . text ,
1118
1107
kind : item . kind ,
1119
1108
kindModifiers : item . kindModifiers ,
1120
- spans : item . spans . map ( span => ( {
1121
- start : scriptInfo . positionToLineOffset ( span . start ) ,
1122
- end : scriptInfo . positionToLineOffset ( ts . textSpanEnd ( span ) )
1123
- } ) ) ,
1124
- childItems : this . decorateNavigationBarItem ( project , fileName , item . childItems ) ,
1109
+ spans : item . spans . map ( span => this . decorateSpan ( span , scriptInfo ) ) ,
1110
+ childItems : this . decorateNavigationBarItems ( item . childItems , scriptInfo ) ,
1125
1111
indent : item . indent
1126
1112
} ) ) ;
1127
1113
}
1128
1114
1129
1115
private getNavigationBarItems ( args : protocol . FileRequestArgs , simplifiedResult : boolean ) : protocol . NavigationBarItem [ ] | NavigationBarItem [ ] {
1130
1116
const { file, project } = this . getFileAndProject ( args ) ;
1131
1117
const items = project . getLanguageService ( /*ensureSynchronized*/ false ) . getNavigationBarItems ( file ) ;
1132
- if ( ! items ) {
1133
- return undefined ;
1134
- }
1135
-
1136
- return simplifiedResult
1137
- ? this . decorateNavigationBarItem ( project , file , items )
1118
+ return ! items
1119
+ ? undefined
1120
+ : simplifiedResult
1121
+ ? this . decorateNavigationBarItems ( items , project . getScriptInfoForNormalizedPath ( file ) )
1138
1122
: items ;
1139
1123
}
1140
1124
1125
+ private decorateNavigationTree ( tree : ts . NavigationTree , scriptInfo : ScriptInfo ) : protocol . NavigationTree {
1126
+ return {
1127
+ text : tree . text ,
1128
+ kind : tree . kind ,
1129
+ kindModifiers : tree . kindModifiers ,
1130
+ spans : tree . spans . map ( span => this . decorateSpan ( span , scriptInfo ) ) ,
1131
+ childItems : map ( tree . childItems , item => this . decorateNavigationTree ( item , scriptInfo ) )
1132
+ } ;
1133
+ }
1134
+
1135
+ private decorateSpan ( span : TextSpan , scriptInfo : ScriptInfo ) : protocol . TextSpan {
1136
+ return {
1137
+ start : scriptInfo . positionToLineOffset ( span . start ) ,
1138
+ end : scriptInfo . positionToLineOffset ( ts . textSpanEnd ( span ) )
1139
+ } ;
1140
+ }
1141
+
1142
+ private getNavigationTree ( args : protocol . FileRequestArgs , simplifiedResult : boolean ) : protocol . NavigationTree | NavigationTree {
1143
+ const { file, project } = this . getFileAndProject ( args ) ;
1144
+ const tree = project . getLanguageService ( /*ensureSynchronized*/ false ) . getNavigationTree ( file ) ;
1145
+ return ! tree
1146
+ ? undefined
1147
+ : simplifiedResult
1148
+ ? this . decorateNavigationTree ( tree , project . getScriptInfoForNormalizedPath ( file ) )
1149
+ : tree ;
1150
+ }
1151
+
1141
1152
private getNavigateToItems ( args : protocol . NavtoRequestArgs , simplifiedResult : boolean ) : protocol . NavtoItem [ ] | NavigateToItem [ ] {
1142
1153
const projects = this . getProjects ( args ) ;
1143
1154
@@ -1274,19 +1285,11 @@ namespace ts.server {
1274
1285
const position = this . getPosition ( args , scriptInfo ) ;
1275
1286
1276
1287
const spans = project . getLanguageService ( /*ensureSynchronized*/ false ) . getBraceMatchingAtPosition ( file , position ) ;
1277
- if ( ! spans ) {
1278
- return undefined ;
1279
- }
1280
- if ( simplifiedResult ) {
1281
-
1282
- return spans . map ( span => ( {
1283
- start : scriptInfo . positionToLineOffset ( span . start ) ,
1284
- end : scriptInfo . positionToLineOffset ( span . start + span . length )
1285
- } ) ) ;
1286
- }
1287
- else {
1288
- return spans ;
1289
- }
1288
+ return ! spans
1289
+ ? undefined
1290
+ : simplifiedResult
1291
+ ? spans . map ( span => this . decorateSpan ( span , scriptInfo ) )
1292
+ : spans ;
1290
1293
}
1291
1294
1292
1295
getDiagnosticsForProject ( delay : number , fileName : string ) {
@@ -1571,6 +1574,12 @@ namespace ts.server {
1571
1574
[ CommandNames . NavBarFull ] : ( request : protocol . FileRequest ) => {
1572
1575
return this . requiredResponse ( this . getNavigationBarItems ( request . arguments , /*simplifiedResult*/ false ) ) ;
1573
1576
} ,
1577
+ [ CommandNames . NavTree ] : ( request : protocol . FileRequest ) => {
1578
+ return this . requiredResponse ( this . getNavigationTree ( request . arguments , /*simplifiedResult*/ true ) ) ;
1579
+ } ,
1580
+ [ CommandNames . NavTreeFull ] : ( request : protocol . FileRequest ) => {
1581
+ return this . requiredResponse ( this . getNavigationTree ( request . arguments , /*simplifiedResult*/ false ) ) ;
1582
+ } ,
1574
1583
[ CommandNames . Occurrences ] : ( request : protocol . FileLocationRequest ) => {
1575
1584
return this . requiredResponse ( this . getOccurrences ( request . arguments ) ) ;
1576
1585
} ,
0 commit comments