Skip to content

Commit 57fa018

Browse files
committed
Use scanner APIs to identify if a display name is valid completion entry
1 parent 91b52b2 commit 57fa018

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/services/services.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,14 +1567,20 @@ module ts {
15671567
/// Completion
15681568
function getValidCompletionEntryDisplayName(displayName: string, target: ScriptTarget): string {
15691569
if (displayName && displayName.length > 0) {
1570-
var firstChar = displayName.charCodeAt(0);
1571-
if (firstChar === TypeScript.CharacterCodes.singleQuote || firstChar === TypeScript.CharacterCodes.doubleQuote) {
1570+
var firstCharCode = displayName.charCodeAt(0);
1571+
if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) &&
1572+
(firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
15721573
// If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an
15731574
// invalid identifer name. We need to check if whatever was inside the quotes is actually a valid identifier name.
1574-
displayName = TypeScript.stripStartAndEndQuotes(displayName);
1575+
displayName = displayName.substring(1, displayName.length - 1);
15751576
}
15761577

1577-
if (TypeScript.Scanner.isValidIdentifier(TypeScript.SimpleText.fromString(displayName), target)) {
1578+
var isValid = isIdentifierStart(displayName.charCodeAt(0), target);
1579+
for (var i = 1, n = displayName.length; isValid && i < n; i++) {
1580+
isValid = isValid && isIdentifierPart(displayName.charCodeAt(i), target);
1581+
}
1582+
1583+
if (isValid) {
15781584
return displayName;
15791585
}
15801586
}

tests/cases/fourslash/completionListInvalidMemberNames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ verify.completionListContains("bar");
1919
verify.completionListContains("break");
2020
verify.completionListContains("any");
2121
verify.completionListContains("$");
22-
verify.completionListContains("\\u0062");
22+
verify.completionListContains("b");
2323

2424
// Nothing else should show up
2525
verify.memberListCount(5);

0 commit comments

Comments
 (0)