diff --git a/internal/fourslash/_scripts/convertFourslash.mts b/internal/fourslash/_scripts/convertFourslash.mts index e099c59f0e..5d01d5fffa 100644 --- a/internal/fourslash/_scripts/convertFourslash.mts +++ b/internal/fourslash/_scripts/convertFourslash.mts @@ -304,6 +304,7 @@ function parseVerifyCompletionArg(arg: ts.Expression): VerifyCompletionsCmd | un break; case "exact": case "includes": + case "unsorted": if (init.getText() === "undefined") { return { kind: "verifyCompletions", @@ -385,9 +386,12 @@ function parseVerifyCompletionArg(arg: ts.Expression): VerifyCompletionsCmd | un if (propName === "includes") { (goArgs ??= {}).includes = expected; } - else { + else if (propName === "exact") { (goArgs ??= {}).exact = expected; } + else { + (goArgs ??= {}).unsorted = expected; + } break; case "excludes": let excludes = "[]string{"; @@ -659,6 +663,7 @@ interface VerifyCompletionsArgs { includes?: string; excludes?: string; exact?: string; + unsorted?: string; } interface GoToMarkerCmd { @@ -680,6 +685,7 @@ function generateVerifyCompletions({ marker, args, isNewIdentifierLocation }: Ve if (args.includes) expected.push(`Includes: ${args.includes},`); if (args.excludes) expected.push(`Excludes: ${args.excludes},`); if (args.exact) expected.push(`Exact: ${args.exact},`); + if (args.unsorted) expected.push(`Unsorted: ${args.unsorted},`); // !!! isIncomplete const commitCharacters = isNewIdentifierLocation ? "[]string{}" : "defaultCommitCharacters"; expectedList = `&fourslash.CompletionsExpectedList{ diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index 6f2433c745..583f137a5d 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -63,6 +63,7 @@ TestCompletionListAndMemberListOnCommentedWhiteSpace TestCompletionListAtInvalidLocations TestCompletionListBuilderLocations_VariableDeclarations TestCompletionListCladule +TestCompletionListClassMembers TestCompletionListForExportEquals TestCompletionListForTransitivelyExportedMembers01 TestCompletionListForTransitivelyExportedMembers04 @@ -94,6 +95,10 @@ TestCompletionListInUnclosedTemplate01 TestCompletionListInUnclosedTemplate02 TestCompletionListInvalidMemberNames2 TestCompletionListInvalidMemberNames_withExistingIdentifier +TestCompletionListOnAliases2 +TestCompletionListPrivateNames +TestCompletionListPrivateNamesAccessors +TestCompletionListPrivateNamesMethods TestCompletionListStaticMembers TestCompletionListStaticProtectedMembers TestCompletionListStaticProtectedMembers2 diff --git a/internal/fourslash/fourslash.go b/internal/fourslash/fourslash.go index d9c5b9b9ff..773a4d7486 100644 --- a/internal/fourslash/fourslash.go +++ b/internal/fourslash/fourslash.go @@ -3,6 +3,8 @@ package fourslash import ( "fmt" "io" + "maps" + "slices" "strings" "testing" "unicode" @@ -392,11 +394,11 @@ type CompletionsExpectedItemDefaults struct { // *lsproto.CompletionItem | string type CompletionsExpectedItem = any -// !!! unsorted completions type CompletionsExpectedItems struct { Includes []CompletionsExpectedItem Excludes []string Exact []CompletionsExpectedItem + Unsorted []CompletionsExpectedItem } // string | *Marker | []string | []*Marker @@ -520,6 +522,9 @@ func verifyCompletionsItems(t *testing.T, prefix string, actual []*lsproto.Compl if expected.Excludes != nil { t.Fatal(prefix + "Expected exact completion list but also specified 'excludes'.") } + if expected.Unsorted != nil { + t.Fatal(prefix + "Expected exact completion list but also specified 'unsorted'.") + } if len(actual) != len(expected.Exact) { t.Fatalf(prefix+"Expected %d exact completion items but got %d: %s", len(expected.Exact), len(actual), cmp.Diff(actual, expected.Exact)) } @@ -532,6 +537,38 @@ func verifyCompletionsItems(t *testing.T, prefix string, actual []*lsproto.Compl for _, item := range actual { nameToActualItem[item.Label] = item } + if expected.Unsorted != nil { + if expected.Includes != nil { + t.Fatal(prefix + "Expected unsorted completion list but also specified 'includes'.") + } + if expected.Excludes != nil { + t.Fatal(prefix + "Expected unsorted completion list but also specified 'excludes'.") + } + for _, item := range expected.Unsorted { + switch item := item.(type) { + case string: + _, ok := nameToActualItem[item] + if !ok { + t.Fatalf("%sLabel '%s' not found in actual items. Actual items: %s", prefix, item, cmp.Diff(actual, nil)) + } + delete(nameToActualItem, item) + case *lsproto.CompletionItem: + actualItem, ok := nameToActualItem[item.Label] + if !ok { + t.Fatalf("%sLabel '%s' not found in actual items. Actual items: %s", prefix, item.Label, cmp.Diff(actual, nil)) + } + delete(nameToActualItem, item.Label) + verifyCompletionItem(t, prefix+"Includes completion item mismatch for label "+item.Label, actualItem, item) + default: + t.Fatalf("%sExpected completion item to be a string or *lsproto.CompletionItem, got %T", prefix, item) + } + } + if len(expected.Unsorted) != len(actual) { + unmatched := slices.Collect(maps.Keys(nameToActualItem)) + t.Fatalf("%sAdditional completions found but not included in 'unsorted': %s", prefix, strings.Join(unmatched, "\n")) + } + return + } if expected.Includes != nil { for _, item := range expected.Includes { switch item := item.(type) { diff --git a/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go b/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go new file mode 100644 index 0000000000..0d84561e68 --- /dev/null +++ b/internal/fourslash/tests/gen/completionForStringLiteralRelativeImport5_test.go @@ -0,0 +1,64 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionForStringLiteralRelativeImport5(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @rootDirs: /repo/src1,/repo/src2/,/repo/generated1,/repo/generated2/ +// @Filename: /dir/secret_file.ts +/*secret_file*/ +// @Filename: /repo/src1/dir/test1.ts +import * as foo1 from ".//*import_as1*/ +import foo2 = require(".//*import_equals1*/ +var foo3 = require(".//*require1*/ +// @Filename: /repo/src2/dir/test2.ts +import * as foo1 from "..//*import_as2*/ +import foo2 = require("..//*import_equals2*/ +var foo3 = require("..//*require2*/ +// @Filename: /repo/src2/index.ts +import * as foo1 from ".//*import_as3*/ +import foo2 = require(".//*import_equals3*/ +var foo3 = require(".//*require3*/ +// @Filename: /repo/generated1/dir/f1.ts +/*f1*/ +// @Filename: /repo/generated2/dir/f2.ts +/*f2*/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"import_as1", "import_equals1", "require1"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"f1", "f2", "test2"}, + }, + }) + f.VerifyCompletions(t, []string{"import_as2", "import_equals2", "require2"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"dir", "index"}, + }, + }) + f.VerifyCompletions(t, []string{"import_as3", "import_equals3", "require3"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"dir"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListClassMembers_test.go b/internal/fourslash/tests/gen/completionListClassMembers_test.go new file mode 100644 index 0000000000..8ce7f50243 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListClassMembers_test.go @@ -0,0 +1,78 @@ +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 TestCompletionListClassMembers(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Class { + private privateInstanceMethod() { } + public publicInstanceMethod() { } + + private privateProperty = 1; + public publicProperty = 1; + + private static privateStaticProperty = 1; + public static publicStaticProperty = 1; + + private static privateStaticMethod() { } + public static publicStaticMethod() { + Class./*staticsInsideClassScope*/publicStaticMethod(); + var c = new Class(); + c./*instanceMembersInsideClassScope*/privateProperty; + } +} + +Class./*staticsOutsideClassScope*/publicStaticMethod(); +var c = new Class(); +c./*instanceMembersOutsideClassScope*/privateProperty;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "staticsInsideClassScope", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: completionFunctionMembersPlus([]fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "privateStaticMethod"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "privateStaticProperty"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "publicStaticMethod"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "publicStaticProperty"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocationPriority)), Label: "prototype"}}), + }, + }) + f.VerifyCompletions(t, "instanceMembersInsideClassScope", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"privateInstanceMethod", "publicInstanceMethod", "privateProperty", "publicProperty"}, + }, + }) + f.VerifyCompletions(t, "staticsOutsideClassScope", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: completionFunctionMembersPlus([]fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "publicStaticMethod"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "publicStaticProperty"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocationPriority)), Label: "prototype"}}), + }, + }) + f.VerifyCompletions(t, "instanceMembersOutsideClassScope", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"publicInstanceMethod", "publicProperty"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListEnumMembers_test.go b/internal/fourslash/tests/gen/completionListEnumMembers_test.go new file mode 100644 index 0000000000..aa8941d103 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListEnumMembers_test.go @@ -0,0 +1,43 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListEnumMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `enum Foo { + bar, + baz +} + +var v = Foo./*valueReference*/ba; +var t :Foo./*typeReference*/ba; +Foo.bar./*enumValueReference*/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"valueReference", "typeReference"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"bar", "baz"}, + }, + }) + f.VerifyCompletions(t, "enumValueReference", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"toString", "toFixed", "toExponential", "toPrecision", "valueOf", "toLocaleString"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go b/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go new file mode 100644 index 0000000000..a92f598b99 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInObjectBindingPattern15_test.go @@ -0,0 +1,70 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInObjectBindingPattern15(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + private xxx1 = 1; + protected xxx2 = 2; + public xxx3 = 3; + private static xxx4 = 4; + protected static xxx5 = 5; + public static xxx6 = 6; + foo() { + const { /*1*/ } = this; + const { /*2*/ } = Foo; + } +} + +const { /*3*/ } = new Foo(); +const { /*4*/ } = Foo;` + 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{ + Unsorted: []fourslash.CompletionsExpectedItem{"xxx1", "xxx2", "xxx3", "foo"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"prototype", "xxx4", "xxx5", "xxx6"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"xxx3", "foo"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"prototype", "xxx6"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_test.go b/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_test.go new file mode 100644 index 0000000000..66ced94e46 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInTypeLiteralInTypeParameter1_test.go @@ -0,0 +1,40 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInTypeLiteralInTypeParameter1(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface Foo { + one: string; + two: number; + 333: symbol; + '4four': boolean; + '5 five': object; + number: string; + Object: number; +} + +interface Bar { + foo: T; +} + +var foobar: Bar<{/**/` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"one", "two", "\"333\"", "\"4four\"", "\"5 five\"", "number", "Object"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go b/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go new file mode 100644 index 0000000000..afe0a1e5bb --- /dev/null +++ b/internal/fourslash/tests/gen/completionListInstanceProtectedMembers_test.go @@ -0,0 +1,63 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListInstanceProtectedMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Base { + private privateMethod() { } + private privateProperty; + + protected protectedMethod() { } + protected protectedProperty; + + public publicMethod() { } + public publicProperty; + + protected protectedOverriddenMethod() { } + protected protectedOverriddenProperty; + + test() { + this./*1*/; + + var b: Base; + var c: C1; + + b./*2*/; + c./*3*/; + } +} + +class C1 extends Base { + protected protectedOverriddenMethod() { } + protected protectedOverriddenProperty; +}` + 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{ + Unsorted: []fourslash.CompletionsExpectedItem{"privateMethod", "privateProperty", "protectedMethod", "protectedProperty", "publicMethod", "publicProperty", "protectedOverriddenMethod", "protectedOverriddenProperty", "test"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"privateMethod", "privateProperty", "protectedMethod", "protectedProperty", "publicMethod", "publicProperty", "test"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListModuleMembers_test.go b/internal/fourslash/tests/gen/completionListModuleMembers_test.go new file mode 100644 index 0000000000..616665fce4 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListModuleMembers_test.go @@ -0,0 +1,55 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListModuleMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` module Module { + var innerVariable = 1; + function innerFunction() { } + class innerClass { } + module innerModule { } + interface innerInterface {} + export var exportedVariable = 1; + export function exportedFunction() { } + export class exportedClass { } + export module exportedModule { export var exportedInnerModuleVariable = 1; } + export interface exportedInterface {} + } + +Module./*ValueReference*/; + +var x : Module./*TypeReference*/ + +class TestClass extends Module./*TypeReferenceInExtendsList*/ { } + +interface TestInterface implements Module./*TypeReferenceInImplementsList*/ { }` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"ValueReference", "TypeReferenceInExtendsList"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"exportedFunction", "exportedVariable", "exportedClass", "exportedModule"}, + }, + }) + f.VerifyCompletions(t, []string{"TypeReference", "TypeReferenceInImplementsList"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"exportedClass", "exportedInterface"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go b/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go new file mode 100644 index 0000000000..0c5dd0d3bb --- /dev/null +++ b/internal/fourslash/tests/gen/completionListOfSplitInterface_test.go @@ -0,0 +1,66 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListOfSplitInterface(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `interface A { + a: number; +} +interface I extends A { + i1: number; +} +interface I1 extends A { + i11: number; +} +interface B { + b: number; +} +interface B1 { + b1: number; +} +interface I extends B { + i2: number; +} +interface I1 extends B, B1 { + i12: number; +} +interface C { + c: number; +} +interface I extends C { + i3: number; +} +var ci: I; +ci./*1*/b; +var ci1: I1; +ci1./*2*/b;` + 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{ + Unsorted: []fourslash.CompletionsExpectedItem{"i1", "i2", "i3", "a", "b", "c"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"i11", "i12", "a", "b", "b1"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListOnAliases2_test.go b/internal/fourslash/tests/gen/completionListOnAliases2_test.go new file mode 100644 index 0000000000..f3938d9391 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListOnAliases2_test.go @@ -0,0 +1,120 @@ +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 TestCompletionListOnAliases2(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `module M { + export interface I { } + export class C { + static property; + } + export enum E { + value = 0 + } + export module N { + export var v; + } + export var V = 0; + export function F() { } + export import A = M; +} + +import m = M; +import c = M.C; +import e = M.E; +import n = M.N; +import v = M.V; +import f = M.F; +import a = M.A; + +m./*1*/; +var tmp: m./*1Type*/; +c./*2*/; +e./*3*/; +n./*4*/; +v./*5*/; +f./*6*/; +a./*7*/; +var tmp2: a./*7Type*/;` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"1", "7"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"F", "C", "E", "N", "V", "A"}, + }, + }) + f.VerifyCompletions(t, []string{"1Type", "7Type"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"I", "C", "E", "A"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: completionFunctionMembersPlus([]fourslash.CompletionsExpectedItem{&lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocalDeclarationPriority)), Label: "property"}, &lsproto.CompletionItem{SortText: ptrTo(string(ls.SortTextLocationPriority)), Label: "prototype"}}), + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"value"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"v"}, + }, + }) + f.VerifyCompletions(t, "5", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"toFixed"}, + }, + }) + f.VerifyCompletions(t, "6", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"call"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go b/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go new file mode 100644 index 0000000000..104f295b76 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNamesAccessors_test.go @@ -0,0 +1,83 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNamesAccessors(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class Foo { + get #x() { return 1 }; + set #x(value: number) { }; + y() {}; + } + class Bar extends Foo { + get #z() { return 1 }; + set #z(value: number) { }; + t() {}; + l; + constructor() { + this./*1*/ + class Baz { + get #z() { return 1 }; + set #z(value: number) { }; + get #u() { return 1 }; + set #u(value: number) { }; + v() {}; + k; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } + } + + new Foo()./*4*/` + 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{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "l", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v", "k"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "l", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go b/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go new file mode 100644 index 0000000000..a52f1bec69 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNamesMethods_test.go @@ -0,0 +1,77 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNamesMethods(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class Foo { + #x() {}; + y() {}; + } + class Bar extends Foo { + #z() {}; + t() {}; + constructor() { + this./*1*/ + class Baz { + #z() {}; + #u() {}; + v() {}; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } + } + + new Foo()./*4*/` + 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{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListPrivateNames_test.go b/internal/fourslash/tests/gen/completionListPrivateNames_test.go new file mode 100644 index 0000000000..0f23424e47 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListPrivateNames_test.go @@ -0,0 +1,78 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListPrivateNames(t *testing.T) { + t.Parallel() + t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Foo { + #x; + y; +} + +class Bar extends Foo { + #z; + t; + constructor() { + this./*1*/ + class Baz { + #z; + #u; + v; + constructor() { + this./*2*/ + new Bar()./*3*/ + } + } + } +} + +new Foo()./*4*/` + 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{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "#u", "v"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"#z", "t", "y"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Exact: []fourslash.CompletionsExpectedItem{"y"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/completionListProtectedMembers_test.go b/internal/fourslash/tests/gen/completionListProtectedMembers_test.go new file mode 100644 index 0000000000..be5d12d598 --- /dev/null +++ b/internal/fourslash/tests/gen/completionListProtectedMembers_test.go @@ -0,0 +1,73 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestCompletionListProtectedMembers(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `class Base { + protected y; + constructor(protected x) {} + method() { this./*1*/; } +} +class D1 extends Base { + protected z; + method1() { this./*2*/; } +} +class D2 extends Base { + method2() { this./*3*/; } +} +class D3 extends D1 { + method2() { this./*4*/; } +} +var b: Base; +f./*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{ + Unsorted: []fourslash.CompletionsExpectedItem{"y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"z", "method1", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"method2", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "4", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"method2", "z", "method1", "y", "x", "method"}, + }, + }) + f.VerifyCompletions(t, "5", nil) +} diff --git a/internal/fourslash/tests/gen/genericTypeAliasIntersectionCompletions_test.go b/internal/fourslash/tests/gen/genericTypeAliasIntersectionCompletions_test.go new file mode 100644 index 0000000000..b4bd0a0136 --- /dev/null +++ b/internal/fourslash/tests/gen/genericTypeAliasIntersectionCompletions_test.go @@ -0,0 +1,52 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestGenericTypeAliasIntersectionCompletions(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` type MixinCtor = new () => A & B & { constructor: MixinCtor }; + function merge(a: { prototype: A }, b: { prototype: B }): MixinCtor { + let merged = function() { } + Object.assign(merged.prototype, a.prototype, b.prototype); + return >merged; + } + + class TreeNode { + value: any; + } + + abstract class LeftSideNode extends TreeNode { + abstract right(): TreeNode; + left(): TreeNode { + return null; + } + } + + abstract class RightSideNode extends TreeNode { + abstract left(): TreeNode; + right(): TreeNode { + return null; + }; + } + + var obj = new (merge(LeftSideNode, RightSideNode))(); + obj./**/` + 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{"right", "left", "value", "constructor"}, + }, + }) +} diff --git a/internal/fourslash/tests/gen/thisPredicateFunctionCompletions03_test.go b/internal/fourslash/tests/gen/thisPredicateFunctionCompletions03_test.go new file mode 100644 index 0000000000..816d2af6cb --- /dev/null +++ b/internal/fourslash/tests/gen/thisPredicateFunctionCompletions03_test.go @@ -0,0 +1,78 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestThisPredicateFunctionCompletions03(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` class RoyalGuard { + isLeader(): this is LeadGuard { + return this instanceof LeadGuard; + } + isFollower(): this is FollowerGuard { + return this instanceof FollowerGuard; + } + } + + class LeadGuard extends RoyalGuard { + lead(): void {}; + } + + class FollowerGuard extends RoyalGuard { + follow(): void {}; + } + + let a: RoyalGuard = new FollowerGuard(); + if (a.is/*1*/Leader()) { + a./*2*/; + } + else if (a.is/*3*/Follower()) { + a./*4*/; + } + + interface GuardInterface { + isLeader(): this is LeadGuard; + isFollower(): this is FollowerGuard; + } + + let b: GuardInterface; + if (b.is/*5*/Leader()) { + b./*6*/; + } + else if (b.is/*7*/Follower()) { + b./*8*/; + } + + let leader/*13*/Status = a.isLeader(); + function isLeaderGuard(g: RoyalGuard) { + return g.isLeader(); + } + let checked/*14*/LeaderStatus = isLeader/*15*/Guard(a);` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyCompletions(t, []string{"2", "6"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"lead", "isLeader", "isFollower"}, + }, + }) + f.VerifyCompletions(t, []string{"4", "8"}, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &defaultCommitCharacters, + EditRange: ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Unsorted: []fourslash.CompletionsExpectedItem{"follow", "isLeader", "isFollower"}, + }, + }) +}