Skip to content

Commit 934a3bf

Browse files
Fixed 'displayName'.
1 parent 6f925ac commit 934a3bf

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

src/services/services.ts

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,25 +4915,20 @@ module ts {
49154915
return undefined;
49164916
}
49174917

4918-
49194918
let declarations = symbol.declarations;
49204919

49214920
// The symbol was an internal symbol and does not have a declaration e.g. undefined symbol
49224921
if (!declarations || !declarations.length) {
49234922
return undefined;
49244923
}
49254924

4926-
// Try to get the local symbol if we're dealing with an 'export default'
4927-
// since that symbol has the "true" name and we need to account for other declarations.
4928-
let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol);
4929-
49304925
let result: ReferencedSymbol[];
49314926

49324927
// Compute the meaning from the location and the symbol it references
49334928
let searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations);
49344929

49354930
// Get the text to search for, we need to normalize it as external module names will have quotes
4936-
let declaredName = getDeclaredName(localExportDefaultSymbol || symbol, node);
4931+
let declaredName = getDeclaredName(typeChecker, symbol, node);
49374932

49384933
// Try to get the smallest valid scope that we can limit our search to;
49394934
// otherwise we'll need to search globally (i.e. include each file).
@@ -4947,7 +4942,7 @@ module ts {
49474942
getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex);
49484943
}
49494944
else {
4950-
let internedName = getInternedName(localExportDefaultSymbol || symbol, node, declarations)
4945+
let internedName = getInternedName(symbol, node, declarations)
49514946
for (let sourceFile of sourceFiles) {
49524947
cancellationToken.throwIfCancellationRequested();
49534948

@@ -4980,30 +4975,12 @@ module ts {
49804975
};
49814976
}
49824977

4983-
function isImportOrExportSpecifierName(location: Node): boolean {
4984-
return location.parent &&
4985-
(location.parent.kind === SyntaxKind.ImportSpecifier || location.parent.kind === SyntaxKind.ExportSpecifier) &&
4986-
(<ImportOrExportSpecifier>location.parent).propertyName === location;
4987-
}
4988-
49894978
function isImportOrExportSpecifierImportSymbol(symbol: Symbol) {
49904979
return (symbol.flags & SymbolFlags.Alias) && forEach(symbol.declarations, declaration => {
49914980
return declaration.kind === SyntaxKind.ImportSpecifier || declaration.kind === SyntaxKind.ExportSpecifier;
49924981
});
49934982
}
49944983

4995-
function getDeclaredName(symbol: Symbol, location: Node) {
4996-
// If this is an export or import specifier it could have been renamed using the 'as' syntax.
4997-
// If so we want to search for whatever is under the cursor.
4998-
if (isImportOrExportSpecifierName(location)) {
4999-
return location.getText();
5000-
}
5001-
5002-
let name = typeChecker.symbolToString(symbol);
5003-
5004-
return stripQuotes(name);
5005-
}
5006-
50074984
function getInternedName(symbol: Symbol, location: Node, declarations: Declaration[]) {
50084985
// If this is an export or import specifier it could have been renamed using the 'as' syntax.
50094986
// If so we want to search for whatever under the cursor.
@@ -5023,15 +5000,12 @@ module ts {
50235000
}
50245001
}
50255002

5026-
return stripQuotes(symbol.name);
5027-
}
5003+
// Try to get the local symbol if we're dealing with an 'export default'
5004+
// since that symbol has the "true" name.
5005+
let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol);
5006+
symbol = localExportDefaultSymbol || symbol;
50285007

5029-
function stripQuotes(name: string) {
5030-
let length = name.length;
5031-
if (length >= 2 && name.charCodeAt(0) === CharacterCodes.doubleQuote && name.charCodeAt(length - 1) === CharacterCodes.doubleQuote) {
5032-
return name.substring(1, length - 1);
5033-
};
5034-
return name;
5008+
return stripQuotes(symbol.name);
50355009
}
50365010

50375011
function getSymbolScope(symbol: Symbol): Node {
@@ -6647,12 +6621,13 @@ module ts {
66476621
}
66486622
}
66496623

6624+
let displayName = getDeclaredName(typeChecker, symbol, node);
66506625
let kind = getSymbolKind(symbol, node);
66516626
if (kind) {
66526627
return {
66536628
canRename: true,
66546629
localizedErrorMessage: undefined,
6655-
displayName: symbol.name,
6630+
displayName,
66566631
fullDisplayName: typeChecker.getFullyQualifiedName(symbol),
66576632
kind: kind,
66586633
kindModifiers: getSymbolModifiers(symbol),

src/services/utilities.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,4 +652,34 @@ module ts {
652652
typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
653653
});
654654
}
655+
656+
export function getDeclaredName(typeChecker: TypeChecker, symbol: Symbol, location: Node) {
657+
// If this is an export or import specifier it could have been renamed using the 'as' syntax.
658+
// If so we want to search for whatever is under the cursor.
659+
if (isImportOrExportSpecifierName(location)) {
660+
return location.getText();
661+
}
662+
663+
// Try to get the local symbol if we're dealing with an 'export default'
664+
// since that symbol has the "true" name.
665+
let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol);
666+
667+
let name = typeChecker.symbolToString(localExportDefaultSymbol || symbol);
668+
669+
return stripQuotes(name);
670+
}
671+
672+
export function isImportOrExportSpecifierName(location: Node): boolean {
673+
return location.parent &&
674+
(location.parent.kind === SyntaxKind.ImportSpecifier || location.parent.kind === SyntaxKind.ExportSpecifier) &&
675+
(<ImportOrExportSpecifier>location.parent).propertyName === location;
676+
}
677+
678+
export function stripQuotes(name: string) {
679+
let length = name.length;
680+
if (length >= 2 && name.charCodeAt(0) === CharacterCodes.doubleQuote && name.charCodeAt(length - 1) === CharacterCodes.doubleQuote) {
681+
return name.substring(1, length - 1);
682+
};
683+
return name;
684+
}
655685
}

0 commit comments

Comments
 (0)