@@ -175,6 +175,9 @@ function parseFourslashStatement(statement: ts.Statement): Cmd[] | undefined {
175175 case "applyCodeActionFromCompletion" :
176176 // `verify.applyCodeActionFromCompletion(...)`
177177 return parseVerifyApplyCodeActionFromCompletionArgs ( callExpression . arguments ) ;
178+ case "importFixAtPosition" :
179+ // `verify.importFixAtPosition(...)`
180+ return parseImportFixAtPositionArgs ( callExpression . arguments ) ;
178181 case "quickInfoAt" :
179182 case "quickInfoExists" :
180183 case "quickInfoIs" :
@@ -542,6 +545,46 @@ function parseVerifyApplyCodeActionArgs(arg: ts.Expression): string | undefined
542545 return `&fourslash.ApplyCodeActionFromCompletionOptions{\n${ props . join ( "\n" ) } \n}` ;
543546}
544547
548+ function parseImportFixAtPositionArgs ( args : readonly ts . Expression [ ] ) : VerifyImportFixAtPositionCmd [ ] | undefined {
549+ if ( args . length < 1 || args . length > 3 ) {
550+ console . error ( `Expected 1-3 arguments in verify.importFixAtPosition, got ${ args . map ( arg => arg . getText ( ) ) . join ( ", " ) } ` ) ;
551+ return undefined ;
552+ }
553+ const arrayArg = getArrayLiteralExpression ( args [ 0 ] ) ;
554+ if ( ! arrayArg ) {
555+ console . error ( `Expected array literal for first argument in verify.importFixAtPosition, got ${ args [ 0 ] . getText ( ) } ` ) ;
556+ return undefined ;
557+ }
558+ const expectedTexts : string [ ] = [ ] ;
559+ for ( const elem of arrayArg . elements ) {
560+ const strElem = getStringLiteralLike ( elem ) ;
561+ if ( ! strElem ) {
562+ console . error ( `Expected string literal in verify.importFixAtPosition array, got ${ elem . getText ( ) } ` ) ;
563+ return undefined ;
564+ }
565+ expectedTexts . push ( getGoMultiLineStringLiteral ( strElem . text ) ) ;
566+ }
567+
568+ // If the array is empty, we should still generate valid Go code
569+ if ( expectedTexts . length === 0 ) {
570+ expectedTexts . push ( "" ) ; // This will be handled specially in code generation
571+ }
572+
573+ let preferences : string | undefined ;
574+ if ( args . length > 2 && ts . isObjectLiteralExpression ( args [ 2 ] ) ) {
575+ preferences = parseUserPreferences ( args [ 2 ] ) ;
576+ if ( ! preferences ) {
577+ console . error ( `Unrecognized user preferences in verify.importFixAtPosition: ${ args [ 2 ] . getText ( ) } ` ) ;
578+ return undefined ;
579+ }
580+ }
581+ return [ {
582+ kind : "verifyImportFixAtPosition" ,
583+ expectedTexts,
584+ preferences : preferences || "nil /*preferences*/" ,
585+ } ] ;
586+ }
587+
545588const completionConstants = new Map ( [
546589 [ "completion.globals" , "CompletionGlobals" ] ,
547590 [ "completion.globalTypes" , "CompletionGlobalTypes" ] ,
@@ -1240,6 +1283,21 @@ function parseUserPreferences(arg: ts.ObjectLiteralExpression): string | undefin
12401283 case "quotePreference" :
12411284 preferences . push ( `QuotePreference: lsutil.QuotePreference(${ prop . initializer . getText ( ) } )` ) ;
12421285 break ;
1286+ case "autoImportFileExcludePatterns" :
1287+ const arrayArg = getArrayLiteralExpression ( prop . initializer ) ;
1288+ if ( ! arrayArg ) {
1289+ return undefined ;
1290+ }
1291+ const patterns : string [ ] = [ ] ;
1292+ for ( const elem of arrayArg . elements ) {
1293+ const strElem = getStringLiteralLike ( elem ) ;
1294+ if ( ! strElem ) {
1295+ return undefined ;
1296+ }
1297+ patterns . push ( getGoStringLiteral ( strElem . text ) ) ;
1298+ }
1299+ preferences . push ( `AutoImportFileExcludePatterns: []string{${ patterns . join ( ", " ) } }` ) ;
1300+ break ;
12431301 case "includeInlayParameterNameHints" :
12441302 let paramHint ;
12451303 if ( ! ts . isStringLiteralLike ( prop . initializer ) ) {
@@ -1701,6 +1759,12 @@ interface VerifyBaselineInlayHintsCmd {
17011759 preferences : string ;
17021760}
17031761
1762+ interface VerifyImportFixAtPositionCmd {
1763+ kind : "verifyImportFixAtPosition" ;
1764+ expectedTexts : string [ ] ;
1765+ preferences : string ;
1766+ }
1767+
17041768interface GoToCmd {
17051769 kind : "goTo" ;
17061770 // !!! `selectRange` and `rangeStart` require parsing variables and `test.ranges()[n]`
@@ -1739,7 +1803,8 @@ type Cmd =
17391803 | VerifyQuickInfoCmd
17401804 | VerifyBaselineRenameCmd
17411805 | VerifyRenameInfoCmd
1742- | VerifyBaselineInlayHintsCmd ;
1806+ | VerifyBaselineInlayHintsCmd
1807+ | VerifyImportFixAtPositionCmd ;
17431808
17441809function generateVerifyCompletions ( { marker, args, isNewIdentifierLocation, andApplyCodeActionArgs } : VerifyCompletionsCmd ) : string {
17451810 let expectedList : string ;
@@ -1840,6 +1905,14 @@ function generateBaselineInlayHints({ span, preferences }: VerifyBaselineInlayHi
18401905 return `f.VerifyBaselineInlayHints(t, ${ span } , ${ preferences } )` ;
18411906}
18421907
1908+ function generateImportFixAtPosition ( { expectedTexts, preferences } : VerifyImportFixAtPositionCmd ) : string {
1909+ // Handle empty array case
1910+ if ( expectedTexts . length === 1 && expectedTexts [ 0 ] === "" ) {
1911+ return `f.VerifyImportFixAtPosition(t, []string{}, ${ preferences } )` ;
1912+ }
1913+ return `f.VerifyImportFixAtPosition(t, []string{\n${ expectedTexts . join ( ",\n" ) } ,\n}, ${ preferences } )` ;
1914+ }
1915+
18431916function generateCmd ( cmd : Cmd ) : string {
18441917 switch ( cmd . kind ) {
18451918 case "verifyCompletions" :
@@ -1878,6 +1951,8 @@ function generateCmd(cmd: Cmd): string {
18781951 return `f.VerifyRenameFailed(t, ${ cmd . preferences } )` ;
18791952 case "verifyBaselineInlayHints" :
18801953 return generateBaselineInlayHints ( cmd ) ;
1954+ case "verifyImportFixAtPosition" :
1955+ return generateImportFixAtPosition ( cmd ) ;
18811956 default :
18821957 let neverCommand : never = cmd ;
18831958 throw new Error ( `Unknown command kind: ${ neverCommand as Cmd [ "kind" ] } ` ) ;
0 commit comments