@@ -35,7 +35,6 @@ export function main() {
35
35
fs . rmSync ( outputDir , { recursive : true , force : true } ) ;
36
36
fs . mkdirSync ( outputDir , { recursive : true } ) ;
37
37
38
- generateHelperFile ( ) ;
39
38
parseTypeScriptFiles ( getFailingTests ( ) , stradaFourslashPath ) ;
40
39
console . log ( unparsedFiles . join ( "\n" ) ) ;
41
40
const gofmt = which . sync ( "go" ) ;
@@ -317,25 +316,25 @@ function parseVerifyCompletionsArgs(args: readonly ts.Expression[]): VerifyCompl
317
316
}
318
317
319
318
const completionConstants = new Map ( [
320
- [ "completion.globals" , "completionGlobals " ] ,
321
- [ "completion.globalTypes" , "completionGlobalTypes " ] ,
322
- [ "completion.classElementKeywords" , "completionClassElementKeywords " ] ,
323
- [ "completion.classElementInJsKeywords" , "completionClassElementInJSKeywords " ] ,
324
- [ "completion.constructorParameterKeywords" , "completionConstructorParameterKeywords " ] ,
325
- [ "completion.functionMembersWithPrototype" , "completionFunctionMembersWithPrototype " ] ,
326
- [ "completion.functionMembers" , "completionFunctionMembers " ] ,
327
- [ "completion.typeKeywords" , "completionTypeKeywords " ] ,
328
- [ "completion.undefinedVarEntry" , "completionUndefinedVarItem " ] ,
329
- [ "completion.typeAssertionKeywords" , "completionTypeAssertionKeywords " ] ,
319
+ [ "completion.globals" , "CompletionGlobals " ] ,
320
+ [ "completion.globalTypes" , "CompletionGlobalTypes " ] ,
321
+ [ "completion.classElementKeywords" , "CompletionClassElementKeywords " ] ,
322
+ [ "completion.classElementInJsKeywords" , "CompletionClassElementInJSKeywords " ] ,
323
+ [ "completion.constructorParameterKeywords" , "CompletionConstructorParameterKeywords " ] ,
324
+ [ "completion.functionMembersWithPrototype" , "CompletionFunctionMembersWithPrototype " ] ,
325
+ [ "completion.functionMembers" , "CompletionFunctionMembers " ] ,
326
+ [ "completion.typeKeywords" , "CompletionTypeKeywords " ] ,
327
+ [ "completion.undefinedVarEntry" , "CompletionUndefinedVarItem " ] ,
328
+ [ "completion.typeAssertionKeywords" , "CompletionTypeAssertionKeywords " ] ,
330
329
] ) ;
331
330
332
331
const completionPlus = new Map ( [
333
- [ "completion.globalsPlus" , "completionGlobalsPlus " ] ,
334
- [ "completion.globalTypesPlus" , "completionGlobalTypesPlus " ] ,
335
- [ "completion.functionMembersPlus" , "completionFunctionMembersPlus " ] ,
336
- [ "completion.functionMembersWithPrototypePlus" , "completionFunctionMembersWithPrototypePlus " ] ,
337
- [ "completion.globalsInJsPlus" , "completionGlobalsInJSPlus " ] ,
338
- [ "completion.typeKeywordsPlus" , "completionTypeKeywordsPlus " ] ,
332
+ [ "completion.globalsPlus" , "CompletionGlobalsPlus " ] ,
333
+ [ "completion.globalTypesPlus" , "CompletionGlobalTypesPlus " ] ,
334
+ [ "completion.functionMembersPlus" , "CompletionFunctionMembersPlus " ] ,
335
+ [ "completion.functionMembersWithPrototypePlus" , "CompletionFunctionMembersWithPrototypePlus " ] ,
336
+ [ "completion.globalsInJsPlus" , "CompletionGlobalsInJSPlus " ] ,
337
+ [ "completion.typeKeywordsPlus" , "CompletionTypeKeywordsPlus " ] ,
339
338
] ) ;
340
339
341
340
function parseVerifyCompletionArg ( arg : ts . Expression ) : VerifyCompletionsCmd | undefined {
@@ -558,7 +557,7 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined {
558
557
if ( ! result ) {
559
558
return undefined ;
560
559
}
561
- itemProps . push ( `SortText: ptrTo (string(${ result } )),` ) ;
560
+ itemProps . push ( `SortText: PtrTo (string(${ result } )),` ) ;
562
561
if ( result === "ls.SortTextOptionalMember" ) {
563
562
isOptional = true ;
564
563
}
@@ -586,15 +585,15 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined {
586
585
break ;
587
586
case "isRecommended" :
588
587
if ( init . kind === ts . SyntaxKind . TrueKeyword ) {
589
- itemProps . push ( `Preselect: ptrTo (true),` ) ;
588
+ itemProps . push ( `Preselect: PtrTo (true),` ) ;
590
589
}
591
590
break ;
592
591
case "kind" :
593
592
const kind = parseKind ( init ) ;
594
593
if ( ! kind ) {
595
594
return undefined ;
596
595
}
597
- itemProps . push ( `Kind: ptrTo (${ kind } ),` ) ;
596
+ itemProps . push ( `Kind: PtrTo (${ kind } ),` ) ;
598
597
break ;
599
598
case "kindModifiers" :
600
599
const modifiers = parseKindModifiers ( init ) ;
@@ -605,7 +604,7 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined {
605
604
break ;
606
605
case "text" :
607
606
if ( ts . isStringLiteralLike ( init ) ) {
608
- itemProps . push ( `Detail: ptrTo (${ getGoStringLiteral ( init . text ) } ),` ) ;
607
+ itemProps . push ( `Detail: PtrTo (${ getGoStringLiteral ( init . text ) } ),` ) ;
609
608
}
610
609
else {
611
610
console . error ( `Expected string literal for text, got ${ init . getText ( ) } ` ) ;
@@ -645,8 +644,8 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined {
645
644
filterText ??= name ;
646
645
name += "?" ;
647
646
}
648
- if ( filterText ) itemProps . unshift ( `FilterText: ptrTo (${ getGoStringLiteral ( filterText ) } ),` ) ;
649
- if ( insertText ) itemProps . unshift ( `InsertText: ptrTo (${ getGoStringLiteral ( insertText ) } ),` ) ;
647
+ if ( filterText ) itemProps . unshift ( `FilterText: PtrTo (${ getGoStringLiteral ( filterText ) } ),` ) ;
648
+ if ( insertText ) itemProps . unshift ( `InsertText: PtrTo (${ getGoStringLiteral ( insertText ) } ),` ) ;
650
649
itemProps . unshift ( `Label: ${ getGoStringLiteral ( name ! ) } ,` ) ;
651
650
return `&lsproto.CompletionItem{\n${ itemProps . join ( "\n" ) } }` ;
652
651
}
@@ -875,12 +874,12 @@ function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: Ve
875
874
if ( args ?. exact ) expected . push ( `Exact: ${ args . exact } ,` ) ;
876
875
if ( args ?. unsorted ) expected . push ( `Unsorted: ${ args . unsorted } ,` ) ;
877
876
// !!! isIncomplete
878
- const commitCharacters = isNewIdentifierLocation ? "[]string{}" : "defaultCommitCharacters " ;
877
+ const commitCharacters = isNewIdentifierLocation ? "[]string{}" : "DefaultCommitCharacters " ;
879
878
expectedList = `&fourslash.CompletionsExpectedList{
880
879
IsIncomplete: false,
881
880
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
882
881
CommitCharacters: &${ commitCharacters } ,
883
- EditRange: ignored ,
882
+ EditRange: Ignored ,
884
883
},
885
884
Items: &fourslash.CompletionsExpectedItems{
886
885
${ expected . join ( "\n" ) }
@@ -945,6 +944,9 @@ function generateGoTest(failingTests: Set<string>, test: GoTest): string {
945
944
if ( commands . includes ( "lsproto." ) ) {
946
945
imports . push ( `"github.com/microsoft/typescript-go/internal/lsp/lsproto"` ) ;
947
946
}
947
+ if ( usesHelper ( commands ) ) {
948
+ imports . push ( `. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"` ) ;
949
+ }
948
950
imports . push ( `"github.com/microsoft/typescript-go/internal/testutil"` ) ;
949
951
const template = `package fourslash_test
950
952
@@ -965,8 +967,20 @@ func Test${testName}(t *testing.T) {
965
967
return template ;
966
968
}
967
969
968
- function generateHelperFile ( ) {
969
- fs . copyFileSync ( helperFilePath , path . join ( outputDir , "util_test.go" ) ) ;
970
+ function usesHelper ( goTxt : string ) : boolean {
971
+ for ( const [ _ , constant ] of completionConstants ) {
972
+ if ( goTxt . includes ( constant ) ) {
973
+ return true ;
974
+ }
975
+ }
976
+ for ( const [ _ , constant ] of completionPlus ) {
977
+ if ( goTxt . includes ( constant ) ) {
978
+ return true ;
979
+ }
980
+ }
981
+ return goTxt . includes ( "Ignored" )
982
+ || goTxt . includes ( "DefaultCommitCharacters" )
983
+ || goTxt . includes ( "PtrTo" ) ;
970
984
}
971
985
972
986
if ( url . fileURLToPath ( import . meta. url ) == process . argv [ 1 ] ) {
0 commit comments