@@ -2553,7 +2553,7 @@ namespace FourSlash {
25532553 * Rerieves a codefix satisfying the parameters, or undefined if no such codefix is found.
25542554 * @param fileName Path to file where error should be retrieved from.
25552555 */
2556- private getCodeFixes ( fileName : string , errorCode ?: number , preferences : ts . UserPreferences = ts . emptyOptions ) : readonly ts . CodeFixAction [ ] {
2556+ private getCodeFixes ( fileName : string , errorCode ?: number , preferences : ts . UserPreferences = ts . emptyOptions , position ?: number ) : readonly ts . CodeFixAction [ ] {
25572557 const diagnosticsForCodeFix = this . getDiagnostics ( fileName , /*includeSuggestions*/ true ) . map ( diagnostic => ( {
25582558 start : diagnostic . start ,
25592559 length : diagnostic . length ,
@@ -2564,7 +2564,12 @@ namespace FourSlash {
25642564 if ( errorCode !== undefined && errorCode !== diagnostic . code ) {
25652565 return ;
25662566 }
2567-
2567+ if ( position !== undefined && diagnostic . start !== undefined && diagnostic . length !== undefined ) {
2568+ const span = ts . createTextRangeFromSpan ( { start : diagnostic . start , length : diagnostic . length } ) ;
2569+ if ( ! ts . textRangeContainsPositionInclusive ( span , position ) ) {
2570+ return ;
2571+ }
2572+ }
25682573 return this . languageService . getCodeFixesAtPosition ( fileName , diagnostic . start ! , diagnostic . start ! + diagnostic . length ! , [ diagnostic . code ] , this . formatCodeSettings , preferences ) ;
25692574 } ) ;
25702575 }
@@ -2614,6 +2619,23 @@ namespace FourSlash {
26142619 } ) ;
26152620 }
26162621
2622+ public verifyImportFixModuleSpecifiers ( markerName : string , moduleSpecifiers : string [ ] ) {
2623+ const marker = this . getMarkerByName ( markerName ) ;
2624+ const codeFixes = this . getCodeFixes ( marker . fileName , ts . Diagnostics . Cannot_find_name_0 . code , {
2625+ includeCompletionsForModuleExports : true ,
2626+ includeCompletionsWithInsertText : true
2627+ } , marker . position ) . filter ( f => f . fixId === ts . codefix . importFixId ) ;
2628+
2629+ const actualModuleSpecifiers = ts . mapDefined ( codeFixes , fix => {
2630+ return ts . forEach ( ts . flatMap ( fix . changes , c => c . textChanges ) , c => {
2631+ const match = / (?: f r o m | r e q u i r e \( ) ( [ ' " ] ) ( (?: (? ! \1) .) * ) \1/ . exec ( c . newText ) ;
2632+ return match ?. [ 2 ] ;
2633+ } ) ;
2634+ } ) ;
2635+
2636+ assert . deepEqual ( actualModuleSpecifiers , moduleSpecifiers ) ;
2637+ }
2638+
26172639 public verifyDocCommentTemplate ( expected : ts . TextInsertion | undefined ) {
26182640 const name = "verifyDocCommentTemplate" ;
26192641 const actual = this . languageService . getDocCommentTemplateAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ! ;
0 commit comments