@@ -110,6 +110,8 @@ namespace ts.server {
110110 export const SyntacticDiagnosticsSync = "syntacticDiagnosticsSync" ;
111111 export const NavBar = "navbar" ;
112112 export const NavBarFull = "navbar-full" ;
113+ export const NavTree = "navtree" ;
114+ export const NavTreeFull = "navtree-full" ;
113115 export const Navto = "navto" ;
114116 export const NavtoFull = "navto-full" ;
115117 export const Occurrences = "occurrences" ;
@@ -960,15 +962,8 @@ namespace ts.server {
960962 return completions . entries . reduce ( ( result : protocol . CompletionEntry [ ] , entry : ts . CompletionEntry ) => {
961963 if ( completions . isMemberCompletion || ( entry . name . toLowerCase ( ) . indexOf ( prefix . toLowerCase ( ) ) === 0 ) ) {
962964 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 ;
972967 result . push ( { name, kind, kindModifiers, sortText, replacementSpan : convertedSpan } ) ;
973968 }
974969 return result ;
@@ -1106,38 +1101,54 @@ namespace ts.server {
11061101 this . projectService . closeClientFile ( file ) ;
11071102 }
11081103
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 => ( {
11171106 text : item . text ,
11181107 kind : item . kind ,
11191108 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 ) ,
11251111 indent : item . indent
11261112 } ) ) ;
11271113 }
11281114
11291115 private getNavigationBarItems ( args : protocol . FileRequestArgs , simplifiedResult : boolean ) : protocol . NavigationBarItem [ ] | NavigationBarItem [ ] {
11301116 const { file, project } = this . getFileAndProject ( args ) ;
11311117 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 ) )
11381122 : items ;
11391123 }
11401124
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+
11411152 private getNavigateToItems ( args : protocol . NavtoRequestArgs , simplifiedResult : boolean ) : protocol . NavtoItem [ ] | NavigateToItem [ ] {
11421153 const projects = this . getProjects ( args ) ;
11431154
@@ -1274,19 +1285,11 @@ namespace ts.server {
12741285 const position = this . getPosition ( args , scriptInfo ) ;
12751286
12761287 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 ;
12901293 }
12911294
12921295 getDiagnosticsForProject ( delay : number , fileName : string ) {
@@ -1571,6 +1574,12 @@ namespace ts.server {
15711574 [ CommandNames . NavBarFull ] : ( request : protocol . FileRequest ) => {
15721575 return this . requiredResponse ( this . getNavigationBarItems ( request . arguments , /*simplifiedResult*/ false ) ) ;
15731576 } ,
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+ } ,
15741583 [ CommandNames . Occurrences ] : ( request : protocol . FileLocationRequest ) => {
15751584 return this . requiredResponse ( this . getOccurrences ( request . arguments ) ) ;
15761585 } ,
0 commit comments