8000 Merge pull request #1184 from Microsoft/gotoDefShorthand · hbcodeXCI/TypeScript@838e760 · GitHub
[go: up one dir, main page]

Skip to content

Commit 838e760

Browse files
author
Yui
committed
Merge pull request microsoft#1184 from Microsoft/gotoDefShorthand
Go-to-Definition for shorthand properties
2 parents 50ddfb7 + 7dde856 commit 838e760

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/services/services.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,6 +3351,23 @@ module ts {
33513351

33523352
var result: DefinitionInfo[] = [];
33533353

3354+
// Because name in short-hand property assignment has two different meanings: property name and property value,
3355+
// using go-to-definition at such position should go to the variable declaration of the property value rather than
3356+
// go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition
3357+
// is performed at the location of property access, we would like to go to definition of the property in the short-hand
3358+
// assignment. This case and others are handled by the following code.
3359+
if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
3360+
var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
3361+
var shorthandDeclarations = shorthandSymbol.getDeclarations();
3362+
var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver);
3363+
var shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol);
3364+
var shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node);
3365+
forEach(shorthandDeclarations, declaration => {
3366+
result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName));
3367+
});
3368+
return result
3369+
}
3370+
33543371
var declarations = symbol.getDeclarations();
33553372
var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol
33563373
var symbolKind = getSymbolKind(symbol, typeInfoResolver);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// var /*valueDeclaration1*/name = "hello";
4+
//// var /*valueDeclaration2*/id = 100000;
5+
//// declare var /*valueDeclaration3*/id;
6+
//// var obj = {/*valueDefinition1*/name, /*valueDefinition2*/id};
7+
//// obj./*valueReference1*/name;
8+
//// obj./*valueReference2*/id;
9+
10+
goTo.marker("valueDefinition1");
11+
goTo.definition();
12+
verify.caretAtMarker("valueDeclaration1");
13+
14+
goTo.marker("valueDefinition2");
15+
goTo.definition(0);
16+
verify.caretAtMarker("valueDeclaration2");
17+
goTo.definition(1);
18+
verify.caretAtMarker("valueDeclaration3");
19+
20+
goTo.marker("valueReference1");
21+
goTo.definition();
22+
verify.caretAtMarker("valueDefinition1");
23+
goTo.marker("valueReference2");
24+
goTo.definition();
25+
verify.caretAtMarker("valueDefinition2");

0 commit comments

Comments
 (0)
0