@@ -2122,36 +2122,81 @@ module FourSlash {
21222122 public verifyOccurrencesAtPositionListContains ( fileName : string , start : number , end : number , isWriteAccess ?: boolean ) {
21232123 this . taoInvalidReason = "verifyOccurrencesAtPositionListContains NYI" ;
21242124
2125- let occurances = this . getOccurancesAtCurrentPosition ( ) ;
2125+ let occurrences = this . getOccurancesAtCurrentPosition ( ) ;
21262126
2127- if ( ! occurances || occurances . length === 0 ) {
2128- this . raiseError ( " verifyOccurancesAtPositionListContains failed - found 0 references, expected at least one." ) ;
2127+ if ( ! occurrences || occurrences . length === 0 ) {
2128+ this . raiseError ( ' verifyOccurancesAtPositionListContains failed - found 0 references, expected at least one.' ) ;
21292129 }
21302130
2131- for ( let i = 0 ; i < occurances . length ; i ++ ) {
2132- let occurance = occurances [ i ] ;
2133- if ( occurance && occurance . fileName === fileName && occurance . textSpan . start === start && ts . textSpanEnd ( occurance . textSpan ) === end ) {
2134- if ( typeof isWriteAccess !== "undefined" && occurance . isWriteAccess !== isWriteAccess ) {
2135- this . raiseError ( `verifyOccurancesAtPositionListContains failed - item isWriteAccess value doe not match, actual: ${ occurance . isWriteAccess } , expected: ${ isWriteAccess } .` ) ;
2131+ for ( let occurrence of occurrences ) {
2132+ if ( occurrence && occurrence . fileName === fileName && occurrence . textSpan . start === start && ts . textSpanEnd ( occurrence . textSpan ) === end ) {
2133+ if ( typeof isWriteAccess !== "undefined" && occurrence . isWriteAccess !== isWriteAccess ) {
2134+ this . raiseError ( `verifyOccurrencesAtPositionListContains failed - item isWriteAccess value does not match, actual: ${ occurrence . isWriteAccess } , expected: ${ isWriteAccess } .` ) ;
21362135 }
21372136 return ;
21382137 }
21392138 }
21402139
21412140 let missingItem = { fileName : fileName , start : start , end : end , isWriteAccess : isWriteAccess } ;
2142- this . raiseError ( `verifyOccurancesAtPositionListContains failed - could not find the item: ${ JSON . stringify ( missingItem ) } in the returned list: (${ JSON . stringify ( occurances ) } )` ) ;
2141+ this . raiseError ( `verifyOccurrencesAtPositionListContains failed - could not find the item: ${ JSON . stringify ( missingItem ) } in the returned list: (${ JSON . stringify ( occurrences ) } )` ) ;
21432142 }
21442143
21452144 public verifyOccurrencesAtPositionListCount ( expectedCount : number ) {
21462145 this . taoInvalidReason = "verifyOccurrencesAtPositionListCount NYI" ;
21472146
2148- let occurances = this . getOccurancesAtCurrentPosition ( ) ;
2149- let actualCount = occurances ? occurances . length : 0 ;
2147+ let occurrences = this . getOccurancesAtCurrentPosition ( ) ;
2148+ let actualCount = occurrences ? occurrences . length : 0 ;
21502149 if ( expectedCount !== actualCount ) {
21512150 this . raiseError ( `verifyOccurrencesAtPositionListCount failed - actual: ${ actualCount } , expected:${ expectedCount } ` ) ;
21522151 }
21532152 }
21542153
2154+ private getDocumentHighlightsAtCurrentPosition ( fileNamesToSearch : string [ ] ) {
2155+ let filesToSearch = fileNamesToSearch . map ( name => ts . combinePaths ( this . basePath , name ) ) ;
2156+ return this . languageService . getDocumentHighlights ( this . activeFile . fileName , this . currentCaretPosition , filesToSearch ) ;
2157+ }
2158+
2159+ public verifyDocumentHighlightsAtPositionListContains ( fileName : string , start : number , end : number , fileNamesToSearch : string [ ] , kind ?: string ) {
2160+ this . taoInvalidReason = 'verifyDocumentHighlightsAtPositionListContains NYI' ;
2161+
2162+ let documentHighlights = this . getDocumentHighlightsAtCurrentPosition ( fileNamesToSearch ) ;
2163+
2164+ if ( ! documentHighlights || documentHighlights . length === 0 ) {
2165+ this . raiseError ( 'verifyDocumentHighlightsAtPositionListContains failed - found 0 highlights, expected at least one.' ) ;
2166+ }
2167+
2168+ for ( let documentHighlight of documentHighlights ) {
2169+ if ( documentHighlight . fileName === fileName ) {
2170+ let { highlightSpans } = documentHighlight ;
2171+
2172+ for ( let highlight of highlightSpans ) {
2173+ if ( highlight && highlight . textSpan . start === start && ts . textSpanEnd ( highlight . textSpan ) === end ) {
2174+ if ( typeof kind !== "undefined" && highlight . kind !== kind ) {
2175+ this . raiseError ( 'verifyDocumentHighlightsAtPositionListContains failed - item "kind" value does not match, actual: ' + highlight . kind + ', expected: ' + kind + '.' ) ;
2176+ }
2177+ return ;
2178+ }
2179+ }
2180+ }
2181+ }
2182+
2183+ let missingItem = { fileName : fileName , start : start , end : end , kind : kind } ;
2184+ this . raiseError ( 'verifyOccurancesAtPositionListContains failed - could not find the item: ' + JSON . stringify ( missingItem ) + ' in the returned list: (' + JSON . stringify ( documentHighlights ) + ')' ) ;
2185+ }
2186+
2187+ public verifyDocumentHighlightsAtPositionListCount ( expectedCount : number , fileNamesToSearch : string [ ] ) {
2188+ this . taoInvalidReason = 'verifyDocumentHighlightsAtPositionListCount NYI' ;
2189+
2190+ let documentHighlights = this . getDocumentHighlightsAtCurrentPosition ( fileNamesToSearch ) ;
2191+ let actualCount = documentHighlights
2192+ ? documentHighlights . reduce ( ( currentCount , { highlightSpans } ) => currentCount + highlightSpans . length , 0 )
2193+ : 0 ;
2194+
2195+ if ( expectedCount !== actualCount ) {
2196+ this . raiseError ( 'verifyDocumentHighlightsAtPositionListCount failed - actual: ' + actualCount + ', expected:' + expectedCount ) ;
2197+ }
2198+ }
2199+
21552200 // Get the text of the entire line the caret is currently at
21562201 private getCurrentLineContent ( ) {
21572202 let text = this . getFileContent ( this . activeFile . fileName ) ;
0 commit comments