diff --git a/src/services/services.ts b/src/services/services.ts index f2000cfb185..851901ea13b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1567,14 +1567,20 @@ module ts { /// Completion function getValidCompletionEntryDisplayName(displayName: string, target: ScriptTarget): string { if (displayName && displayName.length > 0) { - var firstChar = displayName.charCodeAt(0); - if (firstChar === TypeScript.CharacterCodes.singleQuote || firstChar === TypeScript.CharacterCodes.doubleQuote) { + var firstCharCode = displayName.charCodeAt(0); + if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) && + (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an // invalid identifer name. We need to check if whatever was inside the quotes is actually a valid identifier name. - displayName = TypeScript.stripStartAndEndQuotes(displayName); + displayName = displayName.substring(1, displayName.length - 1); } - if (TypeScript.Scanner.isValidIdentifier(TypeScript.SimpleText.fromString(displayName), target)) { + var isValid = isIdentifierStart(displayName.charCodeAt(0), target); + for (var i = 1, n = displayName.length; isValid && i < n; i++) { + isValid = isValid && isIdentifierPart(displayName.charCodeAt(i), target); + } + + if (isValid) { return displayName; } } diff --git a/tests/cases/fourslash/completionListInvalidMemberNames.ts b/tests/cases/fourslash/completionListInvalidMemberNames.ts index 7091850bb3c..7fff46e2a81 100644 --- a/tests/cases/fourslash/completionListInvalidMemberNames.ts +++ b/tests/cases/fourslash/completionListInvalidMemberNames.ts @@ -19,7 +19,7 @@ verify.completionListContains("bar"); verify.completionListContains("break"); verify.completionListContains("any"); verify.completionListContains("$"); -verify.completionListContains("\\u0062"); +verify.completionListContains("b"); // Nothing else should show up verify.memberListCount(5);