Skip to content

Commit 8ff6251

Browse files
committed
Do not use internal aliasing when getting symbol full name to show in quickInfo or completion list
1 parent 461147a commit 8ff6251

File tree

4 files changed

+58
-23
lines changed

4 files changed

+58
-23
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ module ts {
736736
return rightMeaning === SymbolFlags.Value ? SymbolFlags.Value : SymbolFlags.Namespace;
737737
}
738738

739-
function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): Symbol[] {
739+
function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, useOnlyExternalAliasing: boolean): Symbol[] {
740740
function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[] {
741741
function canQualifySymbol(symbolFromSymbolTable: Symbol, meaning: SymbolFlags) {
742742
// If the symbol is equivalent and doesn't need further qualification, this symbol is accessible
@@ -745,7 +745,7 @@ module ts {
745745
}
746746

747747
// If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too
748-
var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning));
748+
var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
749749
return !!accessibleParent;
750750
}
751751

@@ -767,16 +767,21 @@ module ts {
767767
// Check if symbol is any of the alias
768768
return forEachValue(symbols, symbolFromSymbolTable => {
769769
if (symbolFromSymbolTable.flags & SymbolFlags.Import) {
770-
var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable);
771-
if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) {
772-
return [symbolFromSymbolTable];
773-
}
770+
if (!useOnlyExternalAliasing || // We can use any type of alias to get the name
771+
// Is this external alias, then use it to name
772+
ts.forEach(symbolFromSymbolTable.declarations, declaration =>
773+
declaration.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>declaration).externalModuleName)) {
774+
var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable);
775+
if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) {
776+
return [symbolFromSymbolTable];
777+
}
774778

775-
// Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain
776-
// but only if the symbolFromSymbolTable can be qualified
777-
var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
778-
if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
779-
return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
779+
// Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain
780+
// but only if the symbolFromSymbolTable can be qualified
781+
var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
782+
if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
783+
return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
784+
}
780785
}
781786
}
782787
});
@@ -822,7 +827,7 @@ module ts {
822827
var meaningToLook = meaning;
823828
while (symbol) {
824829
// Symbol is accessible if it by itself is accessible
825-
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook);
830+
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false);
826831
if (accessibleSymbolChain) {
827832
var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
828833
if (!hasAccessibleDeclarations) {
@@ -1005,7 +1010,7 @@ module ts {
10051010
writer.trackSymbol(symbol, enclosingDeclaration, meaning);
10061011
function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void {
10071012
if (symbol) {
1008-
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning);
1013+
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
10091014

10101015
if (!accessibleSymbolChain ||
10111016
needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {

src/compiler/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ module ts {
695695
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
696696
// var a: C<number>;
697697
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
698+
UseOnlyExternalAliasing = 0x00000002, // Use only external alias information to get the symbol name in the given context
699+
// eg. module m { export class c { } } import x = m.c;
700+
// When this flag is specified m.c will be used to refer to the class instead of alias symbol x
698701
}
699702

700703
export enum SymbolAccessibility {

src/services/services.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,41 +2851,41 @@ module ts {
28512851
if (symbolFlags & SymbolFlags.Class && !hasAddedSymbolInfo) {
28522852
displayParts.push(keywordPart(SyntaxKind.ClassKeyword));
28532853
displayParts.push(spacePart());
2854-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
2854+
addFullSymbolName(symbol);
28552855
writeTypeParametersOfSymbol(symbol, sourceFile);
28562856
}
28572857
if (symbolFlags & SymbolFlags.Interface) {
28582858
addNewLineIfDisplayPartsExist();
28592859
displayParts.push(keywordPart(SyntaxKind.InterfaceKeyword));
28602860
displayParts.push(spacePart());
2861-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
2861+
addFullSymbolName(symbol);
28622862
writeTypeParametersOfSymbol(symbol, sourceFile);
28632863
}
28642864
if (symbolFlags & SymbolFlags.Enum) {
28652865
addNewLineIfDisplayPartsExist();
28662866
displayParts.push(keywordPart(SyntaxKind.EnumKeyword));
28672867
displayParts.push(spacePart());
2868-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
2868+
addFullSymbolName(symbol);
28692869
}
28702870
if (symbolFlags & SymbolFlags.Module) {
28712871
addNewLineIfDisplayPartsExist();
28722872
displayParts.push(keywordPart(SyntaxKind.ModuleKeyword));
28732873
displayParts.push(spacePart());
2874-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
2874+
addFullSymbolName(symbol);
28752875
}
28762876
if (symbolFlags & SymbolFlags.TypeParameter) {
28772877
addNewLineIfDisplayPartsExist();
28782878
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
28792879
displayParts.push(textPart("type parameter"));
28802880
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
28812881
displayParts.push(spacePart());
2882-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration));
2882+
addFullSymbolName(symbol);
28832883
displayParts.push(spacePart());
28842884
displayParts.push(keywordPart(SyntaxKind.InKeyword));
28852885
displayParts.push(spacePart());
28862886
if (symbol.parent) {
28872887
// Class/Interface type parameter
2888-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol.parent, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments))
2888+
addFullSymbolName(symbol.parent, enclosingDeclaration);
28892889
writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration);
28902890
}
28912891
else {
@@ -2897,7 +2897,7 @@ module ts {
28972897
displayParts.push(spacePart());
28982898
}
28992899
else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) {
2900-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, signatureDeclaration.symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments))
2900+
addFullSymbolName(signatureDeclaration.symbol);
29012901
}
29022902
displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
29032903
}
@@ -2921,7 +2921,7 @@ module ts {
29212921
displayParts.push(textPart("alias"));
29222922
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
29232923
displayParts.push(spacePart());
2924-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
2924+
addFullSymbolName(symbol);
29252925
}
29262926
if (!hasAddedSymbolInfo) {
29272927
if (symbolKind !== ScriptElementKind.unknown) {
@@ -2969,15 +2969,20 @@ module ts {
29692969
}
29702970
}
29712971

2972+
function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) {
2973+
var fullSymbolDisplayParts = symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined,
2974+
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing);
2975+
displayParts.push.apply(displayParts, fullSymbolDisplayParts);
2976+
}
2977+
29722978
function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) {
29732979
addNewLineIfDisplayPartsExist();
29742980
if (symbolKind) {
29752981
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
29762982
displayParts.push(textPart(symbolKind));
29772983
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
29782984
displayParts.push(spacePart());
2979-
// Write type parameters of class/Interface if it is property/method of the generic class/interface
2980-
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
2985+
addFullSymbolName(symbol);
29812986
}
29822987
}
29832988

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
/////** Module comment*/
4+
////export module m1 {
5+
//// /** m2 comments*/
6+
//// export module m2 {
7+
//// /** class comment;*/
8+
//// export class /*1*/c {
9+
//// };
10+
//// }
11+
////}
12+
/////**This is on import declaration*/
13+
////import /*2*/internalAlias = m1.m2./*3*/c;
14+
15+
goTo.marker('1');
16+
verify.quickInfoIs("class m1.m2.c", "class comment;");
17+
18+
goTo.marker('2');
19+
verify.quickInfoIs('(alias) internalAlias', "This is on import declaration");
20+
21+
goTo.marker('3');
22+
verify.quickInfoIs("class m1.m2.c", "class comment;");

0 commit comments

Comments
 (0)