@@ -741,10 +741,6 @@ export class TestState {
741
741
}
742
742
}
743
743
744
- public verifyGoToDefinitionIs ( endMarker : ArrayOrSingle < string > ) {
745
- this . verifyGoToXWorker ( /*startMarker*/ undefined , toArray ( endMarker ) , ( ) => this . getGoToDefinition ( ) ) ;
746
- }
747
-
748
744
private getGoToDefinition ( ) : readonly ts . DefinitionInfo [ ] {
749
745
return this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ! ;
750
746
}
@@ -753,73 +749,6 @@ export class TestState {
753
749
return this . languageService . getDefinitionAndBoundSpan ( this . activeFile . fileName , this . currentCaretPosition ) ! ;
754
750
}
755
751
756
- private verifyGoToXWorker ( startMarker : string | undefined , endMarkers : readonly ( string | { marker ?: string , file ?: string , unverified ?: boolean } ) [ ] , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined , startMarkerName ?: string ) {
757
- const defs = getDefs ( ) ;
758
- let definitions : readonly ts . DefinitionInfo [ ] ;
759
- let testName : string ;
760
-
761
- if ( ! defs || ts . isArray ( defs ) ) {
762
- definitions = defs as ts . DefinitionInfo [ ] || [ ] ;
763
- testName = "goToDefinitions" ;
764
- }
765
- else {
766
- this . verifyDefinitionTextSpan ( defs , startMarkerName ! ) ;
767
-
768
- definitions = defs . definitions ! ; // TODO: GH#18217
769
- testName = "goToDefinitionsAndBoundSpan" ;
770
- }
771
-
772
- if ( endMarkers . length !== definitions . length ) {
773
- const markers = definitions . map ( d => ( { text : "HERE" , fileName : d . fileName , position : d . textSpan . start } ) ) ;
774
- const actual = this . renderMarkers ( markers ) ;
775
- this . raiseError ( `${ testName } failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } \n\n${ actual } ` ) ;
776
- }
777
-
778
- ts . zipWith ( endMarkers , definitions , ( endMarkerOrFileResult , definition , i ) => {
779
- const markerName = typeof endMarkerOrFileResult === "string" ? endMarkerOrFileResult : endMarkerOrFileResult . marker ;
780
- const marker = markerName !== undefined ? this . getMarkerByName ( markerName ) : undefined ;
781
- const expectedFileName = marker ?. fileName || typeof endMarkerOrFileResult !== "string" && endMarkerOrFileResult . file ;
782
- ts . Debug . assert ( typeof expectedFileName === "string" ) ;
783
- const expectedPosition = marker ?. position || 0 ;
784
- if ( ts . comparePaths ( expectedFileName , definition . fileName , /*ignoreCase*/ true ) !== ts . Comparison . EqualTo || expectedPosition !== definition . textSpan . start ) {
785
- const markers = [ { text : "EXPECTED" , fileName : expectedFileName , position : expectedPosition } , { text : "ACTUAL" , fileName : definition . fileName , position : definition . textSpan . start } ] ;
786
- const text = this . renderMarkers ( markers ) ;
787
- this . raiseError ( `${ testName } failed for definition ${ markerName || expectedFileName } (${ i } ): expected ${ expectedFileName } at ${ expectedPosition } , got ${ definition . fileName } at ${ definition . textSpan . start } \n\n${ text } \n` ) ;
788
- }
789
- if ( definition . unverified && ( typeof endMarkerOrFileResult === "string" || ! endMarkerOrFileResult . unverified ) ) {
790
- const isFileResult = typeof endMarkerOrFileResult !== "string" && ! ! endMarkerOrFileResult . file ;
791
- this . raiseError (
792
- `${ testName } failed for definition ${ markerName || expectedFileName } (${ i } ): The actual definition was an \`unverified\` result. Use:\n\n` +
793
- ` verify.goToDefinition(${ startMarker === undefined ? "startMarker" : `"${ startMarker } "` } , { ${ isFileResult ? `file: "${ expectedFileName } "` : `marker: "${ markerName } "` } , unverified: true })\n\n` +
794
- `if this is expected.`
795
- ) ;
796
- }
797
- } ) ;
798
- }
799
-
800
- private verifyDefinitionTextSpan ( defs : ts . DefinitionInfoAndBoundSpan , startMarkerName : string ) {
801
- const range = this . testData . ranges . find ( range => this . markerName ( range . marker ! ) === startMarkerName ) ;
802
-
803
- if ( ! range && ! defs . textSpan ) {
804
- return ;
805
- }
806
-
807
- if ( ! range ) {
808
- const marker = this . getMarkerByName ( startMarkerName ) ;
809
- const startFile = marker . fileName ;
810
- const fileContent = this . getFileContent ( startFile ) ;
811
- const spanContent = fileContent . slice ( defs . textSpan . start , ts . textSpanEnd ( defs . textSpan ) ) ;
812
- const spanContentWithMarker = spanContent . slice ( 0 , marker . position - defs . textSpan . start ) + `/*${ startMarkerName } */` + spanContent . slice ( marker . position - defs . textSpan . start ) ;
813
- const suggestedFileContent = ( fileContent . slice ( 0 , defs . textSpan . start ) + `\x1b[1;4m[|${ spanContentWithMarker } |]\x1b[0;31m` + fileContent . slice ( ts . textSpanEnd ( defs . textSpan ) ) )
814
- . split ( / \r ? \n / ) . map ( line => " " . repeat ( 6 ) + line ) . join ( ts . sys . newLine ) ;
815
- this . raiseError ( `goToDefinitionsAndBoundSpan failed. Found a starting TextSpan around '${ spanContent } ' in '${ startFile } ' (at position ${ defs . textSpan . start } ). `
816
- + `If this is the correct input span, put a fourslash range around it: \n\n${ suggestedFileContent } \n` ) ;
817
- }
818
- else {
819
- this . assertTextSpanEqualsRange ( defs . textSpan , range , "goToDefinitionsAndBoundSpan failed" ) ;
820
- }
821
- }
822
-
823
752
private renderMarkers ( markers : { text : string , fileName : string , position : number } [ ] , useTerminalBoldSequence = true ) {
824
753
const filesToDisplay = ts . deduplicate ( markers . map ( m => m . fileName ) , ts . equateValues ) ;
825
754
return filesToDisplay . map ( fileName => {
@@ -4120,12 +4049,6 @@ export class TestState {
4120
4049
Harness . Baseline . runBaseline ( baselineFile , text ) ;
4121
4050
}
4122
4051
4123
- private assertTextSpanEqualsRange ( span : ts . TextSpan , range : Range , message ?: string ) {
4124
- if ( ! textSpanEqualsRange ( span , range ) ) {
4125
- this . raiseError ( `${ prefixMessage ( message ) } Expected to find TextSpan ${ JSON . stringify ( { start : range . pos , length : range . end - range . pos } ) } but got ${ JSON . stringify ( span ) } instead.` ) ;
4126
- }
4127
- }
4128
-
4129
4052
private getLineContent ( index : number ) {
4130
4053
const text = this . getFileContent ( this . activeFile . fileName ) ;
4131
4054
const pos = this . languageServiceAdapterHost . lineAndCharacterToPosition ( this . activeFile . fileName , { line : index , character : 0 } ) ;
@@ -4308,14 +4231,6 @@ export class TestState {
4308
4231
}
4309
4232
}
4310
4233
4311
- function prefixMessage ( message : string | undefined ) {
4312
- return message ? `${ message } - ` : "" ;
4313
- }
4314
-
4315
- function textSpanEqualsRange ( span : ts . TextSpan , range : Range ) {
4316
- return span . start === range . pos && span . length === range . end - range . pos ;
4317
- }
4318
-
4319
4234
function updateTextRangeForTextChanges ( { pos, end } : ts . TextRange , textChanges : readonly ts . TextChange [ ] ) : ts . TextRange {
4320
4235
forEachTextChange ( textChanges , change => {
4321
4236
const update = ( p : number ) : number => updatePosition ( p , change . span . start , ts . textSpanEnd ( change . span ) , change . newText ) ;
0 commit comments