@@ -2801,34 +2801,25 @@ namespace ts {
2801
2801
}
2802
2802
2803
2803
/// Completion
2804
- function getCompletionEntryDisplayNameForSymbol ( symbol : Symbol , target : ScriptTarget , performCharacterChecks : boolean ) : string {
2805
- let displayName = symbol . getName ( ) ;
2806
- if ( displayName ) {
2807
- // If this is the default export, get the name of the declaration if it exists
2808
- if ( displayName === "default" ) {
2809
- let localSymbol = getLocalSymbolForExportDefault ( symbol ) ;
2810
- if ( localSymbol && localSymbol . name ) {
2811
- displayName = symbol . valueDeclaration . localSymbol . name ;
2812
- }
2813
- }
2814
-
2815
- // Special case for function expression and class expression because despite sometimes having a name, the binder
2816
- // binds them to a symbol with the name "__function" and "__class" respectively. However, for completion entry, we want
2817
- // to display its declared name rather than "__function" and "__class".
2818
- // var x = function foo () {
2819
- // fo$ <- completion list should contain local name "foo"
2820
- // }
2821
- // foo$ <- completion list should not contain "foo"
2822
- // TODO (yuisu): Use getDeclaredName instead once the functions is rewritten
2823
- if ( displayName === "__function" || displayName === "__class" ) {
2824
- displayName = symbol . declarations [ 0 ] . name . getText ( ) ;
2825
-
2826
- // At this point, we expect that all completion list entries have declared name including function expression
2827
- // because when we gather all relevant symbols, we check that the function expression must have declared name
2828
- // before adding the symbol into our symbols table. (see: getSymbolsInScope)
2829
- Debug . assert ( displayName !== undefined , "Expected this function expression to have declared name" ) ;
2830
- }
2831
-
2804
+ function getCompletionEntryDisplayNameForSymbol ( symbol : Symbol , target : ScriptTarget , performCharacterChecks : boolean , location : Node ) : string {
2805
+ let displayName : string ;
2806
+
2807
+ // In the case of default export, function expression and class expression,
2808
+ // the binder bind them with "default", "__function", "__class" respectively.
2809
+ // However, for completion entry, we want to display its declared name rather than binder name.
2810
+ if ( getLocalSymbolForExportDefault ( symbol ) ||
2811
+ getDeclarationOfKind ( symbol , SyntaxKind . FunctionExpression ) ||
2812
+ getDeclarationOfKind ( symbol , SyntaxKind . ClassExpression ) ) {
2813
+ let typeChecker = program . getTypeChecker ( ) ;
2814
+ displayName = getDeclaredName ( typeChecker , symbol , location ) ;
2815
+
2816
+ // At this point, we expect that all completion list entries have declared name including function expression and class expression
2817
+ // because when we gather all relevant symbols, we check that the function expression and class expression must have declared name
2818
+ // before adding the symbol into our symbols table. (see: getSymbolsInScope)
2819
+ Debug . assert ( displayName !== undefined , "Expected displayed name from declaration to existed in this symbol: " + symbol . getName ( ) ) ;
2820
+ }
2821
+ else {
2822
+ displayName = symbol . getName ( ) ;
2832
2823
let firstCharCode = displayName . charCodeAt ( 0 ) ;
2833
2824
// First check of the displayName is not external module; if it is an external module, it is not valid entry
2834
2825
if ( ( symbol . flags & SymbolFlags . Namespace ) && ( firstCharCode === CharacterCodes . singleQuote || firstCharCode === CharacterCodes . doubleQuote ) ) {
@@ -3534,7 +3525,7 @@ namespace ts {
3534
3525
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
3535
3526
// We would like to only show things that can be added after a dot, so for instance numeric properties can
3536
3527
// not be accessed with a dot (a.1 <- invalid)
3537
- let displayName = getCompletionEntryDisplayNameForSymbol ( symbol , program . getCompilerOptions ( ) . target , /*performCharacterChecks:*/ true ) ;
3528
+ let displayName = getCompletionEntryDisplayNameForSymbol ( symbol , program . getCompilerOptions ( ) . target , /*performCharacterChecks:*/ true , location ) ;
3538
3529
if ( ! displayName ) {
3539
3530
return undefined ;
3540
3531
}
@@ -3591,7 +3582,7 @@ namespace ts {
3591
3582
// We don't need to perform character checks here because we're only comparing the
3592
3583
// name against 'entryName' (which is known to be good), not building a new
3593
3584
// completion entry.
3594
- let symbol = forEach ( symbols , s => getCompletionEntryDisplayNameForSymbol ( s , target , /*performCharacterChecks:*/ false ) === entryName ? s : undefined ) ;
3585
+ let symbol = forEach ( symbols , s => getCompletionEntryDisplayNameForSymbol ( s , target , /*performCharacterChecks:*/ false , location ) === entryName ? s : undefined ) ;
3595
3586
3596
3587
if ( symbol ) {
3597
3588
let { displayParts, documentation, symbolKind } = getSymbolDisplayPartsDocumentationAndSymbolKind ( symbol , getValidSourceFile ( fileName ) , location , location , SemanticMeaning . All ) ;
0 commit comments