From aab210096bad1da8c8d0311dd2307b4723b76ec0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 24 Jun 2015 14:10:02 -0700 Subject: [PATCH] Add name of function expression into completion list --- src/compiler/checker.ts | 8 ++++++-- src/services/services.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index efee668a24b..7312dd137a2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12182,8 +12182,12 @@ namespace ts { } break; case SyntaxKind.FunctionExpression: - if ((location).name) { - copySymbol(location.symbol, meaning); + let name = (location).name; + if (name) { + let symbol = location.symbol; + if (symbol.flags & meaning && !hasProperty(symbols, name.text)) { + symbols[name.text] = symbol; + } } break; } diff --git a/src/services/services.ts b/src/services/services.ts index e11fb32c73b..6a7661e0dfd 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2807,6 +2807,22 @@ namespace ts { } } + // Special case for function expression because despite sometimes having a name, the binder + // binds them to a symbol with the name "__function". However, for completion entry, we want + // to display its declared name rather than "__function". + // var x = function foo () { + // fo$ <- completion list should contain local name "foo" + // } + // foo$ <- completion list should not contain "foo" + if (displayName === "__function") { + displayName = symbol.declarations[0].name.getText(); + + // At this point, we expect that all completion list entries have declared name including function expression + // because when we gather all relevant symbols, we check that the function expression must have declared name + // before adding the symbol into our symbols table. (see: getSymbolsInScope) + Debug.assert(displayName !== undefined,"Expected this function expression to have declared name"); + } + let firstCharCode = displayName.charCodeAt(0); // First check of the displayName is not external module; if it is an external module, it is not valid entry if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {