@@ -2544,8 +2544,8 @@ namespace FourSlash {
25442544
25452545 public verifyCodeFixAll ( { fixId, fixAllDescription, newFileContent, commands : expectedCommands } : FourSlashInterface . VerifyCodeFixAllOptions ) : void {
25462546 const fixWithId = ts . find ( this . getCodeFixes ( this . activeFile . fileName ) , a => a . fixId === fixId ) ;
2547- ts . Debug . assert ( fixWithId !== undefined , "No available code fix has that group id." , ( ) =>
2548- `Expected '${ fixId } '. Available action ids: ${ ts . mapDefined ( this . getCodeFixes ( this . activeFile . fileName ) , a => a . fixId ) } ` ) ;
2547+ ts . Debug . assert ( fixWithId !== undefined , "No available code fix has the expected id. Fix All is not available if there is only one potentially fixable diagnostic present ." , ( ) =>
2548+ `Expected '${ fixId } '. Available actions:\n ${ ts . mapDefined ( this . getCodeFixes ( this . activeFile . fileName ) , a => ` ${ a . fixName } ( ${ a . fixId || "no fix id" } )` ) . join ( "\n" ) } ` ) ;
25492549 ts . Debug . assertEqual ( fixWithId ! . fixAllDescription , fixAllDescription ) ;
25502550
25512551 const { changes, commands } = this . languageService . getCombinedCodeFix ( { type : "file" , fileName : this . activeFile . fileName } , fixId , this . formatCodeSettings , ts . emptyOptions ) ;
@@ -2681,7 +2681,7 @@ namespace FourSlash {
26812681 }
26822682 const range = ts . firstOrUndefined ( ranges ) ;
26832683
2684- const codeFixes = this . getCodeFixes ( fileName , errorCode , preferences ) . filter ( f => f . fixId === ts . codefix . importFixId ) ;
2684+ const codeFixes = this . getCodeFixes ( fileName , errorCode , preferences ) . filter ( f => f . fixName === ts . codefix . importFixName ) ;
26852685
26862686 if ( codeFixes . length === 0 ) {
26872687 if ( expectedTextArray . length !== 0 ) {
@@ -2717,7 +2717,7 @@ namespace FourSlash {
27172717 const codeFixes = this . getCodeFixes ( marker . fileName , ts . Diagnostics . Cannot_find_name_0 . code , {
27182718 includeCompletionsForModuleExports : true ,
27192719 includeCompletionsWithInsertText : true
2720- } , marker . position ) . filter ( f => f . fixId === ts . codefix . importFixId ) ;
2720+ } , marker . position ) . filter ( f => f . fixName === ts . codefix . importFixName ) ;
27212721
27222722 const actualModuleSpecifiers = ts . mapDefined ( codeFixes , fix => {
27232723 return ts . forEach ( ts . flatMap ( fix . changes , c => c . textChanges ) , c => {
@@ -3044,6 +3044,26 @@ namespace FourSlash {
30443044 }
30453045 }
30463046
3047+ public verifyCodeFixAllAvailable ( negative : boolean , fixName : string ) {
3048+ const availableFixes = this . getCodeFixes ( this . activeFile . fileName ) ;
3049+ const hasFix = availableFixes . some ( fix => fix . fixName === fixName && fix . fixId ) ;
3050+ if ( negative && hasFix ) {
3051+ this . raiseError ( `Expected not to find a fix with the name '${ fixName } ', but one exists.` ) ;
3052+ }
3053+ else if ( ! negative && ! hasFix ) {
3054+ if ( availableFixes . some ( fix => fix . fixName === fixName ) ) {
3055+ this . raiseError ( `Found a fix with the name '${ fixName } ', but fix-all is not available.` ) ;
3056+ }
3057+
3058+ this . raiseError (
3059+ `Expected to find a fix with the name '${ fixName } ', but none exists.` +
3060+ availableFixes . length
3061+ ? ` Available fixes: ${ availableFixes . map ( fix => `${ fix . fixName } (${ fix . fixId ? "with" : "without" } fix-all)` ) . join ( ", " ) } `
3062+ : ""
3063+ ) ;
3064+ }
3065+ }
3066+
30473067 public verifyApplicableRefactorAvailableAtMarker ( negative : boolean , markerName : string ) {
30483068 const isAvailable = this . getApplicableRefactors ( this . getMarkerByName ( markerName ) ) . length > 0 ;
30493069 if ( negative && isAvailable ) {
0 commit comments