From 308f13fb9b53e9e0e1c243cdfe4c00834647c8fe Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 9 Jan 2015 12:21:30 -0800 Subject: [PATCH 01/21] infrastructure for builder item in completion list --- 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 1618fb6e2767a..abe12b0012859 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1078,6 +1078,7 @@ module ts { export interface CompletionInfo { isMemberCompletion: boolean; + isBuilder: boolean; entries: CompletionEntry[]; } @@ -2266,6 +2267,7 @@ module ts { // Right of dot member completion list var symbols: Symbol[] = []; var isMemberCompletion = true; + var isBuilder = false; if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression) { var symbol = typeInfoResolver.getSymbolAtLocation(node); @@ -2318,6 +2320,7 @@ module ts { else { // Get scope members isMemberCompletion = false; + isBuilder = true; /// TODO filter meaning based on the current context var symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Import; @@ -2335,6 +2338,7 @@ module ts { return { isMemberCompletion, + isBuilder, entries: activeCompletionSession.entries }; @@ -2356,7 +2360,7 @@ module ts { function isCompletionListBlocker(previousToken: Node): boolean { var start = new Date().getTime(); var result = isInStringOrRegularExpressionOrTemplateLiteral(previousToken) || - isIdentifierDefinitionLocation(previousToken) || + // isIdentifierDefinitionLocation(previousToken) || isRightOfIllegalDot(previousToken); host.log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; From 85c5b3d30bb6693d3b922a3fbc73d82342a146f6 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Fri, 9 Jan 2015 14:55:06 -0800 Subject: [PATCH 02/21] This fixes #1505 by not showing completionlist when defining a property. --- 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 abe12b0012859..438bb0163f8d9 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2360,7 +2360,7 @@ module ts { function isCompletionListBlocker(previousToken: Node): boolean { var start = new Date().getTime(); var result = isInStringOrRegularExpressionOrTemplateLiteral(previousToken) || - // isIdentifierDefinitionLocation(previousToken) || + isIdentifierDefinitionLocation(previousToken) || isRightOfIllegalDot(previousToken); host.log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; @@ -2450,7 +2450,7 @@ module ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.StaticKeyword: case SyntaxKind.DotDotDotToken: - return containingNodeKind === SyntaxKind.Parameter; + return containingNodeKind === SyntaxKind.Parameter || containingNodeKind === SyntaxKind.PropertyDeclaration; case SyntaxKind.ClassKeyword: case SyntaxKind.ModuleKeyword: From 54bf7adddb5592145b4a75db2430240952081c3f Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 13 Jan 2015 16:55:50 -0800 Subject: [PATCH 03/21] Add test case for completionlist when adding properties to a class. --- ...dentifierDefinitionLocations_properties.ts | 32 +++++++++++++++++++ ...fierDefinitionLocations_varDeclarations.ts | 1 - 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts new file mode 100644 index 0000000000000..f38e9920b828d --- /dev/null +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts @@ -0,0 +1,32 @@ +/// + +////var aa = 1; + +////class A1 { +//// public /*property1*/ +////} + +////class A2 { +//// public a/*property2*/ +////} + +////class A3 { +//// private /*property3*/ +////} + +////class A4 { +//// private a/*property4*/ +////} + +////class A5 { +//// public static /*property5*/ +////} + +////class A6 { +//// public static a/*property6*/ +////} + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.completionListIsEmpty(); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_varDeclarations.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_varDeclarations.ts index 346a102faa8c0..2e85364ce3c2f 100644 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_varDeclarations.ts +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_varDeclarations.ts @@ -11,7 +11,6 @@ ////var a2, a/*varName4*/ -debugger; test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.completionListIsEmpty(); From 1d2554b166792f2887dec7baaa0266900baab606 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Mon, 19 Jan 2015 16:42:35 -0800 Subject: [PATCH 04/21] Fix to make the completionlist work correctly when typing a new generic type + fourslash tests --- src/services/services.ts | 18 ++++++++++- ...tIdentifierDefinitionLocations_Generics.ts | 18 +++++++++++ ...dentifierDefinitionLocations_properties.ts | 32 ------------------- 3 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_Generics.ts delete mode 100644 tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts diff --git a/src/services/services.ts b/src/services/services.ts index 438bb0163f8d9..7d33e56c9a7db 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2366,6 +2366,13 @@ module ts { return result; } + function isCompletionListBuilder(previousToken: Node): boolean { + var start = new Date().getTime(); + + host.log("getCompletionsAtPosition: isCompletionListBuilder: " + (new Date().getTime() - start)); + return true; + } + function isInStringOrRegularExpressionOrTemplateLiteral(previousToken: Node): boolean { if (previousToken.kind === SyntaxKind.StringLiteral || previousToken.kind === SyntaxKind.RegularExpressionLiteral @@ -2432,7 +2439,10 @@ module ts { containingNodeKind === SyntaxKind.VariableDeclarationList || containingNodeKind === SyntaxKind.VariableStatement || containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { foo, | - isFunction(containingNodeKind); + isFunction(containingNodeKind) || + containingNodeKind === SyntaxKind.ClassDeclaration || // class A + +////interface A { + goTo.position(m.position, m.fileName); + verify.completionListIsEmpty(); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts deleted file mode 100644 index f38e9920b828d..0000000000000 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts +++ /dev/null @@ -1,32 +0,0 @@ -/// - -////var aa = 1; - -////class A1 { -//// public /*property1*/ -////} - -////class A2 { -//// public a/*property2*/ -////} - -////class A3 { -//// private /*property3*/ -////} - -////class A4 { -//// private a/*property4*/ -////} - -////class A5 { -//// public static /*property5*/ -////} - -////class A6 { -//// public static a/*property6*/ -////} - -test.markers().forEach((m) => { - goTo.position(m.position, m.fileName); - verify.completionListIsEmpty(); -}); \ No newline at end of file From 8c26917146b61e2eb6fa95b8caa7fba90c50ff4f Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Mon, 19 Jan 2015 16:57:06 -0800 Subject: [PATCH 05/21] Fourslash support for the builder property on completion lists. --- src/harness/fourslash.ts | 12 ++++++++++++ tests/cases/fourslash/fourslash.ts | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index cfc83af76e5f4..21c54d8b0cf77 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -657,6 +657,18 @@ module FourSlash { } } + public verifyCompletionListIsBuilder(negative: boolean) { + var completions = this.getCompletionListAtCaret(); + + if (!completions) { + this.raiseError("Expected completion list"); + } else if ((completions && !completions.isBuilder) && !negative) { + this.raiseError("Expected builder completion entry"); + } else if ((completions && completions.isBuilder) && negative) { + this.raiseError("Un expected the builder completion entry"); + } + } + public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) { var completions = this.getCompletionListAtCaret(); this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 0f45804152102..243629fa347da 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -172,6 +172,10 @@ module FourSlashInterface { FourSlash.currentTestState.verifyCompletionListIsEmpty(this.negative); } + public completionListIsBuilder() { + FourSlash.currentTestState.verifyCompletionListIsBuilder(this.negative); + } + public memberListIsEmpty() { FourSlash.currentTestState.verifyMemberListIsEmpty(this.negative); } From 8bcf376f2b0e5bc51b33d08a7806548820e8e2ad Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Mon, 19 Jan 2015 17:01:39 -0800 Subject: [PATCH 06/21] Clean up --- 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 21c54d8b0cf77..8ffdef428eb0a 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -653,7 +653,6 @@ module FourSlash { Harness.IO.log(errorMsg); this.raiseError("Completion list is not empty at Caret"); - } } @@ -665,7 +664,7 @@ module FourSlash { } else if ((completions && !completions.isBuilder) && !negative) { this.raiseError("Expected builder completion entry"); } else if ((completions && completions.isBuilder) && negative) { - this.raiseError("Un expected the builder completion entry"); + this.raiseError("Un-expected builder completion entry"); } } From 34cc5ccb387cce5fdd4452ef6e45f31cfb722c82 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Mon, 19 Jan 2015 17:29:39 -0800 Subject: [PATCH 07/21] First try at getting logic in for showing the builder. --- src/services/services.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 7d33e56c9a7db..bb98fd7d5dbd8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2320,7 +2320,7 @@ module ts { else { // Get scope members isMemberCompletion = false; - isBuilder = true; + isBuilder = isCompletionListBuilder(previousToken); /// TODO filter meaning based on the current context var symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Import; @@ -2367,10 +2367,19 @@ module ts { } function isCompletionListBuilder(previousToken: Node): boolean { - var start = new Date().getTime(); + if (previousToken) { + var containingNodeKind = previousToken.parent.kind; + // identifiers in method/function calls + // variable declarations + switch (previousToken.kind) { + case SyntaxKind.CommaToken: + return containingNodeKind === SyntaxKind.CallExpression; + case SyntaxKind.OpenParenToken: + return containingNodeKind === SyntaxKind.CallExpression; + } + } - host.log("getCompletionsAtPosition: isCompletionListBuilder: " + (new Date().getTime() - start)); - return true; + return false; } function isInStringOrRegularExpressionOrTemplateLiteral(previousToken: Node): boolean { From 189c8f81fe78034aff625a61c10513b7ea223bbf Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 20 Jan 2015 13:15:21 -0800 Subject: [PATCH 08/21] Support for builder in modules + tests --- src/services/services.ts | 6 ++++-- .../completionListBuilderLocations_Modules.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/completionListBuilderLocations_Modules.ts diff --git a/src/services/services.ts b/src/services/services.ts index bb98fd7d5dbd8..dfca8aea745bc 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2376,6 +2376,10 @@ module ts { return containingNodeKind === SyntaxKind.CallExpression; case SyntaxKind.OpenParenToken: return containingNodeKind === SyntaxKind.CallExpression; + case SyntaxKind.ModuleKeyword: + return true; + case SyntaxKind.DotToken: + return containingNodeKind === SyntaxKind.ModuleDeclaration; } } @@ -2478,7 +2482,6 @@ module ts { return containingNodeKind === SyntaxKind.Parameter || containingNodeKind === SyntaxKind.PropertyDeclaration; case SyntaxKind.ClassKeyword: - case SyntaxKind.ModuleKeyword: case SyntaxKind.EnumKeyword: case SyntaxKind.InterfaceKeyword: case SyntaxKind.FunctionKeyword: @@ -2494,7 +2497,6 @@ module ts { case "class": case "interface": case "enum": - case "module": case "function": case "var": // TODO: add let and const diff --git a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts new file mode 100644 index 0000000000000..a629371d147d9 --- /dev/null +++ b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts @@ -0,0 +1,14 @@ +/// + +////module A/*moduleName1*/ + + +////module A./*moduleName2*/ + + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.not.completionListIsEmpty(); + debugger; + verify.completionListIsBuilder(); +}); \ No newline at end of file From c0a5deadb8cebe570230b7f9f511ecb90d0265bd Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 20 Jan 2015 14:09:45 -0800 Subject: [PATCH 09/21] Delete old modules completion list test. --- ...onListAtIdentifierDefinitionLocations_modules.ts | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_modules.ts diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_modules.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_modules.ts deleted file mode 100644 index 4ebdf029a8998..0000000000000 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_modules.ts +++ /dev/null @@ -1,13 +0,0 @@ -/// - -////var aa = 1; - -////module /*moduleName1*/ - -////module a/*moduleName2*/ - - -test.markers().forEach((m) => { - goTo.position(m.position, m.fileName); - verify.completionListIsEmpty(); -}); From 832af682edf60df74f502957aae6f6c7afc65815 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 20 Jan 2015 15:26:14 -0800 Subject: [PATCH 10/21] Builder in constructor aruguments + tests. --- src/harness/fourslash.ts | 6 ++---- src/services/services.ts | 11 +++++++---- ...dentifierDefinitionLocations_parameters.ts | 19 ++++++------------- .../completionListBuilderLocations_Modules.ts | 1 - tests/cases/fourslash/fourslash.ts | 2 +- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8ffdef428eb0a..232411d03d939 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -656,12 +656,10 @@ module FourSlash { } } - public verifyCompletionListIsBuilder(negative: boolean) { + public verifyCompletionListHasBuilder(negative: boolean) { var completions = this.getCompletionListAtCaret(); - if (!completions) { - this.raiseError("Expected completion list"); - } else if ((completions && !completions.isBuilder) && !negative) { + if ((completions && !completions.isBuilder) && !negative) { this.raiseError("Expected builder completion entry"); } else if ((completions && completions.isBuilder) && negative) { this.raiseError("Un-expected builder completion entry"); diff --git a/src/services/services.ts b/src/services/services.ts index 7ebf21abc1d1b..bbd297a3940d8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2376,9 +2376,11 @@ module ts { // variable declarations switch (previousToken.kind) { case SyntaxKind.CommaToken: - return containingNodeKind === SyntaxKind.CallExpression; + return containingNodeKind === SyntaxKind.CallExpression + || containingNodeKind === SyntaxKind.Constructor; case SyntaxKind.OpenParenToken: - return containingNodeKind === SyntaxKind.CallExpression; + return containingNodeKind === SyntaxKind.CallExpression + || containingNodeKind === SyntaxKind.Constructor; case SyntaxKind.ModuleKeyword: return true; case SyntaxKind.DotToken: @@ -2435,7 +2437,6 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.CallSignature: @@ -2482,7 +2483,9 @@ module ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.StaticKeyword: case SyntaxKind.DotDotDotToken: - return containingNodeKind === SyntaxKind.Parameter || containingNodeKind === SyntaxKind.PropertyDeclaration; + return containingNodeKind === SyntaxKind.Parameter + || containingNodeKind === SyntaxKind.PropertyDeclaration + || containingNodeKind === SyntaxKind.Constructor; case SyntaxKind.ClassKeyword: case SyntaxKind.EnumKeyword: diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts index 0fd66e9d0916a..f5a82cdcc5730 100644 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts @@ -10,26 +10,19 @@ ////function testFunction(a, b/*parameterName4*/ -////class bar1{ constructor(/*constructorParamter1*/ +////class bar5{ constructor(public /*constructorParamter1*/ -////class bar2{ constructor(a/*constructorParamter2*/ +////class bar6{ constructor(public a/*constructorParamter2*/ -////class bar3{ constructor(a, /*constructorParamter3*/ +////class bar7{ constructor(private a/*constructorParamter3*/ -////class bar4{ constructor(a, b/*constructorParamter4*/ +////class bar8{ constructor(.../*constructorParamter4*/ -////class bar5{ constructor(public /*constructorParamter5*/ - -////class bar6{ constructor(public a/*constructorParamter6*/ - -////class bar7{ constructor(private a/*constructorParamter7*/ - -////class bar8{ constructor(.../*constructorParamter8*/ - -////class bar9{ constructor(...a/*constructorParamter9*/ +////class bar9{ constructor(...a/*constructorParamter5*/ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.completionListIsEmpty(); + verify.not.completionListIsBuilder(); }); diff --git a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts index a629371d147d9..d39c52318cea5 100644 --- a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts +++ b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts @@ -9,6 +9,5 @@ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.not.completionListIsEmpty(); - debugger; verify.completionListIsBuilder(); }); \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 243629fa347da..71e3d723e20b8 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -173,7 +173,7 @@ module FourSlashInterface { } public completionListIsBuilder() { - FourSlash.currentTestState.verifyCompletionListIsBuilder(this.negative); + FourSlash.currentTestState.verifyCompletionListHasBuilder(this.negative); } public memberListIsEmpty() { From cb4a1109d63dee7798ce9da466d26c503fcd7952 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 20 Jan 2015 15:51:24 -0800 Subject: [PATCH 11/21] test cases for builder in constructor --- ...dentifierDefinitionLocations_parameters.ts | 1 - ...mpletionListBuilderLocations_parameters.ts | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionListBuilderLocations_parameters.ts diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts index f5a82cdcc5730..cb1b75925181b 100644 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts @@ -24,5 +24,4 @@ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.completionListIsEmpty(); - verify.not.completionListIsBuilder(); }); diff --git a/tests/cases/fourslash/completionListBuilderLocations_parameters.ts b/tests/cases/fourslash/completionListBuilderLocations_parameters.ts new file mode 100644 index 0000000000000..8d8d89cbdc71e --- /dev/null +++ b/tests/cases/fourslash/completionListBuilderLocations_parameters.ts @@ -0,0 +1,22 @@ +/// + +////var aa = 1; + +////class bar1{ constructor(/*constructorParamter1*/ + +////class bar2{ constructor(a/*constructorParamter2*/ + +////class bar3{ constructor(a, /*constructorParamter3*/ + +////class bar4{ constructor(a, b/*constructorParamter4*/ + +////class bar6{ constructor(public a, /*constructorParamter5*/ + +////class bar7{ constructor(private a, /*constructorParamter6*/ + + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.not.completionListIsEmpty(); + verify.completionListIsBuilder(); +}); From e4a24e97a3b6063019049f44352bbe68d297c998 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 21 Jan 2015 17:43:13 -0800 Subject: [PATCH 12/21] Builder implementation for properties and parameters inlcuding tests. --- src/services/services.ts | 83 +++++++++++-------- ...dentifierDefinitionLocations_parameters.ts | 8 +- ...dentifierDefinitionLocations_properties.ts | 38 +++++++++ ...mpletionListBuilderLocations_properties.ts | 16 ++++ 4 files changed, 109 insertions(+), 36 deletions(-) create mode 100644 tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts create mode 100644 tests/cases/fourslash/completionListBuilderLocations_properties.ts diff --git a/src/services/services.ts b/src/services/services.ts index bbd297a3940d8..0bfbd46f217db 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -407,7 +407,7 @@ module ts { return pos + name.length < end && sourceFile.text.substr(pos, name.length) === name && (isWhiteSpace(sourceFile.text.charCodeAt(pos + name.length)) || - isLineBreak(sourceFile.text.charCodeAt(pos + name.length))); + isLineBreak(sourceFile.text.charCodeAt(pos + name.length))); } function isParamTag(pos: number, end: number, sourceFile: SourceFile) { @@ -798,7 +798,7 @@ module ts { if ((node).name) { namedDeclarations.push(node); } - // fall through + // fall through case SyntaxKind.Constructor: case SyntaxKind.VariableStatement: case SyntaxKind.VariableDeclarationList: @@ -819,7 +819,7 @@ module ts { if (!(node.flags & NodeFlags.AccessibilityModifier)) { break; } - // fall through + // fall through case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: if (isBindingPattern((node).name)) { @@ -852,13 +852,13 @@ module ts { // export interface LanguageServiceHost extends Logger { getCompilationSettings(): CompilerOptions; - getNewLine?(): string; + getNewLine? (): string; getScriptFileNames(): string[]; getScriptVersion(fileName: string): string; getScriptIsOpen(fileName: string): boolean; getScriptSnapshot(fileName: string): IScriptSnapshot; - getLocalizedDiagnosticMessages?(): any; - getCancellationToken?(): CancellationToken; + getLocalizedDiagnosticMessages? (): any; + getCancellationToken? (): CancellationToken; getCurrentDirectory(): string; getDefaultLibFilename(options: CompilerOptions): string; } @@ -890,7 +890,7 @@ module ts { getRenameInfo(fileName: string, position: number): RenameInfo; findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[]; - + getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; @@ -913,7 +913,7 @@ module ts { dispose(): void; } - + export interface ClassifiedSpan { textSpan: TextSpan; classificationType: string; // ClassificationTypeNames @@ -1024,7 +1024,7 @@ module ts { text: string; kind: string; } - + export interface QuickInfo { kind: string; kindModifiers: string; @@ -1542,7 +1542,7 @@ module ts { sourceFile.version = version; sourceFile.isOpen = isOpen; sourceFile.scriptSnapshot = scriptSnapshot; - } + } export function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, isOpen: boolean, setNodeParents: boolean): SourceFile { var sourceFile = createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); @@ -1862,7 +1862,7 @@ module ts { // The position has to be: 1. in the leading trivia (before token.getStart()), and 2. within a comment return position <= token.getStart(sourceFile) && (isInsideCommentRange(getTrailingCommentRanges(sourceFile.text, token.getFullStart())) || - isInsideCommentRange(getLeadingCommentRanges(sourceFile.text, token.getFullStart()))); + isInsideCommentRange(getLeadingCommentRanges(sourceFile.text, token.getFullStart()))); function isInsideCommentRange(comments: CommentRange[]): boolean { return forEach(comments, comment => { @@ -1904,7 +1904,7 @@ module ts { } // A cache of completion entries for keywords, these do not change between sessions - var keywordCompletions:CompletionEntry[] = []; + var keywordCompletions: CompletionEntry[] = []; for (var i = SyntaxKind.FirstKeyword; i <= SyntaxKind.LastKeyword; i++) { keywordCompletions.push({ name: tokenToString(i), @@ -2372,8 +2372,6 @@ module ts { function isCompletionListBuilder(previousToken: Node): boolean { if (previousToken) { var containingNodeKind = previousToken.parent.kind; - // identifiers in method/function calls - // variable declarations switch (previousToken.kind) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.CallExpression @@ -2385,6 +2383,20 @@ module ts { return true; case SyntaxKind.DotToken: return containingNodeKind === SyntaxKind.ModuleDeclaration; + case SyntaxKind.OpenBraceToken: + return containingNodeKind === SyntaxKind.ClassDeclaration; + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + return containingNodeKind === SyntaxKind.PropertyDeclaration; + } + + // Previous token may have been a keyword that was converted to an identifier. + switch (previousToken.getText()) { + case "public": + case "protected": + case "private": + return true; } } @@ -2457,16 +2469,16 @@ module ts { containingNodeKind === SyntaxKind.VariableStatement || containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { foo, | isFunction(containingNodeKind) || - containingNodeKind === SyntaxKind.ClassDeclaration || // class A 0 && !classifyKeywordsInGenerics) { // If it looks like we're could be in something generic, don't classify this // as a keyword. We may just get overwritten by the syntactic classifier, diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts index cb1b75925181b..10293c41a641e 100644 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts @@ -14,11 +14,13 @@ ////class bar6{ constructor(public a/*constructorParamter2*/ -////class bar7{ constructor(private a/*constructorParamter3*/ +////class bar7{ constructor(protected a/*constructorParamter3*/ -////class bar8{ constructor(.../*constructorParamter4*/ +////class bar8{ constructor(private a/*constructorParamter4*/ -////class bar9{ constructor(...a/*constructorParamter5*/ +////class bar9{ constructor(.../*constructorParamter5*/ + +////class bar10{ constructor(...a/*constructorParamter6*/ test.markers().forEach((m) => { diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts new file mode 100644 index 0000000000000..f15868d21586a --- /dev/null +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts @@ -0,0 +1,38 @@ +/// + +////var aa = 1; + +////class A1 { +//// /*property1*/ +////} + +////class A2 { +//// p/*property2*/ +////} + +////class A3 { +//// public s/*property3*/ +////} + +////class A4 { +//// a/*property4*/ +////} + +////class A5 { +//// public a/*property5*/ +////} + +////class A6 { +//// protected a/*property6*/ +////} + +////class A7 { +//// private a/*property7*/ +////} + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + debugger; + verify.not.completionListIsEmpty(); + verify.completionListIsBuilder(); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListBuilderLocations_properties.ts b/tests/cases/fourslash/completionListBuilderLocations_properties.ts new file mode 100644 index 0000000000000..287ffd6746b74 --- /dev/null +++ b/tests/cases/fourslash/completionListBuilderLocations_properties.ts @@ -0,0 +1,16 @@ +/// + +////var aa = 1; + +////class A1 { +//// public static /*property1*/ +////} + +////class A2 { +//// public static a/*property2*/ +////} + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.completionListIsEmpty(); +}); \ No newline at end of file From 54c9e569608467ab7086666e91ab773e04ae5ce8 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 22 Jan 2015 12:42:48 -0800 Subject: [PATCH 13/21] White space fixes --- src/services/services.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 0bfbd46f217db..245ab05afa777 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -852,13 +852,13 @@ module ts { // export interface LanguageServiceHost extends Logger { getCompilationSettings(): CompilerOptions; - getNewLine? (): string; + getNewLine?(): string; getScriptFileNames(): string[]; getScriptVersion(fileName: string): string; getScriptIsOpen(fileName: string): boolean; getScriptSnapshot(fileName: string): IScriptSnapshot; - getLocalizedDiagnosticMessages? (): any; - getCancellationToken? (): CancellationToken; + getLocalizedDiagnosticMessages?(): any; + getCancellationToken?(): CancellationToken; getCurrentDirectory(): string; getDefaultLibFilename(options: CompilerOptions): string; } From 3bb817f00086d404cdd95a936cf6b39bb9c0184a Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 22 Jan 2015 12:48:27 -0800 Subject: [PATCH 14/21] Clean up after code review, white space etc. --- src/services/services.ts | 69 +++++++++---------- ...dentifierDefinitionLocations_properties.ts | 1 - 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 245ab05afa777..662ae7df102ae 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2485,7 +2485,7 @@ module ts { return containingNodeKind === SyntaxKind.PropertySignature && previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration; // interface a { f; | - case SyntaxKind.FirstBinaryOperator: + case SyntaxKind.LessThanToken: return containingNodeKind === SyntaxKind.ClassDeclaration || // class A< | containingNodeKind === SyntaxKind.FunctionDeclaration || // function A< | containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A< | @@ -5150,7 +5150,6 @@ module ts { var childNodes = parentElement.getChildren(sourceFile); for (var i = 0, n = childNodes.length; i < n; i++) { - 33 var current = childNodes[i]; if (current.kind === matchKind) { @@ -5175,14 +5174,14 @@ module ts { function getMatchingTokenKind(token: Node): ts.SyntaxKind { switch (token.kind) { - case ts.SyntaxKind.OpenBraceToken: return ts.SyntaxKind.CloseBraceToken - case ts.SyntaxKind.OpenParenToken: return ts.SyntaxKind.CloseParenToken; - case ts.SyntaxKind.OpenBracketToken: return ts.SyntaxKind.CloseBracketToken; - case ts.SyntaxKind.LessThanToken: return ts.SyntaxKind.GreaterThanToken; - case ts.SyntaxKind.CloseBraceToken: return ts.SyntaxKind.OpenBraceToken - case ts.SyntaxKind.CloseParenToken: return ts.SyntaxKind.OpenParenToken; - case ts.SyntaxKind.CloseBracketToken: return ts.SyntaxKind.OpenBracketToken; - case ts.SyntaxKind.GreaterThanToken: return ts.SyntaxKind.LessThanToken; + case ts.SyntaxKind.OpenBraceToken: return ts.SyntaxKind.CloseBraceToken + case ts.SyntaxKind.OpenParenToken: return ts.SyntaxKind.CloseParenToken; + case ts.SyntaxKind.OpenBracketToken: return ts.SyntaxKind.CloseBracketToken; + case ts.SyntaxKind.LessThanToken: return ts.SyntaxKind.GreaterThanToken; + case ts.SyntaxKind.CloseBraceToken: return ts.SyntaxKind.OpenBraceToken + case ts.SyntaxKind.CloseParenToken: return ts.SyntaxKind.OpenParenToken; + case ts.SyntaxKind.CloseBracketToken: return ts.SyntaxKind.OpenBracketToken; + case ts.SyntaxKind.GreaterThanToken: return ts.SyntaxKind.LessThanToken; } return undefined; @@ -5586,41 +5585,41 @@ module ts { if (!isTrivia(token)) { if ((token === SyntaxKind.SlashToken || token === SyntaxKind.SlashEqualsToken) && !noRegexTable[lastNonTriviaToken]) { - if (scanner.reScanSlashToken() === SyntaxKind.RegularExpressionLiteral) { - token = SyntaxKind.RegularExpressionLiteral; - } + if (scanner.reScanSlashToken() === SyntaxKind.RegularExpressionLiteral) { + token = SyntaxKind.RegularExpressionLiteral; + } } else if (lastNonTriviaToken === SyntaxKind.DotToken && isKeyword(token)) { - token = SyntaxKind.Identifier; + token = SyntaxKind.Identifier; } else if (isKeyword(lastNonTriviaToken) && isKeyword(token) && !canFollow(lastNonTriviaToken, token)) { - // We have two keywords in a row. Only treat the second as a keyword if - // it's a sequence that could legally occur in the language. Otherwise - // treat it as an identifier. This way, if someone writes "private var" - // we recognize that 'var' is actually an identifier here. - token = SyntaxKind.Identifier; + // We have two keywords in a row. Only treat the second as a keyword if + // it's a sequence that could legally occur in the language. Otherwise + // treat it as an identifier. This way, if someone writes "private var" + // we recognize that 'var' is actually an identifier here. + token = SyntaxKind.Identifier; } else if (lastNonTriviaToken === SyntaxKind.Identifier && - token === SyntaxKind.LessThanToken) { - // Could be the start of something generic. Keep track of that by bumping - // up the current count of generic contexts we may be in. - angleBracketStack++; + token === SyntaxKind.LessThanToken) { + // Could be the start of something generic. Keep track of that by bumping + // up the current count of generic contexts we may be in. + angleBracketStack++; } else if (token === SyntaxKind.GreaterThanToken && angleBracketStack > 0) { - // If we think we're currently in something generic, then mark that that - // generic entity is complete. - angleBracketStack--; + // If we think we're currently in something generic, then mark that that + // generic entity is complete. + angleBracketStack--; } else if (token === SyntaxKind.AnyKeyword || - token === SyntaxKind.StringKeyword || - token === SyntaxKind.NumberKeyword || - token === SyntaxKind.BooleanKeyword) { - if (angleBracketStack > 0 && !classifyKeywordsInGenerics) { - // If it looks like we're could be in something generic, don't classify this - // as a keyword. We may just get overwritten by the syntactic classifier, - // causing a noisy experience for the user. - token = SyntaxKind.Identifier; - } + token === SyntaxKind.StringKeyword || + token === SyntaxKind.NumberKeyword || + token === SyntaxKind.BooleanKeyword) { + if (angleBracketStack > 0 && !classifyKeywordsInGenerics) { + // If it looks like we're could be in something generic, don't classify this + // as a keyword. We may just get overwritten by the syntactic classifier, + // causing a noisy experience for the user. + token = SyntaxKind.Identifier; + } } lastNonTriviaToken = token; diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts index f15868d21586a..e709fdfe4ef2c 100644 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts @@ -32,7 +32,6 @@ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); - debugger; verify.not.completionListIsEmpty(); verify.completionListIsBuilder(); }); \ No newline at end of file From 3b0f8f67dd78a6ee41e3f8d55a662811e303d728 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 3 Feb 2015 11:37:52 -0800 Subject: [PATCH 15/21] Added comments and some additional cases --- src/services/services.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 0d6dc073d38d9..b29c0fc84d3ba 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2388,21 +2388,21 @@ module ts { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case SyntaxKind.CommaToken: - return containingNodeKind === SyntaxKind.CallExpression - || containingNodeKind === SyntaxKind.Constructor; + return containingNodeKind === SyntaxKind.CallExpression // func( a, | + || containingNodeKind === SyntaxKind.Constructor; // constructor( a, | case SyntaxKind.OpenParenToken: - return containingNodeKind === SyntaxKind.CallExpression - || containingNodeKind === SyntaxKind.Constructor; - case SyntaxKind.ModuleKeyword: + return containingNodeKind === SyntaxKind.CallExpression // func( | + || containingNodeKind === SyntaxKind.Constructor; // constructor( | + case SyntaxKind.ModuleKeyword: // module | return true; case SyntaxKind.DotToken: - return containingNodeKind === SyntaxKind.ModuleDeclaration; + return containingNodeKind === SyntaxKind.ModuleDeclaration; // module A.| case SyntaxKind.OpenBraceToken: - return containingNodeKind === SyntaxKind.ClassDeclaration; + return containingNodeKind === SyntaxKind.ClassDeclaration; // class A{ | case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: - return containingNodeKind === SyntaxKind.PropertyDeclaration; + return containingNodeKind === SyntaxKind.PropertyDeclaration; // class A{ public | } // Previous token may have been a keyword that was converted to an identifier. @@ -2493,11 +2493,13 @@ module ts { case SyntaxKind.OpenBraceToken: return containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { | - containingNodeKind === SyntaxKind.InterfaceDeclaration; // interface a { | + containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface a { | + containingNodeKind === SyntaxKind.TypeLiteral; // var x : { | case SyntaxKind.SemicolonToken: return containingNodeKind === SyntaxKind.PropertySignature && - previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration; // interface a { f; | + (previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration || // interface a { f; | + previousToken.parent.parent.kind === SyntaxKind.TypeLiteral); // var x : { a; | case SyntaxKind.LessThanToken: return containingNodeKind === SyntaxKind.ClassDeclaration || // class A< | @@ -2506,9 +2508,10 @@ module ts { isFunction(containingNodeKind); case SyntaxKind.StaticKeyword: + return containingNodeKind === SyntaxKind.PropertyDeclaration; + case SyntaxKind.DotDotDotToken: return containingNodeKind === SyntaxKind.Parameter - || containingNodeKind === SyntaxKind.PropertyDeclaration || containingNodeKind === SyntaxKind.Constructor; case SyntaxKind.PublicKeyword: From 62bc9df89952e7a035a3d6248b4b018e83cc699c Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 3 Feb 2015 14:26:32 -0800 Subject: [PATCH 16/21] Support for destructuring + test case. --- src/services/services.ts | 14 +++++++++++--- ...tIdentifierDefinitionLocations_destructuring.ts | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_destructuring.ts diff --git a/src/services/services.ts b/src/services/services.ts index c43f67f94b752..143fd19dd7544 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2515,7 +2515,14 @@ module ts { isFunction(containingNodeKind) || containingNodeKind === SyntaxKind.ClassDeclaration || // class A + +//// var [x/*variable1*/ + +//// var [x, y/*variable2*/ + +//// var [./*variable3*/ + +//// var [x, ...z/*variable4*/ + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.completionListIsEmpty(); +}); From 93f33211ba00819cbc4a60609978d5f7fcb9519a Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 3 Feb 2015 14:53:51 -0800 Subject: [PATCH 17/21] Update API sample tests. --- tests/baselines/reference/APISample_compile.js | 1 + tests/baselines/reference/APISample_compile.types | 3 +++ tests/baselines/reference/APISample_linter.js | 1 + tests/baselines/reference/APISample_linter.types | 3 +++ tests/baselines/reference/APISample_transform.js | 1 + tests/baselines/reference/APISample_transform.types | 3 +++ tests/baselines/reference/APISample_watcher.js | 1 + tests/baselines/reference/APISample_watcher.types | 3 +++ 8 files changed, 16 insertions(+) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index f70ee02415af5..e1c97ef4b8e91 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1697,6 +1697,7 @@ declare module "typescript" { } interface CompletionInfo { isMemberCompletion: boolean; + isBuilder: boolean; entries: CompletionEntry[]; } interface CompletionEntry { diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 090c42a72165c..b4aa0f48627d3 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -5457,6 +5457,9 @@ declare module "typescript" { isMemberCompletion: boolean; >isMemberCompletion : boolean + isBuilder: boolean; +>isBuilder : boolean + entries: CompletionEntry[]; >entries : CompletionEntry[] >CompletionEntry : CompletionEntry diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index b3905862c67ac..005a6c38e6e0b 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1726,6 +1726,7 @@ declare module "typescript" { } interface CompletionInfo { isMemberCompletion: boolean; + isBuilder: boolean; entries: CompletionEntry[]; } interface CompletionEntry { diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 5f613ec140cfe..034d913a329e0 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -5587,6 +5587,9 @@ declare module "typescript" { isMemberCompletion: boolean; >isMemberCompletion : boolean + isBuilder: boolean; +>isBuilder : boolean + entries: CompletionEntry[]; >entries : CompletionEntry[] >CompletionEntry : CompletionEntry diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 06546d2fdbcb9..88a7fcacaa01d 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1727,6 +1727,7 @@ declare module "typescript" { } interface CompletionInfo { isMemberCompletion: boolean; + isBuilder: boolean; entries: CompletionEntry[]; } interface CompletionEntry { diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index f92c2f36774fb..25a363f315ecc 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -5535,6 +5535,9 @@ declare module "typescript" { isMemberCompletion: boolean; >isMemberCompletion : boolean + isBuilder: boolean; +>isBuilder : boolean + entries: CompletionEntry[]; >entries : CompletionEntry[] >CompletionEntry : CompletionEntry diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 9a7064117bfb2..d01e440dc1f49 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1764,6 +1764,7 @@ declare module "typescript" { } interface CompletionInfo { isMemberCompletion: boolean; + isBuilder: boolean; entries: CompletionEntry[]; } interface CompletionEntry { diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 938db86d09e66..cd2036e2e251c 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -5713,6 +5713,9 @@ declare module "typescript" { isMemberCompletion: boolean; >isMemberCompletion : boolean + isBuilder: boolean; +>isBuilder : boolean + entries: CompletionEntry[]; >entries : CompletionEntry[] >CompletionEntry : CompletionEntry From d9f678fd6d5e4d5b49e50ad15ed7f727a7f7b0a7 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 3 Feb 2015 16:31:53 -0800 Subject: [PATCH 18/21] Rename the isBuilder property to something more meaningful. --- src/harness/fourslash.ts | 6 +++--- src/services/services.ts | 10 +++++----- tests/baselines/reference/APISample_compile.js | 2 +- tests/baselines/reference/APISample_compile.types | 4 ++-- tests/baselines/reference/APISample_linter.js | 2 +- tests/baselines/reference/APISample_linter.types | 4 ++-- tests/baselines/reference/APISample_transform.js | 2 +- tests/baselines/reference/APISample_transform.types | 4 ++-- tests/baselines/reference/APISample_watcher.js | 2 +- tests/baselines/reference/APISample_watcher.types | 4 ++-- ...onListAtIdentifierDefinitionLocations_properties.ts | 2 +- .../completionListBuilderLocations_Modules.ts | 2 +- .../completionListBuilderLocations_parameters.ts | 2 +- tests/cases/fourslash/fourslash.ts | 4 ++-- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 7f11c98ce8d21..1e5810926385c 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -665,12 +665,12 @@ module FourSlash { } } - public verifyCompletionListHasBuilder(negative: boolean) { + public verifyCompletionListAllowsNewIdentifier(negative: boolean) { var completions = this.getCompletionListAtCaret(); - if ((completions && !completions.isBuilder) && !negative) { + if ((completions && !completions.isNewIdentifierLocation) && !negative) { this.raiseError("Expected builder completion entry"); - } else if ((completions && completions.isBuilder) && negative) { + } else if ((completions && completions.isNewIdentifierLocation) && negative) { this.raiseError("Un-expected builder completion entry"); } } diff --git a/src/services/services.ts b/src/services/services.ts index 143fd19dd7544..b4a622297c7f0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1072,7 +1072,7 @@ module ts { export interface CompletionInfo { isMemberCompletion: boolean; - isBuilder: boolean; + isNewIdentifierLocation: boolean; // true when the current location also allows for a new identifier entries: CompletionEntry[]; } @@ -2314,7 +2314,7 @@ module ts { // Right of dot member completion list var symbols: Symbol[] = []; var isMemberCompletion = true; - var isBuilder = false; + var isNewIdentifierLocation = false; if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression) { var symbol = typeInfoResolver.getSymbolAtLocation(node); @@ -2367,7 +2367,7 @@ module ts { else { // Get scope members isMemberCompletion = false; - isBuilder = isCompletionListBuilder(previousToken); + isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); /// TODO filter meaning based on the current context var symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Import; @@ -2385,7 +2385,7 @@ module ts { return { isMemberCompletion, - isBuilder, + isNewIdentifierLocation, entries: activeCompletionSession.entries }; @@ -2413,7 +2413,7 @@ module ts { return result; } - function isCompletionListBuilder(previousToken: Node): boolean { + function isNewIdentifierDefinitionLocation(previousToken: Node): boolean { if (previousToken) { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index e1c97ef4b8e91..d6e98c6130215 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1697,7 +1697,7 @@ declare module "typescript" { } interface CompletionInfo { isMemberCompletion: boolean; - isBuilder: boolean; + isNewIdentifierLocation: boolean; entries: CompletionEntry[]; } interface CompletionEntry { diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index b4aa0f48627d3..e70d876d2a97a 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -5457,8 +5457,8 @@ declare module "typescript" { isMemberCompletion: boolean; >isMemberCompletion : boolean - isBuilder: boolean; ->isBuilder : boolean + isNewIdentifierLocation: boolean; +>isNewIdentifierLocation : boolean entries: CompletionEntry[]; >entries : CompletionEntry[] diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 005a6c38e6e0b..bd71ce6270dd4 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1726,7 +1726,7 @@ declare module "typescript" { } interface CompletionInfo { isMemberCompletion: boolean; - isBuilder: boolean; + isNewIdentifierLocation: boolean; entries: CompletionEntry[]; } interface CompletionEntry { diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 034d913a329e0..cceb4142a9602 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -5587,8 +5587,8 @@ declare module "typescript" { isMemberCompletion: boolean; >isMemberCompletion : boolean - isBuilder: boolean; ->isBuilder : boolean + isNewIdentifierLocation: boolean; +>isNewIdentifierLocation : boolean entries: CompletionEntry[]; >entries : CompletionEntry[] diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 88a7fcacaa01d..2402d98dc58a2 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1727,7 +1727,7 @@ declare module "typescript" { } interface CompletionInfo { isMemberCompletion: boolean; - isBuilder: boolean; + isNewIdentifierLocation: boolean; entries: CompletionEntry[]; } interface CompletionEntry { diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 25a363f315ecc..7c159c1a9dd07 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -5535,8 +5535,8 @@ declare module "typescript" { isMemberCompletion: boolean; >isMemberCompletion : boolean - isBuilder: boolean; ->isBuilder : boolean + isNewIdentifierLocation: boolean; +>isNewIdentifierLocation : boolean entries: CompletionEntry[]; >entries : CompletionEntry[] diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index d01e440dc1f49..3113cc4e86dee 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1764,7 +1764,7 @@ declare module "typescript" { } interface CompletionInfo { isMemberCompletion: boolean; - isBuilder: boolean; + isNewIdentifierLocation: boolean; entries: CompletionEntry[]; } interface CompletionEntry { diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index cd2036e2e251c..84fd5065409f8 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -5713,8 +5713,8 @@ declare module "typescript" { isMemberCompletion: boolean; >isMemberCompletion : boolean - isBuilder: boolean; ->isBuilder : boolean + isNewIdentifierLocation: boolean; +>isNewIdentifierLocation : boolean entries: CompletionEntry[]; >entries : CompletionEntry[] diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts index e709fdfe4ef2c..58fdc1d23421b 100644 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_properties.ts @@ -33,5 +33,5 @@ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.not.completionListIsEmpty(); - verify.completionListIsBuilder(); + verify.completionListAllowsNewIdentifier(); }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts index d39c52318cea5..eac7085ab6668 100644 --- a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts +++ b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts @@ -9,5 +9,5 @@ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.not.completionListIsEmpty(); - verify.completionListIsBuilder(); + verify.completionListAllowsNewIdentifier(); }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListBuilderLocations_parameters.ts b/tests/cases/fourslash/completionListBuilderLocations_parameters.ts index 8d8d89cbdc71e..4bc60180efc4d 100644 --- a/tests/cases/fourslash/completionListBuilderLocations_parameters.ts +++ b/tests/cases/fourslash/completionListBuilderLocations_parameters.ts @@ -18,5 +18,5 @@ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.not.completionListIsEmpty(); - verify.completionListIsBuilder(); + verify.completionListAllowsNewIdentifier(); }); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 442d62c0b4d17..267f2c1434120 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -172,8 +172,8 @@ module FourSlashInterface { FourSlash.currentTestState.verifyCompletionListIsEmpty(this.negative); } - public completionListIsBuilder() { - FourSlash.currentTestState.verifyCompletionListHasBuilder(this.negative); + public completionListAllowsNewIdentifier() { + FourSlash.currentTestState.verifyCompletionListAllowsNewIdentifier(this.negative); } public memberListIsEmpty() { From e233da0fd6ae9abe2147e0d6d367f6396be2654d Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 3 Feb 2015 18:03:40 -0800 Subject: [PATCH 19/21] Parameter destructuring + tests --- src/services/services.ts | 10 ++++++---- ...istAtIdentifierDefinitionLocations_destructuring.ts | 8 ++++++++ .../completionListBuilderLocations_parameters.ts | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index b4a622297c7f0..126cf578c1ca2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2515,8 +2515,9 @@ module ts { isFunction(containingNodeKind) || containingNodeKind === SyntaxKind.ClassDeclaration || // class A { goTo.position(m.position, m.fileName); verify.completionListIsEmpty(); diff --git a/tests/cases/fourslash/completionListBuilderLocations_parameters.ts b/tests/cases/fourslash/completionListBuilderLocations_parameters.ts index 4bc60180efc4d..12dba953d3db8 100644 --- a/tests/cases/fourslash/completionListBuilderLocations_parameters.ts +++ b/tests/cases/fourslash/completionListBuilderLocations_parameters.ts @@ -19,4 +19,4 @@ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.not.completionListIsEmpty(); verify.completionListAllowsNewIdentifier(); -}); +}); \ No newline at end of file From 6e35f79412aa6bb43e714f8b19fcf2ec3c50887e Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 4 Feb 2015 14:03:26 -0800 Subject: [PATCH 20/21] Add builder support for variable declarations + test cases. --- src/services/services.ts | 18 ++++++++++++++---- ...istBuilderLocations_VariableDeclarations.ts | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/completionListBuilderLocations_VariableDeclarations.ts diff --git a/src/services/services.ts b/src/services/services.ts index 126cf578c1ca2..5dd32e66bbe63 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2418,17 +2418,27 @@ module ts { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case SyntaxKind.CommaToken: - return containingNodeKind === SyntaxKind.CallExpression // func( a, | - || containingNodeKind === SyntaxKind.Constructor; // constructor( a, | + return containingNodeKind === SyntaxKind.CallExpression // func( a, | + || containingNodeKind === SyntaxKind.Constructor // constructor( a, | + || previousToken.parent.parent.parent.kind === SyntaxKind.VariableDeclaration; // var x = (a, b| <- this can be a lambda expression + case SyntaxKind.OpenParenToken: - return containingNodeKind === SyntaxKind.CallExpression // func( | - || containingNodeKind === SyntaxKind.Constructor; // constructor( | + return containingNodeKind === SyntaxKind.CallExpression // func( | + || containingNodeKind === SyntaxKind.Constructor // constructor( | + || previousToken.parent.parent.kind === SyntaxKind.VariableDeclaration; // var x = (a| <- this can be a lambda expression + case SyntaxKind.ModuleKeyword: // module | return true; + case SyntaxKind.DotToken: return containingNodeKind === SyntaxKind.ModuleDeclaration; // module A.| + case SyntaxKind.OpenBraceToken: return containingNodeKind === SyntaxKind.ClassDeclaration; // class A{ | + + case SyntaxKind.EqualsToken: + return containingNodeKind === SyntaxKind.VariableDeclaration; // var x = a| <- this can be lambda expression + case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: diff --git a/tests/cases/fourslash/completionListBuilderLocations_VariableDeclarations.ts b/tests/cases/fourslash/completionListBuilderLocations_VariableDeclarations.ts new file mode 100644 index 0000000000000..5c222f901f6ac --- /dev/null +++ b/tests/cases/fourslash/completionListBuilderLocations_VariableDeclarations.ts @@ -0,0 +1,18 @@ +/// + +//// var x = a/*var1*/ + +//// var x = (b/*var2*/ + +//// var x = (c, d/*var3*/ + +//// var y : any = "", x = a/*var4*/ + +//// var y : any = "", x = (a/*var5*/ + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.completionListAllowsNewIdentifier(); +}); + + From 40824ed8a58bede88cc9ab59b5e29ff70d4597a3 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 4 Feb 2015 16:40:22 -0800 Subject: [PATCH 21/21] Added templates, assignement and arrays + tests. --- src/services/services.ts | 35 +++++++++++++++---- ...stBuilderLocations_VariableDeclarations.ts | 24 ++++++++++--- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index b58e28a8b2658..677af16bdc4de 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2370,6 +2370,7 @@ module ts { if (containingObjectLiteral) { // Object literal expression, look up possible property names from contextual type isMemberCompletion = true; + isNewIdentifierLocation = true; var contextualType = typeInfoResolver.getContextualType(containingObjectLiteral); if (!contextualType) { @@ -2405,6 +2406,7 @@ module ts { return { isMemberCompletion, isNewIdentifierLocation, + isBuilder : isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation entries: activeCompletionSession.entries }; @@ -2438,13 +2440,20 @@ module ts { switch (previousToken.kind) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.CallExpression // func( a, | - || containingNodeKind === SyntaxKind.Constructor // constructor( a, | - || previousToken.parent.parent.parent.kind === SyntaxKind.VariableDeclaration; // var x = (a, b| <- this can be a lambda expression + || containingNodeKind === SyntaxKind.Constructor // constructor( a, | public, protected, private keywords are allowed here, so show completion + || containingNodeKind === SyntaxKind.NewExpression // new C(a, | + || containingNodeKind === SyntaxKind.ArrayLiteralExpression // [a, | + || containingNodeKind === SyntaxKind.BinaryExpression; // var x = (a, | + case SyntaxKind.OpenParenToken: - return containingNodeKind === SyntaxKind.CallExpression // func( | - || containingNodeKind === SyntaxKind.Constructor // constructor( | - || previousToken.parent.parent.kind === SyntaxKind.VariableDeclaration; // var x = (a| <- this can be a lambda expression + return containingNodeKind === SyntaxKind.CallExpression // func( | + || containingNodeKind === SyntaxKind.Constructor // constructor( | + || containingNodeKind === SyntaxKind.NewExpression // new C(a| + || containingNodeKind === SyntaxKind.ParenthesizedExpression; // var x = (a| + + case SyntaxKind.OpenBracketToken: + return containingNodeKind === SyntaxKind.ArrayLiteralExpression; // [ | case SyntaxKind.ModuleKeyword: // module | return true; @@ -2456,7 +2465,14 @@ module ts { return containingNodeKind === SyntaxKind.ClassDeclaration; // class A{ | case SyntaxKind.EqualsToken: - return containingNodeKind === SyntaxKind.VariableDeclaration; // var x = a| <- this can be lambda expression + return containingNodeKind === SyntaxKind.VariableDeclaration // var x = a| + || containingNodeKind === SyntaxKind.BinaryExpression; // x = a| + + case SyntaxKind.TemplateHead: + return containingNodeKind === SyntaxKind.TemplateExpression; // `aa ${| + + case SyntaxKind.TemplateMiddle: + return containingNodeKind === SyntaxKind.TemplateSpan; // `aa ${10} dd ${| case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: @@ -2596,6 +2612,9 @@ module ts { case SyntaxKind.GetKeyword: case SyntaxKind.SetKeyword: case SyntaxKind.ImportKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: + case SyntaxKind.YieldKeyword: return true; } @@ -2607,7 +2626,9 @@ module ts { case "function": case "var": case "static": - // TODO: add let and const + case "let": + case "const": + case "yield": return true; } } diff --git a/tests/cases/fourslash/completionListBuilderLocations_VariableDeclarations.ts b/tests/cases/fourslash/completionListBuilderLocations_VariableDeclarations.ts index 5c222f901f6ac..45f16090fd89a 100644 --- a/tests/cases/fourslash/completionListBuilderLocations_VariableDeclarations.ts +++ b/tests/cases/fourslash/completionListBuilderLocations_VariableDeclarations.ts @@ -1,15 +1,31 @@ /// -//// var x = a/*var1*/ +////var x = a/*var1*/ -//// var x = (b/*var2*/ +////var x = (b/*var2*/ -//// var x = (c, d/*var3*/ +////var x = (c, d/*var3*/ //// var y : any = "", x = a/*var4*/ //// var y : any = "", x = (a/*var5*/ - + +////class C{} +////var y = new C( + +//// class C{} +//// var y = new C(0, /*var7*/ + +////var y = [/*var8*/ + +////var y = [0, /*var9*/ + +////var y = `${/*var10*/ + +////var y = `${10} dd ${ /*var11*/ + +////var y = 10; y=/*var12*/ + test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.completionListAllowsNewIdentifier();