@@ -92,11 +92,14 @@ namespace FourSlash {
9292 end : number ;
9393 }
9494
95- export interface ErrorIdentifier {
95+ export interface CodeFixIdentifier {
96+ /**
97+ * Error code to search over for codefix.
98+ */
9699 code : number ;
97100 /**
98101 * In a file where there is more than one error with code `code`, `count` refers
99- * to which 0-indexed error , sorted by order of occurence, to consider.
102+ * to which 0-indexed codefix , sorted by order of occurence, to consider.
100103 */
101104 count : number ;
102105 }
@@ -2022,14 +2025,14 @@ namespace FourSlash {
20222025 * Because codefixes are only applied on the working file, it is unsafe
20232026 * to apply this more than once (consider a refactoring across files).
20242027 */
2025- public verifyCodeFixAtPosition ( expectedText : string , errorCode ?: number ) {
2028+ public verifyRangeAfterCodeFix ( expectedText : string , codeFixIdentifier ?: CodeFixIdentifier ) {
20262029 const ranges = this . getRanges ( ) ;
20272030 if ( ranges . length !== 1 ) {
20282031 this . raiseError ( "Exactly one range should be specified in the testfile." ) ;
20292032 }
20302033
20312034 const fileName = this . activeFile . fileName ;
2032- const codeFix : ts . CodeAction = this . getCodeFix ( fileName , errorCode ? { code : errorCode , count : 0 } : undefined ) ;
2035+ const codeFix : ts . CodeAction = this . getCodeFix ( fileName , codeFixIdentifier ) ;
20332036
20342037 if ( ! codeFix ) {
20352038 this . raiseError ( "Should find exactly one codefix." ) ;
@@ -2052,37 +2055,36 @@ namespace FourSlash {
20522055 * Applies fixes for the errors in fileName and compares the results to
20532056 * expectedContents after all fixes have been applied.
20542057 *
2058+ * It is safe to apply this multiple times in a single test.
2059+ *
20552060 * Note: applying one codefix may generate another (eg: remove duplicate implements
20562061 * may generate an extends -> interface conversion fix).
20572062 * @param expectedContents The contents of the file after the fixes are applied.
20582063 * @param fileName The file to check. If not supplied, the current open file is used.
20592064 * @param errorsToFix An array of errors for which quickfixes will be applied. If not
20602065 * supplied, all codefixes in the file are applied until none are left, starting from
20612066 * the first available codefix.
2062- *
2067+ *
20632068 */
2064- public verifyFileAfterCodeFix ( expectedContents : string , fileName ?: string , errorsToFix ?: ErrorIdentifier [ ] ) {
2069+ public verifyFileAfterCodeFix ( expectedContents : string , fileName ?: string , codeFixIdentifier ?: CodeFixIdentifier ) {
20652070 fileName = fileName ? fileName : this . activeFile . fileName ;
20662071
2067- if ( errorsToFix ) {
2068- for ( const error of errorsToFix ) {
2069- const fix = this . getCodeFix ( fileName , error ) ;
2070- if ( fix === undefined ) {
2071- this . raiseError ( `Couldn't find the ${ error . count } 'th error with code ${ error . code } .` ) ;
2072- }
2073- this . applyCodeAction ( fix ) ;
2072+ const codeFix = this . getCodeFix ( fileName , codeFixIdentifier ) ;
2073+
2074+ if ( codeFix === undefined ) {
2075+ if ( codeFixIdentifier ) {
2076+ this . raiseError ( `Couldn't find the ${ codeFixIdentifier . count } 'th error with code ${ codeFixIdentifier . code } .` ) ;
20742077 }
2075- }
2076- else {
2077- let fix : ts . CodeAction ;
2078- while ( fix = this . getCodeFix ( fileName ) ) {
2079- this . applyCodeAction ( fix ) ;
2078+ else {
2079+ this . raiseError ( "No code fix could be found." ) ;
20802080 }
20812081 }
20822082
2083+ this . applyCodeAction ( codeFix ) ;
2084+
20832085 const actualContents : string = this . getFileContent ( fileName ) ;
20842086 if ( this . removeWhitespace ( actualContents ) !== this . removeWhitespace ( expectedContents ) ) {
2085- this . raiseError ( `Actual text doesn't match expected text. Actual:\n${ actualContents } \n\nExpected:\n${ expectedContents } ` ) ;
2087+ this . raiseError ( `Actual text doesn't match expected text. Actual:\n${ actualContents } \n\nExpected:\n\n ${ expectedContents } ` ) ;
20862088 }
20872089 }
20882090
@@ -2093,7 +2095,7 @@ namespace FourSlash {
20932095 *
20942096 * If undefined, we get the first codefix available.
20952097 */
2096- private getCodeFix ( fileName : string , error ?: ErrorIdentifier ) : ts . CodeAction | undefined {
2098+ private getCodeFix ( fileName : string , error ?: CodeFixIdentifier ) : ts . CodeAction | undefined {
20972099 const diagnostics : ts . Diagnostic [ ] = this . getDiagnostics ( fileName ) ;
20982100 const errorCount = error ? error . count : 0 ;
20992101
@@ -3364,12 +3366,12 @@ namespace FourSlashInterface {
33643366 this . DocCommentTemplate ( /*expectedText*/ undefined , /*expectedOffset*/ undefined , /*empty*/ true ) ;
33653367 }
33663368
3367- public codeFixAtPosition ( expectedText : string , errorCode ?: number ) : void {
3368- this . state . verifyCodeFixAtPosition ( expectedText , errorCode ) ;
3369+ public rangeAfterCodeFix ( expectedText : string , codeFixidentifier ?: FourSlash . CodeFixIdentifier ) : void {
3370+ this . state . verifyRangeAfterCodeFix ( expectedText , codeFixidentifier ) ;
33693371 }
33703372
3371- public fileAfterCodeFixes ( expectedContents : string , fileName ?: string , errorsToFix ?: FourSlash . ErrorIdentifier [ ] ) : void {
3372- this . state . verifyFileAfterCodeFix ( expectedContents , fileName , errorsToFix ) ;
3373+ public fileAfterCodeFix ( expectedContents : string , fileName ?: string , codeFixidentifier ?: FourSlash . CodeFixIdentifier ) : void {
3374+ this . state . verifyFileAfterCodeFix ( expectedContents , fileName , codeFixidentifier ) ;
33733375 }
33743376
33753377 public navigationBar ( json : any ) {
0 commit comments