Add support for union properties in goto def

This commit is contained in:
Mohamed Hegazy
2014-10-07 23:17:05 -07:00
parent 5669f63430
commit c439ae4a9d
3 changed files with 75 additions and 13 deletions
+26 -13
View File
@@ -2563,6 +2563,25 @@ module ts {
return false;
}
function getDefinitionFromSymbol(symbol: Symbol, location: Node, result: DefinitionInfo[]): void {
var declarations = symbol.getDeclarations();
if (declarations) {
var symbolName = typeInfoResolver.symbolToString(symbol, location);
var symbolKind = getSymbolKind(symbol);
var containerSymbol = symbol.parent;
var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, location) : "";
var containerKind = containerSymbol ? getSymbolKind(symbol) : "";
if (!tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) &&
!tryAddCallSignature(symbol, location, symbolKind, symbolName, containerName, result)) {
// Just add all the declarations.
forEach(declarations, declaration => {
result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName));
});
}
}
}
synchronizeHostData();
filename = TypeScript.switchToForwardSlashes(filename);
@@ -2601,26 +2620,20 @@ module ts {
// Could not find a symbol e.g. node is string or number keyword,
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
if (!symbol || !(symbol.getDeclarations())) {
if (!symbol) {
return undefined;
}
var result: DefinitionInfo[] = [];
var declarations = symbol.getDeclarations();
var symbolName = typeInfoResolver.symbolToString(symbol, node);
var symbolKind = getSymbolKind(symbol);
var containerSymbol = symbol.parent;
var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : "";
var containerKind = containerSymbol ? getSymbolKind(symbol) : "";
if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) &&
!tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) {
// Just add all the declarations.
forEach(declarations, declaration => {
result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName));
if (symbol.flags & SymbolFlags.UnionProperty) {
forEach(typeInfoResolver.getUnionTypesOfUnionProperty(symbol), t => {
getDefinitionFromSymbol(typeInfoResolver.getPropertyOfType(t, symbol.name), node, result);
});
}
else {
getDefinitionFromSymbol(symbol, node, result);
}
return result;
}
@@ -0,0 +1,24 @@
/// <reference path='fourslash.ts' />
////interface One {
//// /*propertyDefinition1*/commonProperty: number;
//// commonFunction(): number;
////}
////
////interface Two {
//// /*propertyDefinition2*/commonProperty: string
//// commonFunction(): number;
////}
////
////var x : One | Two;
////
////x./*propertyReference*/commonProperty;
////x./*3*/commonFunction;
goTo.marker("propertyReference");
goTo.definition(0);
verify.caretAtMarker("propertyDefinition1");
goTo.marker("propertyReference");
goTo.definition(1);
verify.caretAtMarker("propertyDefinition2");
@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
////interface HasAOrB {
//// /*propertyDefinition1*/a: string;
//// b: string;
////}
////
////interface One {
//// common: { /*propertyDefinition2*/a : number; };
////}
////
////interface Two {
//// common: HasAOrB;
////}
////
////var x : One | Two;
////
////x.common./*propertyReference*/a;
goTo.marker("propertyReference");
goTo.definition(0);
verify.caretAtMarker("propertyDefinition1");
goTo.marker("propertyReference");
goTo.definition(1);
verify.caretAtMarker("propertyDefinition2");