From 26647d4ecf6b7f9c0b0072ecaf24e1436a955a3b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:15:53 -0700 Subject: [PATCH 01/20] Fixed harness. --- src/harness/fourslash.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 95a320ac052..5d488259a36 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -620,7 +620,7 @@ module FourSlash { this.scenarioActions.push(''); var members = this.getMemberListAtCaret(); - if (members.entries.filter(e => e.name === symbol).length !== 0) { + if (members && members.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError('Member list did contain ' + symbol); } } @@ -691,7 +691,12 @@ module FourSlash { public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) { var completions = this.getCompletionListAtCaret(); - this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + if (completions) { + this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + } + else { + this.raiseError(`No completions at position '${ this.currentCaretPosition }' when looking for '${ symbol }'.`); + } } public verifyCompletionListDoesNotContain(symbol: string) { @@ -699,7 +704,7 @@ module FourSlash { this.scenarioActions.push(''); var completions = this.getCompletionListAtCaret(); - if (completions && completions.entries && completions.entries.filter(e => e.name === symbol).length !== 0) { + if (completions && completions.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError('Completion list did contain ' + symbol); } } From 88adb8fbb4a8f13f845adcb8f319e04993ca68da Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:02:18 -0700 Subject: [PATCH 02/20] Added tests for completions before a new scope. Tests for #2292. --- .../cases/fourslash/completionListBeforeNewScope01.ts | 11 +++++++++++ .../cases/fourslash/completionListBeforeNewScope02.ts | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/cases/fourslash/completionListBeforeNewScope01.ts create mode 100644 tests/cases/fourslash/completionListBeforeNewScope02.ts diff --git a/tests/cases/fourslash/completionListBeforeNewScope01.ts b/tests/cases/fourslash/completionListBeforeNewScope01.ts new file mode 100644 index 00000000000..79159744b81 --- /dev/null +++ b/tests/cases/fourslash/completionListBeforeNewScope01.ts @@ -0,0 +1,11 @@ +/// + +////p/*1*/ +//// +////function fun(param) { +//// let party = Math.random() < 0.99; +////} + +goTo.marker("1"); +verify.not.completionListContains("param"); +verify.not.completionListContains("party"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListBeforeNewScope02.ts b/tests/cases/fourslash/completionListBeforeNewScope02.ts new file mode 100644 index 00000000000..9df03ec10a4 --- /dev/null +++ b/tests/cases/fourslash/completionListBeforeNewScope02.ts @@ -0,0 +1,10 @@ +/// + +////a +//// +////{ +//// let aaaaaa = 10; +////} + +goTo.marker("1"); +verify.not.completionListContains("aaaaa"); \ No newline at end of file From 693da9a6df1b12fce9ba4b66bd49e4359b93eab0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:05:34 -0700 Subject: [PATCH 03/20] Added tests. --- .../completionListInClosedFunction01.ts | 12 +++++++++ .../completionListInClosedFunction02.ts | 18 +++++++++++++ .../completionListInClosedFunction03.ts | 19 ++++++++++++++ .../completionListInClosedFunction04.ts | 19 ++++++++++++++ .../completionListInClosedFunction05.ts | 21 ++++++++++++++++ .../completionListInClosedFunction06.ts | 14 +++++++++++ .../completionListInClosedFunction07.ts | 25 +++++++++++++++++++ ...tInClosedObjectTypeLiteralInSignature01.ts | 16 ++++++++++++ ...tInClosedObjectTypeLiteralInSignature02.ts | 16 ++++++++++++ ...tInClosedObjectTypeLiteralInSignature03.ts | 16 ++++++++++++ ...tInClosedObjectTypeLiteralInSignature04.ts | 16 ++++++++++++ .../completionListInUnclosedFunction01.ts | 12 +++++++++ .../completionListInUnclosedFunction02.ts | 16 ++++++++++++ .../completionListInUnclosedFunction03.ts | 17 +++++++++++++ .../completionListInUnclosedFunction04.ts | 16 ++++++++++++ .../completionListInUnclosedFunction05.ts | 17 +++++++++++++ .../completionListInUnclosedFunction06.ts | 17 +++++++++++++ .../completionListInUnclosedFunction07.ts | 17 +++++++++++++ .../completionListInUnclosedFunction08.ts | 19 ++++++++++++++ .../completionListInUnclosedFunction09.ts | 20 +++++++++++++++ .../completionListInUnclosedFunction10.ts | 12 +++++++++ .../completionListInUnclosedFunction11.ts | 12 +++++++++ .../completionListInUnclosedFunction12.ts | 13 ++++++++++ .../completionListInUnclosedFunction13.ts | 14 +++++++++++ .../completionListInUnclosedFunction14.ts | 25 +++++++++++++++++++ .../completionListInUnclosedFunction15.ts | 24 ++++++++++++++++++ .../completionListInUnclosedFunction16.ts | 23 +++++++++++++++++ .../completionListInUnclosedFunction17.ts | 23 +++++++++++++++++ .../completionListInUnclosedFunction18.ts | 24 ++++++++++++++++++ .../completionListInUnclosedFunction19.ts | 23 +++++++++++++++++ ...nUnclosedObjectTypeLiteralInSignature01.ts | 16 ++++++++++++ ...nUnclosedObjectTypeLiteralInSignature02.ts | 16 ++++++++++++ ...nUnclosedObjectTypeLiteralInSignature03.ts | 16 ++++++++++++ ...nUnclosedObjectTypeLiteralInSignature04.ts | 16 ++++++++++++ 34 files changed, 600 insertions(+) create mode 100644 tests/cases/fourslash/completionListInClosedFunction01.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction02.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction03.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction04.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction05.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction06.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction07.ts create mode 100644 tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts create mode 100644 tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts create mode 100644 tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts create mode 100644 tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction03.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction04.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction05.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction06.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction07.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction08.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction09.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction10.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction11.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction12.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction13.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction14.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction15.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction16.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction17.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction18.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction19.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts diff --git a/tests/cases/fourslash/completionListInClosedFunction01.ts b/tests/cases/fourslash/completionListInClosedFunction01.ts new file mode 100644 index 00000000000..7c9c2a20139 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction01.ts @@ -0,0 +1,12 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction02.ts b/tests/cases/fourslash/completionListInClosedFunction02.ts new file mode 100644 index 00000000000..a2ae8a9da83 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction02.ts @@ -0,0 +1,18 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof /*1*/) { +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction03.ts b/tests/cases/fourslash/completionListInClosedFunction03.ts new file mode 100644 index 00000000000..b1a10a4a4b2 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction03.ts @@ -0,0 +1,19 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof x = /*1*/) { +//// +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction04.ts b/tests/cases/fourslash/completionListInClosedFunction04.ts new file mode 100644 index 00000000000..fcc7d070eb7 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction04.ts @@ -0,0 +1,19 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = /*1*/, c: typeof x = "hello") { +//// +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // definitely questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction05.ts b/tests/cases/fourslash/completionListInClosedFunction05.ts new file mode 100644 index 00000000000..7ec3985caf0 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction05.ts @@ -0,0 +1,21 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = /*1*/ +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction06.ts b/tests/cases/fourslash/completionListInClosedFunction06.ts new file mode 100644 index 00000000000..f1aed3ad1a4 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction06.ts @@ -0,0 +1,14 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (x: /*1*/); +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction07.ts b/tests/cases/fourslash/completionListInClosedFunction07.ts new file mode 100644 index 00000000000..13b9f5787de --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction07.ts @@ -0,0 +1,25 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => /*1*/; +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts new file mode 100644 index 00000000000..5e7d8b30484 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: T/*1*/ } + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts new file mode 100644 index 00000000000..ee0e1e8b90c --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: TStr/*1*/ } + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts new file mode 100644 index 00000000000..cdc4e9effff --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: TString/*1*/ } + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts new file mode 100644 index 00000000000..a45d98ad4df --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { /*1*/ } + +goTo.marker("1"); + +verify.not.memberListContains("I"); +verify.not.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedFunction01.ts b/tests/cases/fourslash/completionListInUnclosedFunction01.ts new file mode 100644 index 00000000000..4d33d1220f7 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction01.ts @@ -0,0 +1,12 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// /*1*/ +//// + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction02.ts b/tests/cases/fourslash/completionListInUnclosedFunction02.ts new file mode 100644 index 00000000000..c0c79e94433 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction02.ts @@ -0,0 +1,16 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction03.ts b/tests/cases/fourslash/completionListInUnclosedFunction03.ts new file mode 100644 index 00000000000..d8b3a0a132f --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction03.ts @@ -0,0 +1,17 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction04.ts b/tests/cases/fourslash/completionListInUnclosedFunction04.ts new file mode 100644 index 00000000000..e56978732c2 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction04.ts @@ -0,0 +1,16 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof x = /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction05.ts b/tests/cases/fourslash/completionListInUnclosedFunction05.ts new file mode 100644 index 00000000000..748a334f860 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction05.ts @@ -0,0 +1,17 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof x = /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction06.ts b/tests/cases/fourslash/completionListInUnclosedFunction06.ts new file mode 100644 index 00000000000..3ceaff78039 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction06.ts @@ -0,0 +1,17 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = /*1*/, c: typeof x = "hello" +//// + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // definitely questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction07.ts b/tests/cases/fourslash/completionListInUnclosedFunction07.ts new file mode 100644 index 00000000000..6968a878a77 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction07.ts @@ -0,0 +1,17 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = /*1*/, c: typeof x = "hello" +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // definitely questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction08.ts b/tests/cases/fourslash/completionListInUnclosedFunction08.ts new file mode 100644 index 00000000000..5e8b15941c1 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction08.ts @@ -0,0 +1,19 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction09.ts b/tests/cases/fourslash/completionListInUnclosedFunction09.ts new file mode 100644 index 00000000000..0171ef96342 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction09.ts @@ -0,0 +1,20 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction10.ts b/tests/cases/fourslash/completionListInUnclosedFunction10.ts new file mode 100644 index 00000000000..1d0162b600b --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction10.ts @@ -0,0 +1,12 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: /*1*/ + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction11.ts b/tests/cases/fourslash/completionListInUnclosedFunction11.ts new file mode 100644 index 00000000000..1d0162b600b --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction11.ts @@ -0,0 +1,12 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: /*1*/ + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction12.ts b/tests/cases/fourslash/completionListInUnclosedFunction12.ts new file mode 100644 index 00000000000..b0e36b2fb8a --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction12.ts @@ -0,0 +1,13 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction13.ts b/tests/cases/fourslash/completionListInUnclosedFunction13.ts new file mode 100644 index 00000000000..8e1334941ad --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction13.ts @@ -0,0 +1,14 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: /*1*/ +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction14.ts b/tests/cases/fourslash/completionListInUnclosedFunction14.ts new file mode 100644 index 00000000000..412fcd86670 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction14.ts @@ -0,0 +1,25 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => /*1*/ +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction15.ts b/tests/cases/fourslash/completionListInUnclosedFunction15.ts new file mode 100644 index 00000000000..73a59795396 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction15.ts @@ -0,0 +1,24 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction16.ts b/tests/cases/fourslash/completionListInUnclosedFunction16.ts new file mode 100644 index 00000000000..4ec5f41df53 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction16.ts @@ -0,0 +1,23 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction17.ts b/tests/cases/fourslash/completionListInUnclosedFunction17.ts new file mode 100644 index 00000000000..8cded845673 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction17.ts @@ -0,0 +1,23 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => y + /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction18.ts b/tests/cases/fourslash/completionListInUnclosedFunction18.ts new file mode 100644 index 00000000000..182694d73d2 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction18.ts @@ -0,0 +1,24 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => y + /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction19.ts b/tests/cases/fourslash/completionListInUnclosedFunction19.ts new file mode 100644 index 00000000000..6f49f270250 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction19.ts @@ -0,0 +1,23 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => { return y + /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts new file mode 100644 index 00000000000..888c6eeed0c --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: T/*1*/ + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts new file mode 100644 index 00000000000..15372ccea0d --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: TStr/*1*/ + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts new file mode 100644 index 00000000000..22821eb1084 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: TString/*1*/ + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts new file mode 100644 index 00000000000..c7f53e0e0df --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { /*1*/ + +goTo.marker("1"); + +verify.not.memberListContains("I"); +verify.not.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); From 8eae639a94335c78b4350ec98bf053b00eff6814 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:06:18 -0700 Subject: [PATCH 04/20] Added tests for #1410. --- ...mpletionListInArrowFunctionInUnclosedCallSite01.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts diff --git a/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts b/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts new file mode 100644 index 00000000000..82e4c6e4d15 --- /dev/null +++ b/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts @@ -0,0 +1,11 @@ +/// + +////declare function foo(...params: any[]): any; +////function getAllFiles(rootFileNames: string[]) { +//// var processedFiles = rootFileNames.map(fileName => foo(/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("fileName"); +verify.not.completionListContains("rootFileNames"); +verify.not.completionListContains("getAllFiles"); +verify.not.completionListContains("foo"); \ No newline at end of file From 92955a8f8d06af2cbdf47bd95b30f4a8181ca7a6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:32:57 -0700 Subject: [PATCH 05/20] Fixed up tests. --- ...pletionListInUnclosedObjectTypeLiteralInSignature01.ts | 6 ++++-- ...pletionListInUnclosedObjectTypeLiteralInSignature02.ts | 8 +++++--- ...pletionListInUnclosedObjectTypeLiteralInSignature03.ts | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts index 888c6eeed0c..a931bed6a4b 100644 --- a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts @@ -12,5 +12,7 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); verify.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts index 15372ccea0d..32a9504ebc3 100644 --- a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts @@ -11,6 +11,8 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); -verify.not.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); +verify.memberListContains("TNumber"); // REVIEW: Is this intended behavior? + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts index 22821eb1084..455f122888c 100644 --- a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts @@ -11,6 +11,8 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); -verify.not.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); +verify.memberListContains("TNumber"); // REVIEW: Is this intended behavior? + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); From c27e07a69b57dcc99a82fa127f7e1f626eaf3139 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:33:58 -0700 Subject: [PATCH 06/20] Moved logic from smart indenter; use 'scope nodes' for completions. --- src/services/formatting/smartIndenter.ts | 123 +---------------------- src/services/services.ts | 11 +- src/services/utilities.ts | 118 ++++++++++++++++++++++ 3 files changed, 129 insertions(+), 123 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 0932ad042e7..050468cb9da 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -215,11 +215,7 @@ module ts.formatting { function getStartLineAndCharacterForNode(n: Node, sourceFile: SourceFile): LineAndCharacter { return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); } - - function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean { - return candidate.end > position || !isCompletedNode(candidate, sourceFile); - } - + export function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFile): boolean { if (parent.kind === SyntaxKind.IfStatement && (parent).elseStatement === child) { var elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile); @@ -401,122 +397,5 @@ module ts.formatting { return false; } } - - /* - * Checks if node ends with 'expectedLastToken'. - * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'. - */ - function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean { - var children = n.getChildren(sourceFile); - if (children.length) { - var last = children[children.length - 1]; - if (last.kind === expectedLastToken) { - return true; - } - else if (last.kind === SyntaxKind.SemicolonToken && children.length !== 1) { - return children[children.length - 2].kind === expectedLastToken; - } - } - return false; - } - - /* - * This function is always called when position of the cursor is located after the node - */ - function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { - if (n.getFullWidth() === 0) { - return false; - } - - switch (n.kind) { - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.ObjectBindingPattern: - case SyntaxKind.TypeLiteral: - case SyntaxKind.Block: - case SyntaxKind.ModuleBlock: - case SyntaxKind.CaseBlock: - return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); - case SyntaxKind.CatchClause: - return isCompletedNode((n).block, sourceFile); - case SyntaxKind.NewExpression: - if (!(n).arguments) { - return true; - } - // fall through - case SyntaxKind.CallExpression: - case SyntaxKind.ParenthesizedExpression: - case SyntaxKind.ParenthesizedType: - return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); - - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return isCompletedNode((n).type, sourceFile); - - case SyntaxKind.Constructor: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.ConstructSignature: - case SyntaxKind.CallSignature: - case SyntaxKind.ArrowFunction: - if ((n).body) { - return isCompletedNode((n).body, sourceFile); - } - - if ((n).type) { - return isCompletedNode((n).type, sourceFile); - } - - // Even though type parameters can be unclosed, we can get away with - // having at least a closing paren. - return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile); - - case SyntaxKind.ModuleDeclaration: - return (n).body && isCompletedNode((n).body, sourceFile); - - case SyntaxKind.IfStatement: - if ((n).elseStatement) { - return isCompletedNode((n).elseStatement, sourceFile); - } - return isCompletedNode((n).thenStatement, sourceFile); - - case SyntaxKind.ExpressionStatement: - return isCompletedNode((n).expression, sourceFile); - - case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.ArrayBindingPattern: - case SyntaxKind.IndexSignature: - case SyntaxKind.ComputedPropertyName: - case SyntaxKind.TupleType: - return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); - - case SyntaxKind.CaseClause: - case SyntaxKind.DefaultClause: - // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed - return false; - - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - case SyntaxKind.WhileStatement: - return isCompletedNode((n).statement, sourceFile); - case SyntaxKind.DoStatement: - // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; - var hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); - if (hasWhileKeyword) { - return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); - } - return isCompletedNode((n).statement, sourceFile); - - default: - return true; - } - } } } \ No newline at end of file diff --git a/src/services/services.ts b/src/services/services.ts index 61d7a0736b0..e9d207bddea 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2595,8 +2595,9 @@ module ts { isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); /// TODO filter meaning based on the current context + var scopeNode = getScopeNode(previousToken, position, sourceFile); var symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; - var symbols = typeInfoResolver.getSymbolsInScope(node, symbolMeanings); + var symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } @@ -2615,6 +2616,14 @@ module ts { entries: activeCompletionSession.entries }; + function getScopeNode(initialToken: Node, position: number, sourceFile: SourceFile) { + var scope = initialToken; + while (scope && (isToken(scope) || !positionBelongsToNode(scope, position, sourceFile))) { + scope = scope.parent; + } + return scope; + } + function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void { var start = new Date().getTime(); forEach(symbols, symbol => { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 70c8eada5b7..11337b40e9d 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -59,6 +59,124 @@ module ts { return start < end; } + export function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean { + return candidate.end > position || !isCompletedNode(candidate, sourceFile); + } + + export function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { + if (n.getFullWidth() === 0) { + return false; + } + + switch (n.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.TypeLiteral: + case SyntaxKind.Block: + case SyntaxKind.ModuleBlock: + case SyntaxKind.CaseBlock: + return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); + case SyntaxKind.CatchClause: + return isCompletedNode((n).block, sourceFile); + case SyntaxKind.NewExpression: + if (!(n).arguments) { + return true; + } + // fall through + case SyntaxKind.CallExpression: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ParenthesizedType: + return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return isCompletedNode((n).type, sourceFile); + + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.ArrowFunction: + if ((n).body) { + return isCompletedNode((n).body, sourceFile); + } + + if ((n).type) { + return isCompletedNode((n).type, sourceFile); + } + + // Even though type parameters can be unclosed, we can get away with + // having at least a closing paren. + return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.ModuleDeclaration: + return (n).body && isCompletedNode((n).body, sourceFile); + + case SyntaxKind.IfStatement: + if ((n).elseStatement) { + return isCompletedNode((n).elseStatement, sourceFile); + } + return isCompletedNode((n).thenStatement, sourceFile); + + case SyntaxKind.ExpressionStatement: + return isCompletedNode((n).expression, sourceFile); + + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.IndexSignature: + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.TupleType: + return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); + + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed + return false; + + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.WhileStatement: + return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.DoStatement: + // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; + var hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); + if (hasWhileKeyword) { + return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + } + return isCompletedNode((n).statement, sourceFile); + + default: + return true; + } + } + + /* + * Checks if node ends with 'expectedLastToken'. + * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'. + */ + function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean { + var children = n.getChildren(sourceFile); + if (children.length) { + var last = children[children.length - 1]; + if (last.kind === expectedLastToken) { + return true; + } + else if (last.kind === SyntaxKind.SemicolonToken && children.length !== 1) { + return children[children.length - 2].kind === expectedLastToken; + } + } + return false; + } + export function findListItemInfo(node: Node): ListItemInfo { var list = findContainingList(node); From f1d5582a69ba1d36de21f47ebab2b15a1b1523be Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:39:46 -0700 Subject: [PATCH 07/20] Fixed missing marker. --- tests/cases/fourslash/completionListBeforeNewScope02.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/completionListBeforeNewScope02.ts b/tests/cases/fourslash/completionListBeforeNewScope02.ts index 9df03ec10a4..9fb1182b56e 100644 --- a/tests/cases/fourslash/completionListBeforeNewScope02.ts +++ b/tests/cases/fourslash/completionListBeforeNewScope02.ts @@ -1,6 +1,6 @@ /// -////a +////a/*1*/ //// ////{ //// let aaaaaa = 10; From c30b71db2ce37123953fed23eb63992464b50011 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:41:09 -0700 Subject: [PATCH 08/20] Removed negations from test. --- .../completionListInArrowFunctionInUnclosedCallSite01.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts b/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts index 82e4c6e4d15..633dc00a941 100644 --- a/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts +++ b/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts @@ -5,7 +5,7 @@ //// var processedFiles = rootFileNames.map(fileName => foo(/*1*/ goTo.marker("1"); -verify.not.completionListContains("fileName"); -verify.not.completionListContains("rootFileNames"); -verify.not.completionListContains("getAllFiles"); -verify.not.completionListContains("foo"); \ No newline at end of file +verify.completionListContains("fileName"); +verify.completionListContains("rootFileNames"); +verify.completionListContains("getAllFiles"); +verify.completionListContains("foo"); \ No newline at end of file From 34a3fc4f78fdf40ea2973fbb3ad02303b18212e8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:44:13 -0700 Subject: [PATCH 09/20] Fixed up more tests. --- ...ompletionListInClosedObjectTypeLiteralInSignature01.ts | 6 ++++-- ...ompletionListInClosedObjectTypeLiteralInSignature02.ts | 8 +++++--- ...ompletionListInClosedObjectTypeLiteralInSignature03.ts | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts index 5e7d8b30484..690fb583f67 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts @@ -12,5 +12,7 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); verify.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); \ No newline at end of file + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts index ee0e1e8b90c..57af3592d44 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts @@ -11,6 +11,8 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); -verify.not.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); \ No newline at end of file +verify.memberListContains("TNumber"); // REVIEW: Is this intended behavior? + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts index cdc4e9effff..1e5e6256d6e 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts @@ -11,6 +11,8 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); -verify.not.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); \ No newline at end of file +verify.memberListContains("TNumber"); // REVIEW: Is this intended behavior? + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); \ No newline at end of file From c89febeb238452402bfb5ffe802d1c424e9381b0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:46:21 -0700 Subject: [PATCH 10/20] Added completion check for prefix-unary, binary, and conditional expressions. --- src/services/utilities.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 11337b40e9d..cd7d48e7d0a 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -154,6 +154,13 @@ module ts { } return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.PrefixUnaryExpression: + return isCompletedNode(n, sourceFile); + case SyntaxKind.BinaryExpression: + return isCompletedNode((n).right, sourceFile); + case SyntaxKind.ConditionalExpression: + return isCompletedNode((n).whenFalse, sourceFile); + default: return true; } From f2a7367e9b63a2155d45708ac5b54161f8579926 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 07:50:15 -0700 Subject: [PATCH 11/20] Added index signature case. --- .../completionListInUnclosedIndexSignature01.ts | 11 +++++++++++ .../completionListInUnclosedIndexSignature02.ts | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts diff --git a/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts b/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts new file mode 100644 index 00000000000..fd2e5664f04 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts @@ -0,0 +1,11 @@ +/// + + +////class C { +//// [foo: string]: typeof /*1*/ +////} + + +goTo.marker("1"); +verify.completionListContains("foo"); +verify.completionListContains("C"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts b/tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts new file mode 100644 index 00000000000..318730e41a6 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts @@ -0,0 +1,13 @@ +/// + + +////class C { +//// [foo: /*1*/ +////} + +goTo.marker("1"); +verify.completionListContains("C"); +verify.completionListContains("foo"); // ideally this shouldn't show up for a type +edit.insert("typeof "); +verify.completionListContains("C"); +verify.completionListContains("foo"); \ No newline at end of file From ad084ded72cbfcf2ae581a333a5731cf22dacf1f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 08:07:40 -0700 Subject: [PATCH 12/20] Account for typeof expressions, added test. --- src/services/utilities.ts | 4 +++- .../completionListInUnclosedIndexSignature01.ts | 1 - .../completionListInUnclosedIndexSignature03.ts | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/completionListInUnclosedIndexSignature03.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index ca047414e59..679a97449ec 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -160,8 +160,10 @@ module ts { } return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.TypeOfExpression: + return isCompletedNode((n).expression, sourceFile); case SyntaxKind.PrefixUnaryExpression: - return isCompletedNode(n, sourceFile); + return isCompletedNode((n).operand, sourceFile); case SyntaxKind.BinaryExpression: return isCompletedNode((n).right, sourceFile); case SyntaxKind.ConditionalExpression: diff --git a/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts b/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts index fd2e5664f04..0667742d4cb 100644 --- a/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts +++ b/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts @@ -5,7 +5,6 @@ //// [foo: string]: typeof /*1*/ ////} - goTo.marker("1"); verify.completionListContains("foo"); verify.completionListContains("C"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedIndexSignature03.ts b/tests/cases/fourslash/completionListInUnclosedIndexSignature03.ts new file mode 100644 index 00000000000..bb4ef808bff --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedIndexSignature03.ts @@ -0,0 +1,10 @@ +/// + + +////class C { +//// [foo: string]: { x: typeof /*1*/ +////} + +goTo.marker("1"); +verify.completionListContains("foo"); +verify.completionListContains("C"); \ No newline at end of file From 754a8a617c5868cda1094ab7474113c5eaff012d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 12:21:35 -0700 Subject: [PATCH 13/20] More cases and tests for them. --- src/services/utilities.ts | 19 ++++++++++++++++++- ...pletionListInUnclosedDeleteExpression01.ts | 7 +++++++ ...pletionListInUnclosedDeleteExpression02.ts | 8 ++++++++ ...pletionListInUnclosedSpreadExpression01.ts | 7 +++++++ ...pletionListInUnclosedSpreadExpression02.ts | 8 ++++++++ ...ompletionListInUnclosedTaggedTemplate01.ts | 8 ++++++++ ...ompletionListInUnclosedTaggedTemplate02.ts | 8 ++++++++ .../completionListInUnclosedTemplate01.ts | 8 ++++++++ .../completionListInUnclosedTemplate02.ts | 8 ++++++++ ...pletionListInUnclosedTypeOfExpression01.ts | 7 +++++++ ...pletionListInUnclosedTypeOfExpression02.ts | 8 ++++++++ ...ompletionListInUnclosedVoidExpression01.ts | 8 ++++++++ ...mpletionListInUnclosedYieldExpression01.ts | 10 ++++++++++ 13 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionListInUnclosedDeleteExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedDeleteExpression02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedSpreadExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedSpreadExpression02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTaggedTemplate01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTaggedTemplate02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTemplate01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTemplate02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTypeOfExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTypeOfExpression02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedVoidExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedYieldExpression01.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 679a97449ec..a53ab212bf2 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -160,8 +160,25 @@ module ts { } return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.TypeQuery: + return isCompletedNode((n).exprName, sourceFile); + case SyntaxKind.TypeOfExpression: - return isCompletedNode((n).expression, sourceFile); + case SyntaxKind.DeleteExpression: + case SyntaxKind.VoidExpression: + case SyntaxKind.YieldExpression: + case SyntaxKind.SpreadElementExpression: + let unaryWordExpression = (n); + return isCompletedNode(unaryWordExpression.expression, sourceFile); + + case SyntaxKind.TaggedTemplateExpression: + return isCompletedNode((n).template, sourceFile); + case SyntaxKind.TemplateExpression: + let lastSpan = lastOrUndefined((n).templateSpans); + return isCompletedNode(lastSpan, sourceFile); + case SyntaxKind.TemplateSpan: + return nodeIsPresent((n).literal); + case SyntaxKind.PrefixUnaryExpression: return isCompletedNode((n).operand, sourceFile); case SyntaxKind.BinaryExpression: diff --git a/tests/cases/fourslash/completionListInUnclosedDeleteExpression01.ts b/tests/cases/fourslash/completionListInUnclosedDeleteExpression01.ts new file mode 100644 index 00000000000..fdb67dfc335 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedDeleteExpression01.ts @@ -0,0 +1,7 @@ +/// + +////var x; +////var y = delete /*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedDeleteExpression02.ts b/tests/cases/fourslash/completionListInUnclosedDeleteExpression02.ts new file mode 100644 index 00000000000..3573c345285 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedDeleteExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => delete /*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); +verify.completionListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedSpreadExpression01.ts b/tests/cases/fourslash/completionListInUnclosedSpreadExpression01.ts new file mode 100644 index 00000000000..b9cc01f0a66 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedSpreadExpression01.ts @@ -0,0 +1,7 @@ +/// + +////var x; +////var y = [1,2,.../*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedSpreadExpression02.ts b/tests/cases/fourslash/completionListInUnclosedSpreadExpression02.ts new file mode 100644 index 00000000000..40d90370232 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedSpreadExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => [1,2,.../*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTaggedTemplate01.ts b/tests/cases/fourslash/completionListInUnclosedTaggedTemplate01.ts new file mode 100644 index 00000000000..20e2a5d0663 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTaggedTemplate01.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => x `abc ${ /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTaggedTemplate02.ts b/tests/cases/fourslash/completionListInUnclosedTaggedTemplate02.ts new file mode 100644 index 00000000000..d4bbd5992c6 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTaggedTemplate02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => x `abc ${ 123 } ${ /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTemplate01.ts b/tests/cases/fourslash/completionListInUnclosedTemplate01.ts new file mode 100644 index 00000000000..c7b8f628170 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTemplate01.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => `abc ${ /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTemplate02.ts b/tests/cases/fourslash/completionListInUnclosedTemplate02.ts new file mode 100644 index 00000000000..5fd5c94ee3e --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTemplate02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => `abc ${ 123 } ${ /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTypeOfExpression01.ts b/tests/cases/fourslash/completionListInUnclosedTypeOfExpression01.ts new file mode 100644 index 00000000000..3da8b4fd616 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTypeOfExpression01.ts @@ -0,0 +1,7 @@ +/// + +////var x; +////var y = typeof /*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTypeOfExpression02.ts b/tests/cases/fourslash/completionListInUnclosedTypeOfExpression02.ts new file mode 100644 index 00000000000..b1d347211ac --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTypeOfExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => typeof /*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); +verify.completionListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedVoidExpression01.ts b/tests/cases/fourslash/completionListInUnclosedVoidExpression01.ts new file mode 100644 index 00000000000..d1cfecbffec --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedVoidExpression01.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => void /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedYieldExpression01.ts b/tests/cases/fourslash/completionListInUnclosedYieldExpression01.ts new file mode 100644 index 00000000000..658b0de7dc8 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedYieldExpression01.ts @@ -0,0 +1,10 @@ +/// + +////var x; +////var y = function* gen(p) { yield /*1*/ + +goTo.marker("1"); +// These tentatively don't work. +verify.not.completionListContains("p"); +verify.not.completionListContains("gen"); +verify.not.completionListContains("x"); \ No newline at end of file From 860c04637611adf2a3d512fe000a4e86c0afb880 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 12:27:24 -0700 Subject: [PATCH 14/20] Start using nodeIsMissing. --- src/services/utilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/utilities.ts b/src/services/utilities.ts index a53ab212bf2..8758d126f63 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -64,7 +64,7 @@ module ts { } export function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { - if (n.getFullWidth() === 0) { + if (nodeIsMissing(n)) { return false; } From 7a716d9d42c25f53d5e35fa92e5b014bac285e74 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 12:27:59 -0700 Subject: [PATCH 15/20] Start handling element access expressions. --- src/services/utilities.ts | 1 + .../completionListInUnclosedElementAccessExpression01.ts | 7 +++++++ .../completionListInUnclosedElementAccessExpression02.ts | 8 ++++++++ 3 files changed, 16 insertions(+) create mode 100644 tests/cases/fourslash/completionListInUnclosedElementAccessExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedElementAccessExpression02.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 8758d126f63..6147112c909 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -131,6 +131,7 @@ module ts { case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.ElementAccessExpression: case SyntaxKind.ComputedPropertyName: case SyntaxKind.TupleType: return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); diff --git a/tests/cases/fourslash/completionListInUnclosedElementAccessExpression01.ts b/tests/cases/fourslash/completionListInUnclosedElementAccessExpression01.ts new file mode 100644 index 00000000000..59c4922671e --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedElementAccessExpression01.ts @@ -0,0 +1,7 @@ +/// + +////var x; +////var y = x[/*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedElementAccessExpression02.ts b/tests/cases/fourslash/completionListInUnclosedElementAccessExpression02.ts new file mode 100644 index 00000000000..1d6403cfa10 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedElementAccessExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => x[/*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file From 3418a49f8a29be430d9233d9638f8a2f2d9f93cb Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 13:20:44 -0700 Subject: [PATCH 16/20] Line endings. --- src/services/services.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 95251b81984..f5b9e36f59b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2596,10 +2596,10 @@ module ts { isMemberCompletion = false; isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); - /// TODO filter meaning based on the current context + /// TODO filter meaning based on the current context let scopeNode = getScopeNode(previousToken, position, sourceFile); let symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; - let symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); + let symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } From e49fc058b08b0d62fe573b20f3eba6f4ac51273e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 13:33:01 -0700 Subject: [PATCH 17/20] Added tests. --- .../completionListInUnclosedCommaExpression01.ts | 8 ++++++++ .../completionListInUnclosedCommaExpression02.ts | 8 ++++++++ .../cases/fourslash/completionListInUnclosedForLoop01.ts | 6 ++++++ .../cases/fourslash/completionListInUnclosedForLoop02.ts | 6 ++++++ .../completionListOutsideOfClosedArrowFunction01.ts | 8 ++++++++ .../completionListOutsideOfClosedArrowFunction02.ts | 8 ++++++++ .../completionListOutsideOfClosedFunctionDeclaration01.ts | 8 ++++++++ tests/cases/fourslash/completionListOutsideOfForLoop01.ts | 6 ++++++ tests/cases/fourslash/completionListOutsideOfForLoop02.ts | 6 ++++++ 9 files changed, 64 insertions(+) create mode 100644 tests/cases/fourslash/completionListInUnclosedCommaExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedCommaExpression02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedForLoop01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedForLoop02.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfClosedArrowFunction01.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfClosedArrowFunction02.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfClosedFunctionDeclaration01.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfForLoop01.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfForLoop02.ts diff --git a/tests/cases/fourslash/completionListInUnclosedCommaExpression01.ts b/tests/cases/fourslash/completionListInUnclosedCommaExpression01.ts new file mode 100644 index 00000000000..de0f26eb86e --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedCommaExpression01.ts @@ -0,0 +1,8 @@ +/// + +////// should NOT see a and b +////foo((a, b) => a,/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("a"); +verify.not.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedCommaExpression02.ts b/tests/cases/fourslash/completionListInUnclosedCommaExpression02.ts new file mode 100644 index 00000000000..e0ea3abbd38 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedCommaExpression02.ts @@ -0,0 +1,8 @@ +/// + +////// should NOT see a and b +////foo((a, b) => (a,/*1*/ + +goTo.marker("1"); +verify.completionListContains("a"); +verify.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedForLoop01.ts b/tests/cases/fourslash/completionListInUnclosedForLoop01.ts new file mode 100644 index 00000000000..35e5efdd304 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedForLoop01.ts @@ -0,0 +1,6 @@ +/// + +////for (let i = 0; /*1*/ + +goTo.marker("1"); +verify.completionListContains("i"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedForLoop02.ts b/tests/cases/fourslash/completionListInUnclosedForLoop02.ts new file mode 100644 index 00000000000..e79f428b2b0 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedForLoop02.ts @@ -0,0 +1,6 @@ +/// + +////for (let i = 0; i < 10; i++) /*1*/ + +goTo.marker("1"); +verify.completionListContains("i"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction01.ts b/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction01.ts new file mode 100644 index 00000000000..d775371796f --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction01.ts @@ -0,0 +1,8 @@ +/// + +////// no a or b +/////*1*/(a, b) => { } + +goTo.marker("1"); +verify.not.completionListContains("a"); +verify.not.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction02.ts b/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction02.ts new file mode 100644 index 00000000000..d9195ce5b97 --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction02.ts @@ -0,0 +1,8 @@ +/// + +////// no a or b +////(a, b) => { }/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("a"); +verify.not.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfClosedFunctionDeclaration01.ts b/tests/cases/fourslash/completionListOutsideOfClosedFunctionDeclaration01.ts new file mode 100644 index 00000000000..8b6077e0f8b --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfClosedFunctionDeclaration01.ts @@ -0,0 +1,8 @@ +/// + +////// no a or b +/////*1*/function f (a, b) {} + +goTo.marker("1"); +verify.not.completionListContains("a"); +verify.not.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfForLoop01.ts b/tests/cases/fourslash/completionListOutsideOfForLoop01.ts new file mode 100644 index 00000000000..473a39a453d --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfForLoop01.ts @@ -0,0 +1,6 @@ +/// + +////for (let i = 0; i < 10; i++) i;/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("i"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfForLoop02.ts b/tests/cases/fourslash/completionListOutsideOfForLoop02.ts new file mode 100644 index 00000000000..b1186ac7cce --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfForLoop02.ts @@ -0,0 +1,6 @@ +/// + +////for (let i = 0; i < 10; i++);/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("i"); \ No newline at end of file From ec4278972d8cdc949571017b063b7180c0016c3f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 12:08:09 -0700 Subject: [PATCH 18/20] Addressed CR feedback. --- src/services/services.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index f5b9e36f59b..f549bce6bd5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2618,9 +2618,13 @@ module ts { entries: activeCompletionSession.entries }; + /** + * Finds the first node that "embraces" the position, so that one may + * accurately aggregate locals from the closest containing scope. + */ function getScopeNode(initialToken: Node, position: number, sourceFile: SourceFile) { var scope = initialToken; - while (scope && (isToken(scope) || !positionBelongsToNode(scope, position, sourceFile))) { + while (scope && !positionBelongsToNode(scope, position, sourceFile)) { scope = scope.parent; } return scope; From e82ea7df0f6bc1e6932abf77647241c30fe67b76 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 12:12:57 -0700 Subject: [PATCH 19/20] Added test for completions at beginning of file. --- .../fourslash/completionListAtBeginningOfFile01.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/cases/fourslash/completionListAtBeginningOfFile01.ts diff --git a/tests/cases/fourslash/completionListAtBeginningOfFile01.ts b/tests/cases/fourslash/completionListAtBeginningOfFile01.ts new file mode 100644 index 00000000000..f811fec4c67 --- /dev/null +++ b/tests/cases/fourslash/completionListAtBeginningOfFile01.ts @@ -0,0 +1,13 @@ +/// + +/////*1*/ +////var x = 0, y = 1, z = 2; +////enum E { +//// A, B, C +////} + +goTo.marker("1"); +verify.completionListContains("x"); +verify.completionListContains("y"); +verify.completionListContains("z"); +verify.completionListContains("E"); \ No newline at end of file From ee073e19f08c623e22f51e3bc557d1286d960111 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 12:27:28 -0700 Subject: [PATCH 20/20] Remove space. --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index f549bce6bd5..067e4580991 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2614,7 +2614,7 @@ module ts { return { isMemberCompletion, isNewIdentifierLocation, - isBuilder : isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation + isBuilder: isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation entries: activeCompletionSession.entries };