@@ -98,6 +98,8 @@ namespace ts.server {
9898 export const SyntacticDiagnosticsSync = "syntacticDiagnosticsSync" ;
9999 export const NavBar = "navbar" ;
100100 export const NavBarFull = "navbar-full" ;
101+ export const NavTree = "navtree" ;
102+ export const NavTreeFull = "navtree-full" ;
101103 export const Navto = "navto" ;
102104 export const NavtoFull = "navto-full" ;
103105 export const Occurrences = "occurrences" ;
@@ -550,7 +552,7 @@ namespace ts.server {
550552 const scriptInfo = this . projectService . getScriptInfo ( args . file ) ;
551553 projects = scriptInfo . containingProjects ;
552554 }
553- // ts.filter handles case when 'projects' is undefined
555+ // ts.filter handles case when 'projects' is undefined
554556 projects = filter ( projects , p => p . languageServiceEnabled ) ;
555557 if ( ! projects || ! projects . length ) {
556558 return Errors . ThrowNoProject ( ) ;
@@ -947,15 +949,8 @@ namespace ts.server {
947949 return completions . entries . reduce ( ( result : protocol . CompletionEntry [ ] , entry : ts . CompletionEntry ) => {
948950 if ( completions . isMemberCompletion || ( entry . name . toLowerCase ( ) . indexOf ( prefix . toLowerCase ( ) ) === 0 ) ) {
949951 const { name, kind, kindModifiers, sortText, replacementSpan } = entry ;
950-
951- let convertedSpan : protocol . TextSpan = undefined ;
952- if ( replacementSpan ) {
953- convertedSpan = {
954- start : scriptInfo . positionToLineOffset ( replacementSpan . start ) ,
955- end : scriptInfo . positionToLineOffset ( replacementSpan . start + replacementSpan . length )
956- } ;
957- }
958-
952+ const convertedSpan : protocol . TextSpan =
953+ replacementSpan ? this . decorateSpan ( replacementSpan , scriptInfo ) : undefined ;
959954 result . push ( { name, kind, kindModifiers, sortText, replacementSpan : convertedSpan } ) ;
960955 }
961956 return result ;
@@ -1093,38 +1088,54 @@ namespace ts.server {
10931088 this . projectService . closeClientFile ( file ) ;
10941089 }
10951090
1096- private decorateNavigationBarItem ( project : Project , fileName : NormalizedPath , items : ts . NavigationBarItem [ ] ) : protocol . NavigationBarItem [ ] {
1097- if ( ! items ) {
1098- return undefined ;
1099- }
1100-
1101- const scriptInfo = project . getScriptInfoForNormalizedPath ( fileName ) ;
1102-
1103- return items . map ( item => ( {
1091+ private decorateNavigationBarItems ( items : ts . NavigationBarItem [ ] , scriptInfo : ScriptInfo ) : protocol . NavigationBarItem [ ] {
1092+ return map ( items , item => ( {
11041093 text : item . text ,
11051094 kind : item . kind ,
11061095 kindModifiers : item . kindModifiers ,
1107- spans : item . spans . map ( span => ( {
1108- start : scriptInfo . positionToLineOffset ( span . start ) ,
1109- end : scriptInfo . positionToLineOffset ( ts . textSpanEnd ( span ) )
1110- } ) ) ,
1111- childItems : this . decorateNavigationBarItem ( project , fileName , item . childItems ) ,
1096+ spans : item . spans . map ( span => this . decorateSpan ( span , scriptInfo ) ) ,
1097+ childItems : this . decorateNavigationBarItems ( item . childItems , scriptInfo ) ,
11121098 indent : item . indent
11131099 } ) ) ;
11141100 }
11151101
11161102 private getNavigationBarItems ( args : protocol . FileRequestArgs , simplifiedResult : boolean ) : protocol . NavigationBarItem [ ] | NavigationBarItem [ ] {
11171103 const { file, project } = this . getFileAndProject ( args ) ;
11181104 const items = project . getLanguageService ( /*ensureSynchronized*/ false ) . getNavigationBarItems ( file ) ;
1119- if ( ! items ) {
1120- return undefined ;
1121- }
1122-
1123- return simplifiedResult
1124- ? this . decorateNavigationBarItem ( project , file , items )
1105+ return ! items
1106+ ? undefined
1107+ : simplifiedResult
1108+ ? this . decorateNavigationBarItems ( items , project . getScriptInfoForNormalizedPath ( file ) )
11251109 : items ;
11261110 }
11271111
1112+ private decorateNavigationTree ( tree : ts . NavigationTree , scriptInfo : ScriptInfo ) : protocol . NavigationTree {
1113+ return {
1114+ text : tree . text ,
1115+ kind : tree . kind ,
1116+ kindModifiers : tree . kindModifiers ,
1117+ spans : tree . spans . map ( span => this . decorateSpan ( span , scriptInfo ) ) ,
1118+ childItems : map ( tree . childItems , item => this . decorateNavigationTree ( item , scriptInfo ) )
1119+ } ;
1120+ }
1121+
1122+ private decorateSpan ( span : TextSpan , scriptInfo : ScriptInfo ) : protocol . TextSpan {
1123+ return {
1124+ start : scriptInfo . positionToLineOffset ( span . start ) ,
1125+ end : scriptInfo . positionToLineOffset ( ts . textSpanEnd ( span ) )
1126+ } ;
1127+ }
1128+
1129+ private getNavigationTree ( args : protocol . FileRequestArgs , simplifiedResult : boolean ) : protocol . NavigationTree | NavigationTree {
1130+ const { file, project } = this . getFileAndProject ( args ) ;
1131+ const tree = project . getLanguageService ( /*ensureSynchronized*/ false ) . getNavigationTree ( file ) ;
1132+ return ! tree
1133+ ? undefined
1134+ : simplifiedResult
1135+ ? this . decorateNavigationTree ( tree , project . getScriptInfoForNormalizedPath ( file ) )
1136+ : tree ;
1137+ }
1138+
11281139 private getNavigateToItems ( args : protocol . NavtoRequestArgs , simplifiedResult : boolean ) : protocol . NavtoItem [ ] | NavigateToItem [ ] {
11291140 const projects = this . getProjects ( args ) ;
11301141
@@ -1212,19 +1223,11 @@ namespace ts.server {
12121223 const position = this . getPosition ( args , scriptInfo ) ;
12131224
12141225 const spans = project . getLanguageService ( /*ensureSynchronized*/ false ) . getBraceMatchingAtPosition ( file , position ) ;
1215- if ( ! spans ) {
1216- return undefined ;
1217- }
1218- if ( simplifiedResult ) {
1219-
1220- return spans . map ( span => ( {
1221- start : scriptInfo . positionToLineOffset ( span . start ) ,
1222- end : scriptInfo . positionToLineOffset ( span . start + span . length )
1223- } ) ) ;
1224- }
1225- else {
1226- return spans ;
1227- }
1226+ return ! spans
1227+ ? undefined
1228+ : simplifiedResult
1229+ ? spans . map ( span => this . decorateSpan ( span , scriptInfo ) )
1230+ : spans ;
12281231 }
12291232
12301233 getDiagnosticsForProject ( delay : number , fileName : string ) {
@@ -1509,6 +1512,12 @@ namespace ts.server {
15091512 [ CommandNames . NavBarFull ] : ( request : protocol . FileRequest ) => {
15101513 return this . requiredResponse ( this . getNavigationBarItems ( request . arguments , /*simplifiedResult*/ false ) ) ;
15111514 } ,
1515+ [ CommandNames . NavTree ] : ( request : protocol . FileRequest ) => {
1516+ return this . requiredResponse ( this . getNavigationTree ( request . arguments , /*simplifiedResult*/ true ) ) ;
1517+ } ,
1518+ [ CommandNames . NavTreeFull ] : ( request : protocol . FileRequest ) => {
1519+ return this . requiredResponse ( this . getNavigationTree ( request . arguments , /*simplifiedResult*/ false ) ) ;
1520+ } ,
15121521 [ CommandNames . Occurrences ] : ( request : protocol . FileLocationRequest ) => {
15131522 return this . requiredResponse ( this . getOccurrences ( request . arguments ) ) ;
15141523 } ,
0 commit comments