@@ -601,7 +601,7 @@ namespace ts.server {
601601 }
602602
603603 if ( simplifiedResult ) {
604- return this . getSimplifiedDefinitions ( definitions , project ) ;
604+ return this . mapFileSpan ( definitions , project ) ;
605605 }
606606 else {
607607 return definitions ;
@@ -624,32 +624,24 @@ namespace ts.server {
624624
625625 if ( simplifiedResult ) {
626626 return {
627- definitions : this . getSimplifiedDefinitions ( definitionAndBoundSpan . definitions , project ) ,
628- textSpan : this . getSimplifiedTextSpan ( scriptInfo , definitionAndBoundSpan . textSpan )
627+ definitions : this . mapFileSpan ( definitionAndBoundSpan . definitions , project ) ,
628+ textSpan : this . toLocationTextSpan ( definitionAndBoundSpan . textSpan , scriptInfo )
629629 } ;
630630 }
631631
632632 return definitionAndBoundSpan ;
633633 }
634634
635- private getSimplifiedDefinitions ( definitions : ReadonlyArray < DefinitionInfo > , project : Project ) : ReadonlyArray < protocol . FileSpan > {
636- return definitions . map ( def => this . getSimplifiedFileSpan ( def . fileName , def . textSpan , project ) ) ;
635+ private mapFileSpan ( definitions : ReadonlyArray < DefinitionInfo > , project : Project ) : ReadonlyArray < protocol . FileSpan > {
636+ return definitions . map ( def => this . getFileSpan ( def . fileName , def . textSpan , project ) ) ;
637637 }
638638
639- private getSimplifiedFileSpan ( fileName : string , textSpan : TextSpan , project : Project ) : protocol . FileSpan {
639+ private getFileSpan ( fileName : string , textSpan : TextSpan , project : Project ) : protocol . FileSpan {
640640 const scriptInfo = project . getScriptInfo ( fileName ) ;
641- const simplifiedTextSpan = this . getSimplifiedTextSpan ( scriptInfo , textSpan ) ;
642641
643642 return {
644643 file : fileName ,
645- ...simplifiedTextSpan
646- } ;
647- }
648-
649- private getSimplifiedTextSpan ( scriptInfo : ScriptInfo , textSpan : TextSpan ) : protocol . TextSpan {
650- return {
651- start : scriptInfo . positionToLineOffset ( textSpan . start ) ,
652- end : scriptInfo . positionToLineOffset ( textSpanEnd ( textSpan ) )
644+ ...this . toLocationTextSpan ( textSpan , scriptInfo )
653645 } ;
654646 }
655647
@@ -662,14 +654,7 @@ namespace ts.server {
662654 return emptyArray ;
663655 }
664656
665- return definitions . map ( def => {
666- const defScriptInfo = project . getScriptInfo ( def . fileName ) ;
667- return {
668- file : def . fileName ,
669- start : defScriptInfo . positionToLineOffset ( def . textSpan . start ) ,
670- end : defScriptInfo . positionToLineOffset ( textSpanEnd ( def . textSpan ) )
671- } ;
672- } ) ;
657+ return this . mapFileSpan ( definitions , project ) ;
673658 }
674659
675660 private getImplementation ( args : protocol . FileLocationRequestArgs , simplifiedResult : boolean ) : ReadonlyArray < protocol . FileSpan > | ReadonlyArray < ImplementationLocation > {
@@ -680,14 +665,7 @@ namespace ts.server {
680665 return emptyArray ;
681666 }
682667 if ( simplifiedResult ) {
683- return implementations . map ( ( { fileName, textSpan } ) => {
684- const scriptInfo = project . getScriptInfo ( fileName ) ;
685- return {
686- file : fileName ,
687- start : scriptInfo . positionToLineOffset ( textSpan . start ) ,
688- end : scriptInfo . positionToLineOffset ( textSpanEnd ( textSpan ) )
689- } ;
690- } ) ;
668+ return implementations . map ( ( { fileName, textSpan } ) => this . getFileSpan ( fileName , textSpan , project ) ) ;
691669 }
692670 else {
693671 return implementations ;
@@ -707,13 +685,10 @@ namespace ts.server {
707685 return occurrences . map ( occurrence => {
708686 const { fileName, isWriteAccess, textSpan, isInString } = occurrence ;
709687 const scriptInfo = project . getScriptInfo ( fileName ) ;
710- const start = scriptInfo . positionToLineOffset ( textSpan . start ) ;
711- const end = scriptInfo . positionToLineOffset ( textSpanEnd ( textSpan ) ) ;
712688 const result : protocol . OccurrencesResponseItem = {
713- start,
714- end,
715689 file : fileName ,
716690 isWriteAccess,
691+ ...this . toLocationTextSpan ( textSpan , scriptInfo )
717692 } ;
718693 // no need to serialize the property if it is not true
719694 if ( isInString ) {
@@ -751,13 +726,13 @@ namespace ts.server {
751726 }
752727
753728 if ( simplifiedResult ) {
754- return documentHighlights . map ( convertToDocumentHighlightsItem ) ;
729+ return documentHighlights . map ( x => convertToDocumentHighlightsItem ( x , this . toLocationTextSpan ) ) ;
755730 }
756731 else {
757732 return documentHighlights ;
758733 }
759734
760- function convertToDocumentHighlightsItem ( documentHighlights : DocumentHighlights ) : protocol . DocumentHighlightsItem {
735+ function convertToDocumentHighlightsItem ( documentHighlights : DocumentHighlights , toLocationSpan : ( textSpan : TextSpan , scriptInfo : ScriptInfo ) => protocol . TextSpan ) : protocol . DocumentHighlightsItem {
761736 const { fileName, highlightSpans } = documentHighlights ;
762737
763738 const scriptInfo = project . getScriptInfo ( fileName ) ;
@@ -766,11 +741,10 @@ namespace ts.server {
766741 highlightSpans : highlightSpans . map ( convertHighlightSpan )
767742 } ;
768743
769- function convertHighlightSpan ( highlightSpan : HighlightSpan ) : protocol . HighlightSpan {
744+ function convertHighlightSpan ( this : Session , highlightSpan : HighlightSpan ) : protocol . HighlightSpan {
770745 const { textSpan, kind } = highlightSpan ;
771- const start = scriptInfo . positionToLineOffset ( textSpan . start ) ;
772- const end = scriptInfo . positionToLineOffset ( textSpanEnd ( textSpan ) ) ;
773- return { start, end, kind } ;
746+
747+ return { kind, ...toLocationSpan ( textSpan , scriptInfo ) } ;
774748 }
775749 }
776750 }
@@ -863,8 +837,7 @@ namespace ts.server {
863837 const locationScriptInfo = project . getScriptInfo ( location . fileName ) ;
864838 return {
865839 file : location . fileName ,
866- start : locationScriptInfo . positionToLineOffset ( location . textSpan . start ) ,
867- end : locationScriptInfo . positionToLineOffset ( textSpanEnd ( location . textSpan ) ) ,
840+ ...this . toLocationTextSpan ( location . textSpan , locationScriptInfo )
868841 } ;
869842 } ) ;
870843 } ,
@@ -959,16 +932,15 @@ namespace ts.server {
959932
960933 return references . map ( ref => {
961934 const refScriptInfo = project . getScriptInfo ( ref . fileName ) ;
962- const start = refScriptInfo . positionToLineOffset ( ref . textSpan . start ) ;
963- const refLineSpan = refScriptInfo . lineToTextSpan ( start . line - 1 ) ;
935+ const textSpan = this . toLocationTextSpan ( ref . textSpan , refScriptInfo ) ;
936+ const refLineSpan = refScriptInfo . lineToTextSpan ( textSpan . start . line - 1 ) ;
964937 const lineText = refScriptInfo . getSnapshot ( ) . getText ( refLineSpan . start , textSpanEnd ( refLineSpan ) ) . replace ( / \r | \n / g, "" ) ;
965938 return {
966939 file : ref . fileName ,
967- start,
968940 lineText,
969- end : refScriptInfo . positionToLineOffset ( textSpanEnd ( ref . textSpan ) ) ,
970941 isWriteAccess : ref . isWriteAccess ,
971- isDefinition : ref . isDefinition
942+ isDefinition : ref . isDefinition ,
943+ ...textSpan
972944 } ;
973945 } ) ;
974946 } ,
@@ -1107,11 +1079,10 @@ namespace ts.server {
11071079 return {
11081080 kind : quickInfo . kind ,
11091081 kindModifiers : quickInfo . kindModifiers ,
1110- start : scriptInfo . positionToLineOffset ( quickInfo . textSpan . start ) ,
1111- end : scriptInfo . positionToLineOffset ( textSpanEnd ( quickInfo . textSpan ) ) ,
11121082 displayString,
11131083 documentation : docString ,
1114- tags : quickInfo . tags || [ ]
1084+ tags : quickInfo . tags || [ ] ,
1085+ ...this . toLocationTextSpan ( quickInfo . textSpan , scriptInfo )
11151086 } ;
11161087 }
11171088 else {
@@ -1201,9 +1172,8 @@ namespace ts.server {
12011172
12021173 return edits . map ( ( edit ) => {
12031174 return {
1204- start : scriptInfo . positionToLineOffset ( edit . span . start ) ,
1205- end : scriptInfo . positionToLineOffset ( textSpanEnd ( edit . span ) ) ,
1206- newText : edit . newText ? edit . newText : ""
1175+ newText : edit . newText ? edit . newText : "" ,
1176+ ...this . toLocationTextSpan ( edit . span , scriptInfo )
12071177 } ;
12081178 } ) ;
12091179 }
@@ -1219,7 +1189,7 @@ namespace ts.server {
12191189 return mapDefined ( completions && completions . entries , entry => {
12201190 if ( completions . isMemberCompletion || ( entry . name . toLowerCase ( ) . indexOf ( prefix . toLowerCase ( ) ) === 0 ) ) {
12211191 const { name, kind, kindModifiers, sortText, replacementSpan } = entry ;
1222- const convertedSpan = replacementSpan ? this . decorateSpan ( replacementSpan , scriptInfo ) : undefined ;
1192+ const convertedSpan = replacementSpan ? this . toLocationTextSpan ( replacementSpan , scriptInfo ) : undefined ;
12231193 return { name, kind, kindModifiers, sortText, replacementSpan : convertedSpan } ;
12241194 }
12251195 } ) . sort ( ( a , b ) => compareStrings ( a . name , b . name ) ) ;
@@ -1353,13 +1323,13 @@ namespace ts.server {
13531323 this . projectService . closeClientFile ( file ) ;
13541324 }
13551325
1356- private decorateNavigationBarItems ( items : NavigationBarItem [ ] , scriptInfo : ScriptInfo ) : protocol . NavigationBarItem [ ] {
1326+ private mapLocationNavigationBarItems ( items : NavigationBarItem [ ] , scriptInfo : ScriptInfo ) : protocol . NavigationBarItem [ ] {
13571327 return map ( items , item => ( {
13581328 text : item . text ,
13591329 kind : item . kind ,
13601330 kindModifiers : item . kindModifiers ,
1361- spans : item . spans . map ( span => this . decorateSpan ( span , scriptInfo ) ) ,
1362- childItems : this . decorateNavigationBarItems ( item . childItems , scriptInfo ) ,
1331+ spans : item . spans . map ( span => this . toLocationTextSpan ( span , scriptInfo ) ) ,
1332+ childItems : this . mapLocationNavigationBarItems ( item . childItems , scriptInfo ) ,
13631333 indent : item . indent
13641334 } ) ) ;
13651335 }
@@ -1370,21 +1340,21 @@ namespace ts.server {
13701340 return ! items
13711341 ? undefined
13721342 : simplifiedResult
1373- ? this . decorateNavigationBarItems ( items , this . projectService . getScriptInfoForNormalizedPath ( file ) )
1343+ ? this . mapLocationNavigationBarItems ( items , this . projectService . getScriptInfoForNormalizedPath ( file ) )
13741344 : items ;
13751345 }
13761346
1377- private decorateNavigationTree ( tree : NavigationTree , scriptInfo : ScriptInfo ) : protocol . NavigationTree {
1347+ private toLocationNavigationTree ( tree : NavigationTree , scriptInfo : ScriptInfo ) : protocol . NavigationTree {
13781348 return {
13791349 text : tree . text ,
13801350 kind : tree . kind ,
13811351 kindModifiers : tree . kindModifiers ,
1382- spans : tree . spans . map ( span => this . decorateSpan ( span , scriptInfo ) ) ,
1383- childItems : map ( tree . childItems , item => this . decorateNavigationTree ( item , scriptInfo ) )
1352+ spans : tree . spans . map ( span => this . toLocationTextSpan ( span , scriptInfo ) ) ,
1353+ childItems : map ( tree . childItems , item => this . toLocationNavigationTree ( item , scriptInfo ) )
13841354 } ;
13851355 }
13861356
1387- private decorateSpan ( span : TextSpan , scriptInfo : ScriptInfo ) : protocol . TextSpan {
1357+ private toLocationTextSpan ( span : TextSpan , scriptInfo : ScriptInfo ) : protocol . TextSpan {
13881358 return {
13891359 start : scriptInfo . positionToLineOffset ( span . start ) ,
13901360 end : scriptInfo . positionToLineOffset ( textSpanEnd ( span ) )
@@ -1397,7 +1367,7 @@ namespace ts.server {
13971367 return ! tree
13981368 ? undefined
13991369 : simplifiedResult
1400- ? this . decorateNavigationTree ( tree , this . projectService . getScriptInfoForNormalizedPath ( file ) )
1370+ ? this . toLocationNavigationTree ( tree , this . projectService . getScriptInfoForNormalizedPath ( file ) )
14011371 : tree ;
14021372 }
14031373
@@ -1416,14 +1386,11 @@ namespace ts.server {
14161386
14171387 return navItems . map ( ( navItem ) => {
14181388 const scriptInfo = project . getScriptInfo ( navItem . fileName ) ;
1419- const start = scriptInfo . positionToLineOffset ( navItem . textSpan . start ) ;
1420- const end = scriptInfo . positionToLineOffset ( textSpanEnd ( navItem . textSpan ) ) ;
14211389 const bakedItem : protocol . NavtoItem = {
14221390 name : navItem . name ,
14231391 kind : navItem . kind ,
14241392 file : navItem . fileName ,
1425- start,
1426- end,
1393+ ...this . toLocationTextSpan ( navItem . textSpan , scriptInfo )
14271394 } ;
14281395 if ( navItem . kindModifiers && ( navItem . kindModifiers !== "" ) ) {
14291396 bakedItem . kindModifiers = navItem . kindModifiers ;
@@ -1629,7 +1596,7 @@ namespace ts.server {
16291596 return ! spans
16301597 ? undefined
16311598 : simplifiedResult
1632- ? spans . map ( span => this . decorateSpan ( span , scriptInfo ) )
1599+ ? spans . map ( span => this . toLocationTextSpan ( span , scriptInfo ) )
16331600 : spans ;
16341601 }
16351602
0 commit comments