@@ -2041,13 +2041,7 @@ namespace FourSlash {
20412041 }
20422042 }
20432043
2044- public verifyCodeFixAtPosition ( expectedText : string , errorCode ?: number ) {
2045-
2046- const ranges = this . getRanges ( ) ;
2047- if ( ranges . length == 0 ) {
2048- this . raiseError ( "At least one range should be specified in the testfile." ) ;
2049- }
2050-
2044+ private getCodeFixes ( errorCode ?: number ) {
20512045 const fileName = this . activeFile . fileName ;
20522046 const diagnostics = this . getDiagnostics ( fileName ) ;
20532047
@@ -2061,7 +2055,16 @@ namespace FourSlash {
20612055
20622056 const diagnostic = ! errorCode ? diagnostics [ 0 ] : ts . find ( diagnostics , d => d . code == errorCode ) ;
20632057
2064- const actual = this . languageService . getCodeFixesAtPosition ( fileName , diagnostic . start , diagnostic . length , [ `TS${ diagnostic . code } ` ] ) ;
2058+ return this . languageService . getCodeFixesAtPosition ( fileName , diagnostic . start , diagnostic . length , [ `TS${ diagnostic . code } ` ] ) ;
2059+ }
2060+
2061+ public verifyCodeFixAtPosition ( expectedText : string , errorCode ?: number ) {
2062+ const ranges = this . getRanges ( ) ;
2063+ if ( ranges . length == 0 ) {
2064+ this . raiseError ( "At least one range should be specified in the testfile." ) ;
2065+ }
2066+
2067+ const actual = this . getCodeFixes ( errorCode ) ;
20652068
20662069 if ( ! actual || actual . length == 0 ) {
20672070 this . raiseError ( "No codefixes returned." ) ;
@@ -2350,6 +2353,18 @@ namespace FourSlash {
23502353 }
23512354 }
23522355
2356+ public verifyCodeFixAvailable ( negative : boolean , errorCode ?:number ) {
2357+ const fixes = this . getCodeFixes ( errorCode ) ;
2358+
2359+ if ( negative && fixes && fixes . length > 0 ) {
2360+ this . raiseError ( `verifyCodeFixAvailable failed - expected no fixes, actual: ${ fixes . length } ` ) ;
2361+ }
2362+
2363+ if ( ! negative && ( fixes === undefined || fixes . length === 0 ) ) {
2364+ this . raiseError ( `verifyCodeFixAvailable failed - expected code fixes, actual: 0` ) ;
2365+ }
2366+ }
2367+
23532368 // Get the text of the entire line the caret is currently at
23542369 private getCurrentLineContent ( ) {
23552370 const text = this . getFileContent ( this . activeFile . fileName ) ;
@@ -3137,6 +3152,10 @@ namespace FourSlashInterface {
31373152 public isValidBraceCompletionAtPosition ( openingBrace : string ) {
31383153 this . state . verifyBraceCompletionAtPosition ( this . negative , openingBrace ) ;
31393154 }
3155+
3156+ public codeFixAvailable ( errorCode ?: number ) {
3157+ this . state . verifyCodeFixAvailable ( this . negative , errorCode ) ;
3158+ }
31403159 }
31413160
31423161 export class Verify extends VerifyNegatable {
0 commit comments