From 308f13fb9b53e9e0e1c243cdfe4c00834647c8fe Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 9 Jan 2015 12:21:30 -0800 Subject: [PATCH 01/25] 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 1618fb6e276..abe12b00128 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/25] 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 abe12b00128..438bb0163f8 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/25] 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 00000000000..f38e9920b82 --- /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 346a102faa8..2e85364ce3c 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/25] 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 438bb0163f8..7d33e56c9a7 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 f38e9920b82..00000000000 --- 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/25] 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 cfc83af76e5..21c54d8b0cf 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 0f458041521..243629fa347 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/25] 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 21c54d8b0cf..8ffdef428eb 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/25] 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 7d33e56c9a7..bb98fd7d5db 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/25] 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 bb98fd7d5db..dfca8aea745 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 00000000000..a629371d147 --- /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/25] 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 4ebdf029a89..00000000000 --- 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/25] 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 8ffdef428eb..232411d03d9 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 7ebf21abc1d..bbd297a3940 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 0fd66e9d091..f5a82cdcc57 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 a629371d147..d39c52318ce 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 243629fa347..71e3d723e20 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/25] 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 f5a82cdcc57..cb1b7592518 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 00000000000..8d8d89cbdc7 --- /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/25] 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 bbd297a3940..0bfbd46f217 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 cb1b7592518..10293c41a64 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 00000000000..f15868d2158 --- /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 00000000000..287ffd6746b --- /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/25] 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 0bfbd46f217..245ab05afa7 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/25] 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 245ab05afa7..662ae7df102 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 f15868d2158..e709fdfe4ef 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 091038eca1e644673db3dd1c340783fe9dc3cebd Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 2 Feb 2015 19:15:43 -0800 Subject: [PATCH 15/25] Change the default LS target to ES5 from ES6 --- 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 978bc2ad36b..c659d08fb3e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1418,9 +1418,9 @@ module ts { } export function getDefaultCompilerOptions(): CompilerOptions { - // Set "ScriptTarget.Latest" target by default for language service + // Always default to "ScriptTarget.ES5" for the language service return { - target: ScriptTarget.Latest, + target: ScriptTarget.ES5, module: ModuleKind.None, }; } From 3b0f8f67dd78a6ee41e3f8d55a662811e303d728 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 3 Feb 2015 11:37:52 -0800 Subject: [PATCH 16/25] 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 0d6dc073d38..b29c0fc84d3 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 17/25] 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 c43f67f94b7..143fd19dd75 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 18/25] 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 f70ee02415a..e1c97ef4b8e 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 090c42a7216..b4aa0f48627 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 b3905862c67..005a6c38e6e 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 5f613ec140c..034d913a329 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 06546d2fdbc..88a7fcacaa0 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 f92c2f36774..25a363f315e 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 9a7064117bf..d01e440dc1f 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 938db86d09e..cd2036e2e25 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 19/25] 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 7f11c98ce8d..1e581092638 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 143fd19dd75..b4a622297c7 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 e1c97ef4b8e..d6e98c61302 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 b4aa0f48627..e70d876d2a9 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 005a6c38e6e..bd71ce6270d 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 034d913a329..cceb4142a96 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 88a7fcacaa0..2402d98dc58 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 25a363f315e..7c159c1a9dd 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 d01e440dc1f..3113cc4e86d 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 cd2036e2e25..84fd5065409 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 e709fdfe4ef..58fdc1d2342 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 d39c52318ce..eac7085ab66 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 8d8d89cbdc7..4bc60180efc 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 442d62c0b4d..267f2c14341 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 20/25] 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 b4a622297c7..126cf578c1c 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 4bc60180efc..12dba953d3d 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 c80a6da18e7e1bba49349636309699ed6fed673f Mon Sep 17 00:00:00 2001 From: jbondc Date: Wed, 4 Feb 2015 08:52:45 -0500 Subject: [PATCH 21/25] Add 'jake tsc' to only build the compiler for quick testing. --- Jakefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Jakefile b/Jakefile index 767387c5d86..dc8070fd751 100644 --- a/Jakefile +++ b/Jakefile @@ -382,6 +382,10 @@ compileFile(nodeDefinitionsFile, servicesSources,[builtLocalDirectory, copyright desc("Builds the full compiler and services"); task("local", ["generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile]); +// Local target to build only tsc.js +desc("Builds only the compiler"); +task("tsc", ["generate-diagnostics", "lib", tscFile]); + // Local target to build the compiler and services desc("Sets release mode flag"); task("release", function() { From 6e35f79412aa6bb43e714f8b19fcf2ec3c50887e Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 4 Feb 2015 14:03:26 -0800 Subject: [PATCH 22/25] 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 126cf578c1c..5dd32e66bbe 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 00000000000..5c222f901f6 --- /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 23/25] 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 b58e28a8b26..677af16bdc4 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 5c222f901f6..45f16090fd8 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(); From 953e568d9e8df805c6af851e985620d8150d9ac8 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Thu, 5 Feb 2015 13:32:33 -0800 Subject: [PATCH 24/25] Disallow rename for elements that are defined in the standard TypeScript library. --- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 +++ src/services/services.ts | 31 ++++++++++++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 7bf95dcc846..1188d346191 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -451,6 +451,7 @@ module ts { _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." }, + You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b4944f56d77..b1a794716a4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1798,6 +1798,10 @@ "category": "Error", "code": 8000 }, + "You cannot rename elements that are defined in the standard TypeScript library.": { + "category": "Error", + "code": 8001 + }, "'yield' expressions are not currently supported.": { "category": "Error", "code": 9000 diff --git a/src/services/services.ts b/src/services/services.ts index 00084f51081..43f74bd323f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5450,22 +5450,39 @@ module ts { var symbol = typeInfoResolver.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. - if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) { - var kind = getSymbolKind(symbol, typeInfoResolver, node); - if (kind) { - return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, - getSymbolModifiers(symbol), - createTextSpan(node.getStart(), node.getWidth())); + if (symbol) { + var declarations = symbol.getDeclarations(); + if (declarations && declarations.length > 0) { + + // Disallow rename for elements that are defined in the standard TypeScript library. + var defaultLibFile = getDefaultLibFileName(host.getCompilationSettings()); + for (var i = 0; i < declarations.length; i++) { + var sourceFile = declarations[i].getSourceFile(); + if (sourceFile && endsWith(sourceFile.fileName, defaultLibFile)) { + return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key)); + } + } + + var kind = getSymbolKind(symbol, typeInfoResolver, node); + if (kind) { + return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, + getSymbolModifiers(symbol), + createTextSpan(node.getStart(), node.getWidth())); + } } } } return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_this_element.key)); + function endsWith(string: string, value: string): boolean { + return string.substring(string.length - value.length, string.length) === value; + } + function getRenameInfoError(localizedErrorMessage: string): RenameInfo { return { canRename: false, - localizedErrorMessage: getLocaleSpecificMessage(Diagnostics.You_cannot_rename_this_element.key), + localizedErrorMessage: localizedErrorMessage, displayName: undefined, fullDisplayName: undefined, kind: undefined, From 987dab9c9eb9583f3b85a066a6ebaa9388c73734 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Thu, 5 Feb 2015 16:05:54 -0800 Subject: [PATCH 25/25] addressing CR comments --- src/services/services.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 43f74bd323f..c29edf34be2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5453,7 +5453,6 @@ module ts { if (symbol) { var declarations = symbol.getDeclarations(); if (declarations && declarations.length > 0) { - // Disallow rename for elements that are defined in the standard TypeScript library. var defaultLibFile = getDefaultLibFileName(host.getCompilationSettings()); for (var i = 0; i < declarations.length; i++) { @@ -5461,13 +5460,19 @@ module ts { if (sourceFile && endsWith(sourceFile.fileName, defaultLibFile)) { return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key)); } - } + } var kind = getSymbolKind(symbol, typeInfoResolver, node); if (kind) { - return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, - getSymbolModifiers(symbol), - createTextSpan(node.getStart(), node.getWidth())); + return { + canRename: true, + localizedErrorMessage: undefined, + displayName: symbol.name, + fullDisplayName: typeInfoResolver.getFullyQualifiedName(symbol), + kind: kind, + kindModifiers: getSymbolModifiers(symbol), + triggerSpan: createTextSpan(node.getStart(), node.getWidth()) + }; } } } @@ -5476,7 +5481,7 @@ module ts { return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_this_element.key)); function endsWith(string: string, value: string): boolean { - return string.substring(string.length - value.length, string.length) === value; + return string.lastIndexOf(value) + value.length === string.length; } function getRenameInfoError(localizedErrorMessage: string): RenameInfo { @@ -5490,18 +5495,6 @@ module ts { triggerSpan: undefined }; } - - function getRenameInfo(displayName: string, fullDisplayName: string, kind: string, kindModifiers: string, triggerSpan: TextSpan): RenameInfo { - return { - canRename: true, - localizedErrorMessage: undefined, - displayName, - fullDisplayName, - kind, - kindModifiers, - triggerSpan - }; - } } return {