From d52b096d55600095a2c380722e97527fa5761f00 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 17 Nov 2014 14:27:14 -0800 Subject: [PATCH 1/3] go-to-definition with test cases --- src/services/services.ts | 17 ++++++++++++++ .../goToDefinitionShorthandProperty.ts | 23 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/cases/fourslash/goToDefinitionShorthandProperty.ts diff --git a/src/services/services.ts b/src/services/services.ts index 334bcc9da7e..90635354a3d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3418,6 +3418,23 @@ module ts { var result: DefinitionInfo[] = []; + // Because name in short-hand property assignment has two different meanings: property name and property value, + // using go-to-definition at such position should go to the variable declaration of the property value rather than + // go to the declaration of the property name (in this case stay at the same position). However, if go-to-defition + // is performed at the location of property accessing, we would like to go to defition of the property in the short-hand + // assignment. Such case is handled as normal by below code section. + if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment && !(symbol.flags & SymbolFlags.Transient)) { + var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + var shorthandDeclarations = shorthandSymbol.getDeclarations(); + var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver); + var shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); + var shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); + forEach(shorthandDeclarations, declaration => { + result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); + }); + return result + } + var declarations = symbol.getDeclarations(); var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol var symbolKind = getSymbolKind(symbol, typeInfoResolver); diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty.ts new file mode 100644 index 00000000000..9fa1be22ffd --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty.ts @@ -0,0 +1,23 @@ +/// + +//// var /*valueDeclaration1*/name = "hello"; +//// var /*valueDeclaration2*/id = 100000; +//// declare var /*valueDeclaration3*/id; +//// var obj = {/*valueDefition1*/name, /*valueDefinition2*/id}; +//// obj./*valueReference1*/name; +//// obj./*valueReference2*/id; + +goTo.marker("valueDefition1"); +goTo.definition(); +verify.caretAtMarker("valueDeclaration1"); + +goTo.marker("valueDefinition2"); +goTo.definition(0); +verify.caretAtMarker("valueDeclaration2"); +goTo.definition(1); +verify.caretAtMarker("valueDeclaration3"); + +goTo.marker("valueReference1"); +verify.caretAtMarker("valueDefinition1"); +goTo.marker("valueReference2"); +verify.caretAtMarker("valueDefinition2"); From 38dce094633eeea8b4fac807075ee84e02c9b1f5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 18 Nov 2014 10:27:31 -0800 Subject: [PATCH 2/3] Address code review --- src/services/services.ts | 8 ++++---- tests/cases/fourslash/goToDefinitionShorthandProperty.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 9345d84b7c1..12f4c49dd56 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3353,10 +3353,10 @@ module ts { // Because name in short-hand property assignment has two different meanings: property name and property value, // using go-to-definition at such position should go to the variable declaration of the property value rather than - // go to the declaration of the property name (in this case stay at the same position). However, if go-to-defition - // is performed at the location of property accessing, we would like to go to defition of the property in the short-hand - // assignment. Such case is handled as normal by below code section. - if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment && !(symbol.flags & SymbolFlags.Transient)) { + // go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition + // is performed at the location of property access, we would like to go to definition of the property in the short-hand + // assignment. This case and others are handled by the following code. + if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) { var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); var shorthandDeclarations = shorthandSymbol.getDeclarations(); var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver); diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty.ts index 9fa1be22ffd..7f0855e524d 100644 --- a/tests/cases/fourslash/goToDefinitionShorthandProperty.ts +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty.ts @@ -3,11 +3,11 @@ //// var /*valueDeclaration1*/name = "hello"; //// var /*valueDeclaration2*/id = 100000; //// declare var /*valueDeclaration3*/id; -//// var obj = {/*valueDefition1*/name, /*valueDefinition2*/id}; +//// var obj = {/*valueDefinition1*/name, /*valueDefinition2*/id}; //// obj./*valueReference1*/name; //// obj./*valueReference2*/id; -goTo.marker("valueDefition1"); +goTo.marker("valueDefinition1"); goTo.definition(); verify.caretAtMarker("valueDeclaration1"); From 5844f6804094d35eb7b338a9e272431f1a8812a2 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 18 Nov 2014 10:27:31 -0800 Subject: [PATCH 3/3] Address code review --- src/services/services.ts | 8 ++++---- tests/cases/fourslash/goToDefinitionShorthandProperty.ts | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 9345d84b7c1..12f4c49dd56 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3353,10 +3353,10 @@ module ts { // Because name in short-hand property assignment has two different meanings: property name and property value, // using go-to-definition at such position should go to the variable declaration of the property value rather than - // go to the declaration of the property name (in this case stay at the same position). However, if go-to-defition - // is performed at the location of property accessing, we would like to go to defition of the property in the short-hand - // assignment. Such case is handled as normal by below code section. - if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment && !(symbol.flags & SymbolFlags.Transient)) { + // go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition + // is performed at the location of property access, we would like to go to definition of the property in the short-hand + // assignment. This case and others are handled by the following code. + if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) { var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); var shorthandDeclarations = shorthandSymbol.getDeclarations(); var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver); diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty.ts index 9fa1be22ffd..07ea82c03e1 100644 --- a/tests/cases/fourslash/goToDefinitionShorthandProperty.ts +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty.ts @@ -3,11 +3,11 @@ //// var /*valueDeclaration1*/name = "hello"; //// var /*valueDeclaration2*/id = 100000; //// declare var /*valueDeclaration3*/id; -//// var obj = {/*valueDefition1*/name, /*valueDefinition2*/id}; +//// var obj = {/*valueDefinition1*/name, /*valueDefinition2*/id}; //// obj./*valueReference1*/name; //// obj./*valueReference2*/id; -goTo.marker("valueDefition1"); +goTo.marker("valueDefinition1"); goTo.definition(); verify.caretAtMarker("valueDeclaration1"); @@ -18,6 +18,8 @@ goTo.definition(1); verify.caretAtMarker("valueDeclaration3"); goTo.marker("valueReference1"); +goTo.definition(); verify.caretAtMarker("valueDefinition1"); goTo.marker("valueReference2"); +goTo.definition(); verify.caretAtMarker("valueDefinition2");