From d2fe1c0a61b7518f8b1b2f32ba46703a1c1db9e3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 23 Jun 2015 15:13:11 -0700 Subject: [PATCH 01/13] Added tests. --- .../completionsInObjectBindingPattern01.ts | 13 +++++++++++++ .../completionsInObjectBindingPattern02.ts | 13 +++++++++++++ .../completionsInObjectBindingPattern03.ts | 13 +++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern01.ts create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern02.ts create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern03.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern01.ts b/tests/cases/fourslash/completionsInObjectBindingPattern01.ts new file mode 100644 index 00000000000..128e95b8ed3 --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern01.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { /**/ } = foo; + +goTo.marker(); +verify.completionListContains("property1"); +verify.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern02.ts b/tests/cases/fourslash/completionsInObjectBindingPattern02.ts new file mode 100644 index 00000000000..776fcc955c2 --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern02.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1, /**/ } = foo; + +goTo.marker(); +verify.not.completionListContains("property1"); +verify.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern03.ts b/tests/cases/fourslash/completionsInObjectBindingPattern03.ts new file mode 100644 index 00000000000..72da68168bd --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern03.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1: /**/ } = foo; + +goTo.marker(); +verify.completionListAllowsNewIdentifier(); +verify.completionListIsEmpty(); \ No newline at end of file From 0b78d037467f26629f260d9eeb87baaa982bcdc9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 23 Jun 2015 15:32:02 -0700 Subject: [PATCH 02/13] Clean up 'getContainingObjectLiteralApplicableForCompletion'. --- src/services/services.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 18510b9a178..5af32f9972c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3187,15 +3187,14 @@ namespace ts { return false; } - function getContainingObjectLiteralApplicableForCompletion(previousToken: Node): ObjectLiteralExpression { - // The locations in an object literal expression that are applicable for completion are property name definition locations. - - if (previousToken) { - let parent = previousToken.parent; - - switch (previousToken.kind) { + function getContainingObjectLiteralApplicableForCompletion(contextToken: Node): ObjectLiteralExpression { + // The locations in an object literal expression that + // are applicable for completion are property name definition locations. + if (contextToken) { + switch (contextToken.kind) { case SyntaxKind.OpenBraceToken: // let x = { | case SyntaxKind.CommaToken: // let x = { a: 0, | + let parent = contextToken.parent; if (parent && parent.kind === SyntaxKind.ObjectLiteralExpression) { return parent; } From 30ec5f92767b2f996c38b15c906598860f36d420 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 23 Jun 2015 16:08:19 -0700 Subject: [PATCH 03/13] Add test case for when in the middle/at the end of the word. --- .../completionsInObjectBindingPattern04.ts | 13 +++++++++++++ .../completionsInObjectBindingPattern05.ts | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern04.ts create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern05.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern04.ts b/tests/cases/fourslash/completionsInObjectBindingPattern04.ts new file mode 100644 index 00000000000..92b202a1b37 --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern04.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { prope/**/ } = foo; + +goTo.marker(); +verify.completionListContains("property1"); +verify.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern05.ts b/tests/cases/fourslash/completionsInObjectBindingPattern05.ts new file mode 100644 index 00000000000..d17e11810df --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern05.ts @@ -0,0 +1,12 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1/**/ } = foo; + +goTo.marker(); +verify.completionListContains("property1"); \ No newline at end of file From 6accbdf0299e01e723fd07676f98bb8f71694e88 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 23 Jun 2015 16:37:22 -0700 Subject: [PATCH 04/13] Generalize logic for upcoming work on object binding completion. --- src/services/services.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 5af32f9972c..1aeac286748 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2985,8 +2985,8 @@ namespace ts { } function tryGetGlobalSymbols(): boolean { - let containingObjectLiteral = getContainingObjectLiteralApplicableForCompletion(contextToken); - if (containingObjectLiteral) { + let containingObjectLiteral = getContainingObjectLiteralOrBindingPatternIfApplicableForCompletion(contextToken); + if (containingObjectLiteral && containingObjectLiteral.kind === SyntaxKind.ObjectLiteralExpression) { // Object literal expression, look up possible property names from contextual type isMemberCompletion = true; isNewIdentifierLocation = true; @@ -3187,7 +3187,7 @@ namespace ts { return false; } - function getContainingObjectLiteralApplicableForCompletion(contextToken: Node): ObjectLiteralExpression { + function getContainingObjectLiteralOrBindingPatternIfApplicableForCompletion(contextToken: Node): ObjectLiteralExpression | BindingPattern { // The locations in an object literal expression that // are applicable for completion are property name definition locations. if (contextToken) { @@ -3195,8 +3195,8 @@ namespace ts { case SyntaxKind.OpenBraceToken: // let x = { | case SyntaxKind.CommaToken: // let x = { a: 0, | let parent = contextToken.parent; - if (parent && parent.kind === SyntaxKind.ObjectLiteralExpression) { - return parent; + if (parent && (parent.kind === SyntaxKind.ObjectLiteralExpression || parent.kind === SyntaxKind.ObjectBindingPattern)) { + return parent; } break; } From c6498d79e57fa8ca018b3b7060b7d81c3c487a5e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Jun 2015 11:28:56 -0400 Subject: [PATCH 05/13] Changed ordering of verifications. --- tests/cases/fourslash/completionsInObjectBindingPattern02.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern02.ts b/tests/cases/fourslash/completionsInObjectBindingPattern02.ts index 776fcc955c2..6d2b7a6b516 100644 --- a/tests/cases/fourslash/completionsInObjectBindingPattern02.ts +++ b/tests/cases/fourslash/completionsInObjectBindingPattern02.ts @@ -9,5 +9,5 @@ ////var { property1, /**/ } = foo; goTo.marker(); -verify.not.completionListContains("property1"); -verify.completionListContains("property2"); \ No newline at end of file +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); \ No newline at end of file From 513d73ad4b48601511e5b6515db663a973d22dc4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Jun 2015 11:30:10 -0400 Subject: [PATCH 06/13] Don't print in the middle of tests. --- src/harness/fourslash.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 5915698462c..ff5baddbb70 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -660,8 +660,7 @@ module FourSlash { } errorMsg += "]\n"; - Harness.IO.log(errorMsg); - this.raiseError("Member list is not empty at Caret"); + this.raiseError("Member list is not empty at Caret: " + errorMsg); } } From c114de1a836524f3a60e9569d5369b7631d6f5fc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Jun 2015 11:31:36 -0400 Subject: [PATCH 07/13] Basic completion in object destructuring working. --- src/compiler/checker.ts | 6 +++++- src/services/services.ts | 31 ++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a18f2921a9a..00426d2aaf3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11993,7 +11993,7 @@ namespace ts { return resolveExternalModuleName(node, node); } - // Intentional fall-through + // fall through case SyntaxKind.NumericLiteral: // index access if (node.parent.kind === SyntaxKind.ElementAccessExpression && (node.parent).argumentExpression === node) { @@ -12060,6 +12060,10 @@ namespace ts { return symbol && getTypeOfSymbol(symbol); } + if (isBindingPattern(node)) { + return getTypeForVariableLikeDeclaration(node.parent); + } + if (isInRightSideOfImportOrExportAssignment(node)) { let symbol = getSymbolInfo(node); let declaredType = symbol && getDeclaredTypeOfSymbol(symbol); diff --git a/src/services/services.ts b/src/services/services.ts index 1aeac286748..78ce084b3ff 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2985,21 +2985,32 @@ namespace ts { } function tryGetGlobalSymbols(): boolean { - let containingObjectLiteral = getContainingObjectLiteralOrBindingPatternIfApplicableForCompletion(contextToken); - if (containingObjectLiteral && containingObjectLiteral.kind === SyntaxKind.ObjectLiteralExpression) { + let objectLikeContainer = getContainingObjectLiteralOrBindingPatternIfApplicableForCompletion(contextToken); + if (objectLikeContainer) { // Object literal expression, look up possible property names from contextual type isMemberCompletion = true; isNewIdentifierLocation = true; - let contextualType = typeChecker.getContextualType(containingObjectLiteral); - if (!contextualType) { + let typeForObject: Type; + let existingMembers: Declaration[]; + + if (objectLikeContainer.kind === SyntaxKind.ObjectLiteralExpression) { + typeForObject = typeChecker.getContextualType(objectLikeContainer); + existingMembers = (objectLikeContainer).properties; + } + else { + typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); + existingMembers = (objectLikeContainer).elements; + } + + if (!typeForObject) { return false; } - let contextualTypeMembers = typeChecker.getPropertiesOfType(contextualType); - if (contextualTypeMembers && contextualTypeMembers.length > 0) { + let typeMembers = typeChecker.getPropertiesOfType(typeForObject); + if (typeMembers && typeMembers.length > 0) { // Add filtered items to the completion list - symbols = filterContextualMembersList(contextualTypeMembers, containingObjectLiteral.properties); + symbols = filterContextualMembersList(typeMembers, existingMembers); } } else if (getAncestor(contextToken, SyntaxKind.ImportClause)) { @@ -3235,8 +3246,7 @@ namespace ts { containingNodeKind === SyntaxKind.ClassDeclaration || // class A Date: Wed, 24 Jun 2015 11:41:59 -0400 Subject: [PATCH 08/13] Got filtering working in object binding patterns. --- src/services/services.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 78ce084b3ff..2283d02ccb9 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3010,7 +3010,7 @@ namespace ts { let typeMembers = typeChecker.getPropertiesOfType(typeForObject); if (typeMembers && typeMembers.length > 0) { // Add filtered items to the completion list - symbols = filterContextualMembersList(typeMembers, existingMembers); + symbols = filterObjectMembersList(typeMembers, existingMembers); } } else if (getAncestor(contextToken, SyntaxKind.ImportClause)) { @@ -3356,26 +3356,28 @@ namespace ts { return filter(exports, e => !lookUp(exisingImports, e.name)); } - function filterContextualMembersList(contextualMemberSymbols: Symbol[], existingMembers: Declaration[]): Symbol[] { + function filterObjectMembersList(contextualMemberSymbols: Symbol[], existingMembers: Declaration[]): Symbol[] { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; } let existingMemberNames: Map = {}; - forEach(existingMembers, m => { - if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) { - // Ignore omitted expressions for missing members in the object literal - return; + for (let m of existingMembers) { + if (m.kind !== SyntaxKind.PropertyAssignment && + m.kind !== SyntaxKind.ShorthandPropertyAssignment && + m.kind !== SyntaxKind.BindingElement) { + // Ignore omitted expressions for missing members + continue; } if (m.getStart() <= position && position <= m.getEnd()) { // If this is the current item we are editing right now, do not filter it out - return; + continue; } // TODO(jfreeman): Account for computed property name existingMemberNames[(m.name).text] = true; - }); + } let filteredMembers: Symbol[] = []; forEach(contextualMemberSymbols, s => { From d3c59f4cc2c062f377896f01c001757ea5c2a940 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Jun 2015 12:33:49 -0400 Subject: [PATCH 09/13] Added more tests. --- .../completionsInObjectBindingPattern06.ts | 12 ++++++++++++ .../completionsInObjectBindingPattern07.ts | 18 ++++++++++++++++++ .../completionsInObjectBindingPattern08.ts | 18 ++++++++++++++++++ .../completionsInObjectBindingPattern09.ts | 19 +++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern06.ts create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern07.ts create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern08.ts create mode 100644 tests/cases/fourslash/completionsInObjectBindingPattern09.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern06.ts b/tests/cases/fourslash/completionsInObjectBindingPattern06.ts new file mode 100644 index 00000000000..8060c2bde78 --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern06.ts @@ -0,0 +1,12 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1, property2, /**/ } = foo; + +goTo.marker(); +verify.completionListIsEmpty(); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern07.ts b/tests/cases/fourslash/completionsInObjectBindingPattern07.ts new file mode 100644 index 00000000000..a3015346aa3 --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern07.ts @@ -0,0 +1,18 @@ +/// + +////interface I { +//// propertyOfI_1: number; +//// propertyOfI_2: string; +////} +////interface J { +//// property1: I; +//// property2: string; +////} +//// +////var foo: J; +////var { property1: { /**/ } } = foo; + +goTo.marker(); +verify.completionListContains("propertyOfI_1"); +verify.completionListContains("propertyOfI_2"); +verify.not.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern08.ts b/tests/cases/fourslash/completionsInObjectBindingPattern08.ts new file mode 100644 index 00000000000..6d6be330b83 --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern08.ts @@ -0,0 +1,18 @@ +/// + +////interface I { +//// propertyOfI_1: number; +//// propertyOfI_2: string; +////} +////interface J { +//// property1: I; +//// property2: string; +////} +//// +////var foo: J; +////var { property1: { propertyOfI_1, /**/ } } = foo; + +goTo.marker(); +verify.completionListContains("propertyOfI_2"); +verify.not.completionListContains("propertyOfI_1"); +verify.not.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern09.ts b/tests/cases/fourslash/completionsInObjectBindingPattern09.ts new file mode 100644 index 00000000000..2698e78667b --- /dev/null +++ b/tests/cases/fourslash/completionsInObjectBindingPattern09.ts @@ -0,0 +1,19 @@ +/// + +////interface I { +//// propertyOfI_1: number; +//// propertyOfI_2: string; +////} +////interface J { +//// property1: I; +//// property2: string; +////} +//// +////var foo: J; +////var { property1: { propertyOfI_1, }, /**/ } = foo; + +goTo.marker(); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); +verify.not.completionListContains("propertyOfI_2"); +verify.not.completionListContains("propertyOfI_1"); \ No newline at end of file From d892a55aa9cd14b86bd6578ed102540fbcf7c8eb Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Jun 2015 12:35:11 -0400 Subject: [PATCH 10/13] Use 'propertyName' when available in a BindingPattern. --- src/services/services.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 2283d02ccb9..25949082e8d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3363,20 +3363,31 @@ namespace ts { let existingMemberNames: Map = {}; for (let m of existingMembers) { + // Ignore omitted expressions for missing members if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment && m.kind !== SyntaxKind.BindingElement) { - // Ignore omitted expressions for missing members continue; } + // If this is the current item we are editing right now, do not filter it out if (m.getStart() <= position && position <= m.getEnd()) { - // If this is the current item we are editing right now, do not filter it out continue; } - // TODO(jfreeman): Account for computed property name - existingMemberNames[(m.name).text] = true; + let existingName: string; + + if (m.kind === SyntaxKind.BindingElement && (m).propertyName) { + existingName = (m).propertyName.text; + } + else { + // TODO(jfreeman): Account for computed property name + // NOTE: if one only performs this step when m.name is an identifier, + // things like '__proto__' are not filtered out. + existingName = (m.name).text; + } + + existingMemberNames[existingName] = true; } let filteredMembers: Symbol[] = []; From 713a70d794356a2fd5c6ba9d5a84cbde0d392803 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Jun 2015 12:39:10 -0400 Subject: [PATCH 11/13] Renamed tests. --- ...dingPattern01.ts => completionListInObjectBindingPattern01.ts} | 0 ...dingPattern02.ts => completionListInObjectBindingPattern02.ts} | 0 ...dingPattern03.ts => completionListInObjectBindingPattern03.ts} | 0 ...dingPattern04.ts => completionListInObjectBindingPattern04.ts} | 0 ...dingPattern05.ts => completionListInObjectBindingPattern05.ts} | 0 ...dingPattern06.ts => completionListInObjectBindingPattern06.ts} | 0 ...dingPattern07.ts => completionListInObjectBindingPattern07.ts} | 0 ...dingPattern08.ts => completionListInObjectBindingPattern08.ts} | 0 ...dingPattern09.ts => completionListInObjectBindingPattern09.ts} | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/fourslash/{completionsInObjectBindingPattern01.ts => completionListInObjectBindingPattern01.ts} (100%) rename tests/cases/fourslash/{completionsInObjectBindingPattern02.ts => completionListInObjectBindingPattern02.ts} (100%) rename tests/cases/fourslash/{completionsInObjectBindingPattern03.ts => completionListInObjectBindingPattern03.ts} (100%) rename tests/cases/fourslash/{completionsInObjectBindingPattern04.ts => completionListInObjectBindingPattern04.ts} (100%) rename tests/cases/fourslash/{completionsInObjectBindingPattern05.ts => completionListInObjectBindingPattern05.ts} (100%) rename tests/cases/fourslash/{completionsInObjectBindingPattern06.ts => completionListInObjectBindingPattern06.ts} (100%) rename tests/cases/fourslash/{completionsInObjectBindingPattern07.ts => completionListInObjectBindingPattern07.ts} (100%) rename tests/cases/fourslash/{completionsInObjectBindingPattern08.ts => completionListInObjectBindingPattern08.ts} (100%) rename tests/cases/fourslash/{completionsInObjectBindingPattern09.ts => completionListInObjectBindingPattern09.ts} (100%) diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern01.ts b/tests/cases/fourslash/completionListInObjectBindingPattern01.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern01.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern01.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern02.ts b/tests/cases/fourslash/completionListInObjectBindingPattern02.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern02.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern02.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern03.ts b/tests/cases/fourslash/completionListInObjectBindingPattern03.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern03.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern03.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern04.ts b/tests/cases/fourslash/completionListInObjectBindingPattern04.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern04.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern04.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern05.ts b/tests/cases/fourslash/completionListInObjectBindingPattern05.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern05.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern05.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern06.ts b/tests/cases/fourslash/completionListInObjectBindingPattern06.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern06.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern06.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern07.ts b/tests/cases/fourslash/completionListInObjectBindingPattern07.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern07.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern07.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern08.ts b/tests/cases/fourslash/completionListInObjectBindingPattern08.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern08.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern08.ts diff --git a/tests/cases/fourslash/completionsInObjectBindingPattern09.ts b/tests/cases/fourslash/completionListInObjectBindingPattern09.ts similarity index 100% rename from tests/cases/fourslash/completionsInObjectBindingPattern09.ts rename to tests/cases/fourslash/completionListInObjectBindingPattern09.ts From 02e01d7afcf03af039f2452e1b242b2aac2c39b3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Jun 2015 17:13:47 -0400 Subject: [PATCH 12/13] Added tests. --- .../completionListInObjectBindingPattern10.ts | 23 +++++++++++++++++++ .../completionListInObjectBindingPattern11.ts | 13 +++++++++++ .../completionListInObjectBindingPattern12.ts | 13 +++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/cases/fourslash/completionListInObjectBindingPattern10.ts create mode 100644 tests/cases/fourslash/completionListInObjectBindingPattern11.ts create mode 100644 tests/cases/fourslash/completionListInObjectBindingPattern12.ts diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern10.ts b/tests/cases/fourslash/completionListInObjectBindingPattern10.ts new file mode 100644 index 00000000000..fcc09d1ead4 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern10.ts @@ -0,0 +1,23 @@ +/// + +////interface I { +//// propertyOfI_1: number; +//// propertyOfI_2: string; +////} +////interface J { +//// property1: I; +//// property2: string; +////} +//// +////var foo: J[]; +////var [{ property1: { propertyOfI_1, }, /*1*/ }, { /*2*/ }] = foo; + +goTo.marker("1"); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); +verify.not.completionListContains("propertyOfI_2"); +verify.not.completionListContains("propertyOfI_1"); + +goTo.marker("2"); +verify.completionListContains("property1"); +verify.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern11.ts b/tests/cases/fourslash/completionListInObjectBindingPattern11.ts new file mode 100644 index 00000000000..25d6651a038 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern11.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var { property1: prop1, /**/ }: I; + +goTo.marker(""); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); +verify.not.completionListContains("prop1"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern12.ts b/tests/cases/fourslash/completionListInObjectBindingPattern12.ts new file mode 100644 index 00000000000..f31206a21b6 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern12.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////function f({ property1, /**/ }: I): void { +////} + +goTo.marker(""); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); \ No newline at end of file From e52a27b3de5f003de74f4d245bed7fabbc26d7f5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Jun 2015 18:07:49 -0400 Subject: [PATCH 13/13] Renamed function. --- src/services/services.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 25949082e8d..f4e37bf56ea 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2985,7 +2985,7 @@ namespace ts { } function tryGetGlobalSymbols(): boolean { - let objectLikeContainer = getContainingObjectLiteralOrBindingPatternIfApplicableForCompletion(contextToken); + let objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken); if (objectLikeContainer) { // Object literal expression, look up possible property names from contextual type isMemberCompletion = true; @@ -3198,9 +3198,11 @@ namespace ts { return false; } - function getContainingObjectLiteralOrBindingPatternIfApplicableForCompletion(contextToken: Node): ObjectLiteralExpression | BindingPattern { - // The locations in an object literal expression that - // are applicable for completion are property name definition locations. + /** + * Returns the immediate owning object literal or binding pattern of a context token, + * on the condition that one exists and that the context implies completion should be given. + */ + function tryGetObjectLikeCompletionContainer(contextToken: Node): ObjectLiteralExpression | BindingPattern { if (contextToken) { switch (contextToken.kind) { case SyntaxKind.OpenBraceToken: // let x = { |