From a31ce789f402e79f4ef5360c8345b10745891515 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Sat, 21 Oct 2017 17:17:02 -0700 Subject: [PATCH 1/2] Remove escaped names of well known symbols from string completions --- src/compiler/utilities.ts | 6 ++++++ src/services/completions.ts | 18 ++++++++++-------- .../fourslash/completionForStringLiteral13.ts | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 tests/cases/fourslash/completionForStringLiteral13.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 01bb36e9065..69ea970a56d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -385,6 +385,12 @@ namespace ts { return (identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier) as __String; } + export function isEscapedNameOfWellKnownSymbol(escapedName: __String) { + return (escapedName as string).charCodeAt(0) === CharacterCodes._ && + (escapedName as string).charCodeAt(1) === CharacterCodes._ && + (escapedName as string).charCodeAt(2) === CharacterCodes.at; + } + /** * @deprecated Use `id.escapedText` to get the escaped text of an Identifier. * @param identifier The identifier to escape diff --git a/src/services/completions.ts b/src/services/completions.ts index 7afa85ce26d..0cd3a1e59c7 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -167,15 +167,17 @@ namespace ts.Completions { const uniqueNames = createMap(); if (symbols) { for (const symbol of symbols) { - const entry = createCompletionEntry(symbol, location, performCharacterChecks, typeChecker, target, allowStringLiteral); - if (entry) { - const id = entry.name; - if (!uniqueNames.has(id)) { - if (symbolToOriginInfoMap && symbolToOriginInfoMap[getUniqueSymbolId(symbol, typeChecker)]) { - entry.hasAction = true; + if (!isEscapedNameOfWellKnownSymbol(symbol.escapedName)) { + const entry = createCompletionEntry(symbol, location, performCharacterChecks, typeChecker, target, allowStringLiteral); + if (entry) { + const id = entry.name; + if (!uniqueNames.has(id)) { + if (symbolToOriginInfoMap && symbolToOriginInfoMap[getUniqueSymbolId(symbol, typeChecker)]) { + entry.hasAction = true; + } + entries.push(entry); + uniqueNames.set(id, true); } - entries.push(entry); - uniqueNames.set(id, true); } } } diff --git a/tests/cases/fourslash/completionForStringLiteral13.ts b/tests/cases/fourslash/completionForStringLiteral13.ts new file mode 100644 index 00000000000..391a1ed5083 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteral13.ts @@ -0,0 +1,14 @@ +/// + +////interface SymbolConstructor { +//// readonly species: symbol; +////} +////var Symbol: SymbolConstructor; +////interface PromiseConstructor { +//// [Symbol.species]: PromiseConstructor; +////} +////var Promise: PromiseConstructor; +////Promise["/*1*/"]; + +goTo.marker('1'); +verify.not.completionListContains("__@species"); From 9f1100cf307f8f5d2b7fd7ab136394d678fb41aa Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 23 Oct 2017 13:55:31 -0700 Subject: [PATCH 2/2] PR cleanup --- src/compiler/utilities.ts | 6 ------ src/services/completions.ts | 30 ++++++++++++++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 69ea970a56d..01bb36e9065 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -385,12 +385,6 @@ namespace ts { return (identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier) as __String; } - export function isEscapedNameOfWellKnownSymbol(escapedName: __String) { - return (escapedName as string).charCodeAt(0) === CharacterCodes._ && - (escapedName as string).charCodeAt(1) === CharacterCodes._ && - (escapedName as string).charCodeAt(2) === CharacterCodes.at; - } - /** * @deprecated Use `id.escapedText` to get the escaped text of an Identifier. * @param identifier The identifier to escape diff --git a/src/services/completions.ts b/src/services/completions.ts index 0cd3a1e59c7..448740b3192 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -167,17 +167,15 @@ namespace ts.Completions { const uniqueNames = createMap(); if (symbols) { for (const symbol of symbols) { - if (!isEscapedNameOfWellKnownSymbol(symbol.escapedName)) { - const entry = createCompletionEntry(symbol, location, performCharacterChecks, typeChecker, target, allowStringLiteral); - if (entry) { - const id = entry.name; - if (!uniqueNames.has(id)) { - if (symbolToOriginInfoMap && symbolToOriginInfoMap[getUniqueSymbolId(symbol, typeChecker)]) { - entry.hasAction = true; - } - entries.push(entry); - uniqueNames.set(id, true); + const entry = createCompletionEntry(symbol, location, performCharacterChecks, typeChecker, target, allowStringLiteral); + if (entry) { + const id = entry.name; + if (!uniqueNames.has(id)) { + if (symbolToOriginInfoMap && symbolToOriginInfoMap[getUniqueSymbolId(symbol, typeChecker)]) { + entry.hasAction = true; } + entries.push(entry); + uniqueNames.set(id, true); } } } @@ -1778,6 +1776,18 @@ namespace ts.Completions { } } + // If the symbol is for a member of an object type and is the internal name of an ES + // symbol, it is not a valid entry. Internal names for ES symbols start with "__@" + if (symbol.flags & SymbolFlags.ClassMember) { + const escapedName = symbol.escapedName as string; + if (escapedName.length >= 3 && + escapedName.charCodeAt(0) === CharacterCodes._ && + escapedName.charCodeAt(1) === CharacterCodes._ && + escapedName.charCodeAt(2) === CharacterCodes.at) { + return undefined; + } + } + return getCompletionEntryDisplayName(name, target, performCharacterChecks, allowStringLiteral); }