diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index 8a56d152ff..a094443a79 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -370,6 +370,13 @@ function parseVerifyCompletionArg(arg: ts.Expression): VerifyCompletionsCmd | un else if (init.getText() === "test.markers()") { marker = "f.Markers()"; } + else if ( + ts.isCallExpression(init) + && init.expression.getText() === "test.marker" + && ts.isStringLiteralLike(init.arguments[0]) + ) { + marker = getGoStringLiteral(init.arguments[0].text); + } else { console.error(`Unrecognized marker initializer: ${init.getText()}`); return undefined; @@ -511,7 +518,7 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined { if (completionConstants.has(expr.getText())) { return completionConstants.get(expr.getText())!; } - if (ts.isStringLiteral(expr)) { + if (ts.isStringLiteralLike(expr)) { return getGoStringLiteral(expr.text); } if (ts.isObjectLiteralExpression(expr)) { @@ -531,7 +538,7 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined { const init = prop.initializer; switch (propName) { case "name": - if (ts.isStringLiteral(init)) { + if (ts.isStringLiteralLike(init)) { name = init.text; } else { @@ -550,16 +557,19 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined { } break; case "insertText": - if (ts.isStringLiteral(init)) { + if (ts.isStringLiteralLike(init)) { insertText = init.text; } + else if (init.getText() === "undefined") { + // Ignore + } else { console.error(`Expected string literal for insertText, got ${init.getText()}`); return undefined; } break; case "filterText": - if (ts.isStringLiteral(init)) { + if (ts.isStringLiteralLike(init)) { filterText = init.text; } else { @@ -609,6 +619,8 @@ function parseExpectedCompletionItem(expr: ts.Expression): string | undefined { return undefined; } break; + case "isFromUncheckedFile": + break; // Ignored case "commitCharacters": case "replacementSpan": // !!! support these later @@ -742,6 +754,9 @@ function parseKindModifiers(expr: ts.Expression): { isOptional: boolean; isDepre } function parseSortText(expr: ts.Expression): string | undefined { + if (ts.isCallExpression(expr) && expr.expression.getText() === "completion.SortText.Deprecated") { + return `ls.DeprecateSortText(${parseSortText(expr.arguments[0])})`; + } const text = expr.getText(); switch (text) { case "completion.SortText.LocalDeclarationPriority": diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index f0639b78fb..3460c34703 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -65,7 +65,11 @@ TestCompletionInFunctionLikeBody_includesPrimitiveTypes TestCompletionInJsDoc TestCompletionInJsDocQualifiedNames TestCompletionInNamedImportLocation +TestCompletionInUncheckedJSFile TestCompletionInfoWithExplicitTypeArguments +TestCompletionListAfterRegularExpressionLiteral01 +TestCompletionListAfterRegularExpressionLiteral1 +TestCompletionListAfterStringLiteral1 TestCompletionListAndMemberListOnCommentedDot TestCompletionListAndMemberListOnCommentedLine TestCompletionListAndMemberListOnCommentedWhiteSpace @@ -124,6 +128,7 @@ TestCompletionListStringParenthesizedExpression TestCompletionListStringParenthesizedType TestCompletionListWithoutVariableinitializer TestCompletionListsStringLiteralTypeAsIndexedAccessTypeObject +TestCompletionNoAutoInsertQuestionDotForThis TestCompletionNoAutoInsertQuestionDotForTypeParameter TestCompletionNoAutoInsertQuestionDotWithUserPreferencesOff TestCompletionOfAwaitPromise6 @@ -135,6 +140,7 @@ TestCompletionsAfterJSDoc TestCompletionsAugmentedTypesClass2 TestCompletionsBeforeRestArg1 TestCompletionsDefaultExport +TestCompletionsECMAPrivateMember TestCompletionsECMAPrivateMemberTriggerCharacter TestCompletionsExportImport TestCompletionsGenericTypeWithMultipleBases1 @@ -162,6 +168,8 @@ TestCompletionsNewTarget TestCompletionsOptionalKindModifier TestCompletionsOptionalMethod TestCompletionsOverridingMethod1 +TestCompletionsOverridingMethod10 +TestCompletionsOverridingMethod11 TestCompletionsOverridingMethod14 TestCompletionsOverridingMethod17 TestCompletionsOverridingMethod3 @@ -185,6 +193,9 @@ TestCompletionsSymbolMembers TestCompletionsTriggerCharacter TestCompletionsTypeOnlyNamespace TestCompletionsUniqueSymbol1 +TestCompletionsWithDeprecatedTag5 +TestCompletionsWithDeprecatedTag6 +TestCompletionsWithDeprecatedTag9 TestCompletionsWithStringReplacementMode1 TestDoubleUnderscoreCompletions TestExportDefaultClass diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index 8f972cf9bb..0189cba8da 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -338,7 +338,7 @@ func (f *FourslashTest) goToPosition(t *testing.T, position lsproto.Position) { f.selectionEnd = nil } -func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, action func(t *testing.T, marker *Marker, index int)) { +func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, action func(marker *Marker, index int)) { var markers []*Marker if len(markers) == 0 { markers = f.Markers() @@ -354,7 +354,7 @@ func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, actio } for i, marker := range markers { f.goToMarker(t, marker) - action(t, marker, i) + action(marker, i) } } diff --git a/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go b/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go index c728bd7434..46255d0b81 100644 --- a/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go +++ b/internal/fourslash/tests/completionListInUnclosedTypeArguments_test.go @@ -34,7 +34,7 @@ f2/*4x*/T/*5x*/y/*6x*/ f2<() =>/*1y*/T/*2y*/y/*3y*/, () =>/*4y*/T/*5y*/y/*6y*/ f2/*1z*/T/*2z*/y/*3z*/` f := fourslash.NewFourslash(t, nil /*capabilities*/, content) - f.GoToEachMarker(t, nil, func(t *testing.T, marker *fourslash.Marker, index int) { + f.GoToEachMarker(t, nil, func(marker *fourslash.Marker, index int) { markerName := marker.Name valueOnly := markerName != nil && strings.HasSuffix(*markerName, "ValueOnly") commitCharacters := &defaultCommitCharacters diff --git a/internal/fourslash/tests/gen/completionInUncheckedJSFile_test.go b/internal/fourslash/tests/gen/completionInUncheckedJSFile_test.go new file mode 100644 index 0000000000..3a5e1d7fd6 --- /dev/null +++ b/internal/fourslash/tests/gen/completionInUncheckedJSFile_test.go @@ -0,0 +1,46 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionInUncheckedJSFile(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @allowJs: true +// @checkJs: false +// @Filename: index.js +function hello() { + +} + +const goodbye = 5; + +console./*0*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "0", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "hello", + SortText: ptrTo(string(ls.SortTextJavascriptIdentifiers)), + }, + &lsproto.CompletionItem{ + Label: "goodbye", + SortText: ptrTo(string(ls.SortTextJavascriptIdentifiers)), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral01_test.go b/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral01_test.go new file mode 100644 index 0000000000..9f7c1892d0 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral01_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListAfterRegularExpressionLiteral01(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `let v = 100; +/a/./**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{ + "exec", + "test", + "source", + "global", + "ignoreCase", + "multiline", + "lastIndex", + &lsproto.CompletionItem{ + Label: "compile", + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral1_test.go b/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral1_test.go new file mode 100644 index 0000000000..831c895057 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListAfterRegularExpressionLiteral1_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListAfterRegularExpressionLiteral1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/a/./**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{ + "exec", + "test", + "source", + "global", + "ignoreCase", + "multiline", + "lastIndex", + &lsproto.CompletionItem{ + Label: "compile", + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListAfterStringLiteral1_test.go b/internal/fourslash/tests/gen/completionListAfterStringLiteral1_test.go new file mode 100644 index 0000000000..15fa5f4d69 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListAfterStringLiteral1_test.go @@ -0,0 +1,53 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListAfterStringLiteral1(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `"a"./**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{ + "toString", + "charAt", + "charCodeAt", + "concat", + "indexOf", + "lastIndexOf", + "localeCompare", + "match", + "replace", + "search", + "slice", + "split", + "substring", + "toLowerCase", + "toLocaleLowerCase", + "toUpperCase", + "toLocaleUpperCase", + "trim", + "length", + &lsproto.CompletionItem{ + Label: "substr", + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + "valueOf", + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionNoAutoInsertQuestionDotForThis_test.go b/internal/fourslash/tests/gen/completionNoAutoInsertQuestionDotForThis_test.go new file mode 100644 index 0000000000..960fe73731 --- /dev/null +++ b/internal/fourslash/tests/gen/completionNoAutoInsertQuestionDotForThis_test.go @@ -0,0 +1,47 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionNoAutoInsertQuestionDotForThis(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true +class Address { + city: string = ""; + "postal code": string = ""; + method() { + this[|./**/|] + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "city", + Detail: ptrTo("(property) Address.city: string"), + }, + &lsproto.CompletionItem{ + Label: "method", + }, + &lsproto.CompletionItem{ + Label: "postal code", + InsertText: ptrTo("[\"postal code\"]"), + Detail: ptrTo("(property) Address[\"postal code\"]: string"), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsECMAPrivateMember_test.go b/internal/fourslash/tests/gen/completionsECMAPrivateMember_test.go new file mode 100644 index 0000000000..305d3f9826 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsECMAPrivateMember_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsECMAPrivateMember(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @target: esnext +class K { + #value: number; + + foo() { + this.#va/**/ + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "#value", + }, + &lsproto.CompletionItem{ + Label: "foo", + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsForStringDependingOnContexSensitiveSignature_test.go b/internal/fourslash/tests/gen/completionsForStringDependingOnContexSensitiveSignature_test.go new file mode 100644 index 0000000000..55b361f27f --- /dev/null +++ b/internal/fourslash/tests/gen/completionsForStringDependingOnContexSensitiveSignature_test.go @@ -0,0 +1,76 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsForStringDependingOnContexSensitiveSignature(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true + +type ActorRef = { + send: (ev: TEvent) => void +} + +type Action = { + (ctx: TContext): void +} + +type Config = { + entry: Action +} + +declare function createMachine(config: Config): void + +type EventFrom = T extends ActorRef ? TEvent : never + +declare function sendTo< + TContext, + TActor extends ActorRef +>( + actor: ((ctx: TContext) => TActor), + event: EventFrom +): Action + +createMachine<{ + child: ActorRef<{ type: "EVENT" }>; +}>({ + entry: sendTo((ctx) => ctx.child, { type: /*1*/ }), +}); + +createMachine<{ + child: ActorRef<{ type: "EVENT" }>; +}>({ + entry: sendTo((ctx) => ctx.child, { type: "/*2*/" }), +});` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "\"EVENT\"", + }, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + "EVENT", + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsJsxExpression_test.go b/internal/fourslash/tests/gen/completionsJsxExpression_test.go new file mode 100644 index 0000000000..05bac1e2c5 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsJsxExpression_test.go @@ -0,0 +1,42 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsJsxExpression(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.tsx +// @jsx: react +declare namespace JSX { + interface IntrinsicElements { + div: { a: string, b: string } + } +} +const value = "test"; +
` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "value", + Kind: ptrTo(lsproto.CompletionItemKindVariable), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsLiteralDirectlyInArgumentWithNullableConstraint_test.go b/internal/fourslash/tests/gen/completionsLiteralDirectlyInArgumentWithNullableConstraint_test.go new file mode 100644 index 0000000000..ef683efdac --- /dev/null +++ b/internal/fourslash/tests/gen/completionsLiteralDirectlyInArgumentWithNullableConstraint_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsLiteralDirectlyInArgumentWithNullableConstraint(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true + +declare function func< + const T extends 'a' | 'b' | undefined = undefined, +>(arg?: T): string; + +func('/*1*/');` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"1"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + "a", + "b", + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsLiteralDirectlyInRestConstrainedToArrayType_test.go b/internal/fourslash/tests/gen/completionsLiteralDirectlyInRestConstrainedToArrayType_test.go new file mode 100644 index 0000000000..84442683c6 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsLiteralDirectlyInRestConstrainedToArrayType_test.go @@ -0,0 +1,35 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsLiteralDirectlyInRestConstrainedToArrayType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true + +function fn(...values: T): T { return values; } + +const value1 = fn('/*1*/'); +const value2 = fn('value1', '/*2*/');` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"1", "2"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + "value1", + "value2", + "value3", + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsLiteralDirectlyInRestConstrainedToTupleType_test.go b/internal/fourslash/tests/gen/completionsLiteralDirectlyInRestConstrainedToTupleType_test.go new file mode 100644 index 0000000000..e80ec48271 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsLiteralDirectlyInRestConstrainedToTupleType_test.go @@ -0,0 +1,41 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsLiteralDirectlyInRestConstrainedToTupleType(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true + +interface Func { + ( + ...args: + | [key: Key, options?: any] + | [key: Key, defaultValue: string, options?: any] + ): string; +} + +declare const func: Func; + +func("/*1*/");` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"1"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + "a", + "b", + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsOverridingMethod10_test.go b/internal/fourslash/tests/gen/completionsOverridingMethod10_test.go new file mode 100644 index 0000000000..7986ea06bb --- /dev/null +++ b/internal/fourslash/tests/gen/completionsOverridingMethod10_test.go @@ -0,0 +1,57 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsOverridingMethod10(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: a.ts +// @newline: LF +interface Base { + a: string; + b(a: string): void; + c(a: string): string; + c(a: number): number; +} +class Sub implements Base { + /*a*/ +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "a", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "a", + InsertText: ptrTo("a: string;"), + FilterText: ptrTo("a"), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "b", + InsertText: ptrTo("b(a: string): void {\n}"), + FilterText: ptrTo("b"), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "c", + InsertText: ptrTo("c(a: string): string;\nc(a: number): number;\nc(a: unknown): string | number {\n}"), + FilterText: ptrTo("c"), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsOverridingMethod11_test.go b/internal/fourslash/tests/gen/completionsOverridingMethod11_test.go new file mode 100644 index 0000000000..b24ee8ff8f --- /dev/null +++ b/internal/fourslash/tests/gen/completionsOverridingMethod11_test.go @@ -0,0 +1,64 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsOverridingMethod11(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: a.ts +// @newline: LF +function foo() { + const a = 1 + const b = 2 + foo() + return a + b +} + +interface Base { + a: string + b(a: string): void + c(a: string): string + c(a: number): number +} +class Sub implements Base { + /*a*/ +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "a", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "a", + InsertText: ptrTo("a: string"), + FilterText: ptrTo("a"), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "b", + InsertText: ptrTo("b(a: string): void {\n}"), + FilterText: ptrTo("b"), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "c", + InsertText: ptrTo("c(a: string): string\nc(a: number): number\nc(a: unknown): string | number {\n}"), + FilterText: ptrTo("c"), + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag1_test.go b/internal/fourslash/tests/gen/completionsWithDeprecatedTag1_test.go new file mode 100644 index 0000000000..ad90315927 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsWithDeprecatedTag1_test.go @@ -0,0 +1,117 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsWithDeprecatedTag1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true +// @filename: /foobar.ts + /** @deprecated */ + export function foobar() {} +// @filename: /foo.ts + import { foobar/*4*/ } from "./foobar"; + + /** @deprecated */ + interface Foo { + /** @deprecated */ + bar(): void + /** @deprecated */ + prop: number + } + declare const foo: Foo; + declare const foooo: Fo/*1*/; + foo.ba/*2*/; + foo.pro/*3*/; + + fooba/*5*/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "Foo", + Kind: ptrTo(lsproto.CompletionItemKindInterface), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "bar", + Kind: ptrTo(lsproto.CompletionItemKindMethod), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "prop", + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "foobar", + Kind: ptrTo(lsproto.CompletionItemKindFunction), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) + f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "foobar", + Kind: ptrTo(lsproto.CompletionItemKindVariable), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag2_test.go b/internal/fourslash/tests/gen/completionsWithDeprecatedTag2_test.go new file mode 100644 index 0000000000..a608c319ff --- /dev/null +++ b/internal/fourslash/tests/gen/completionsWithDeprecatedTag2_test.go @@ -0,0 +1,39 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsWithDeprecatedTag2(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `/** @deprecated foo */ +declare function foo(); +/** @deprecated foo */ +declare function foo(x); + +foo/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "foo", + Kind: ptrTo(lsproto.CompletionItemKindFunction), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag4_test.go b/internal/fourslash/tests/gen/completionsWithDeprecatedTag4_test.go new file mode 100644 index 0000000000..121c0ba45f --- /dev/null +++ b/internal/fourslash/tests/gen/completionsWithDeprecatedTag4_test.go @@ -0,0 +1,45 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsWithDeprecatedTag4(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @noLib: true +f({ + a/**/ + xyz: ` + "`" + `` + "`" + `, +}); +declare function f(options: { + /** @deprecated abc */ + abc?: number, + xyz?: string +}): void;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "abc?", + InsertText: ptrTo("abc"), + FilterText: ptrTo("abc"), + Kind: ptrTo(lsproto.CompletionItemKindField), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextOptionalMember))), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag5_test.go b/internal/fourslash/tests/gen/completionsWithDeprecatedTag5_test.go new file mode 100644 index 0000000000..eaf071c659 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsWithDeprecatedTag5_test.go @@ -0,0 +1,43 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsWithDeprecatedTag5(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + /** @deprecated m */ + static m() {} +} +Foo./**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: completionFunctionMembersPlus( + []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "prototype", + SortText: ptrTo(string(ls.SortTextLocationPriority)), + }, + &lsproto.CompletionItem{ + Label: "m", + Kind: ptrTo(lsproto.CompletionItemKindMethod), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocalDeclarationPriority))), + }, + }), + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag6_test.go b/internal/fourslash/tests/gen/completionsWithDeprecatedTag6_test.go new file mode 100644 index 0000000000..d95b57597c --- /dev/null +++ b/internal/fourslash/tests/gen/completionsWithDeprecatedTag6_test.go @@ -0,0 +1,38 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsWithDeprecatedTag6(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module Foo { + /** @deprecated foo */ + export var foo: number; +} +Foo./**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "foo", + Kind: ptrTo(lsproto.CompletionItemKindVariable), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextLocationPriority))), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag7_test.go b/internal/fourslash/tests/gen/completionsWithDeprecatedTag7_test.go new file mode 100644 index 0000000000..5d0af06581 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsWithDeprecatedTag7_test.go @@ -0,0 +1,45 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsWithDeprecatedTag7(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @strict: true +interface I { + /** @deprecated a */ + a: number; +} +const foo = { + a: 1 +} +const i: I = { + ...foo, + /**/ +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "a", + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextMemberDeclaredBySpreadAssignment))), + Kind: ptrTo(lsproto.CompletionItemKindField), + }, + }, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionsWithDeprecatedTag9_test.go b/internal/fourslash/tests/gen/completionsWithDeprecatedTag9_test.go new file mode 100644 index 0000000000..026ba19397 --- /dev/null +++ b/internal/fourslash/tests/gen/completionsWithDeprecatedTag9_test.go @@ -0,0 +1,46 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/ls" + "github.com/microsoft/typescript-go/internal/lsp/lsproto" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionsWithDeprecatedTag9(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @lib: dom +// @allowJs: true +// @Filename: globals.d.ts +/** @deprecated foo */ +declare var foo: string; +// @Filename: index.ts +class Foo { + foo: number; + m() { + foo/**/ + } +}` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{ + &lsproto.CompletionItem{ + Label: "foo", + Kind: ptrTo(lsproto.CompletionItemKindVariable), + SortText: ptrTo(string(ls.DeprecateSortText(ls.SortTextGlobalsOrKeywords))), + }, + }, + }, + }) + f.VerifyCompletions(t, nil, nil) +}