Don't include literals from enum members in completions (#45588)

* don't include literals from enum members in completions

* add enum symbol to completions test

* use symbol flags for detecting enum member

* use type flags to check for enum member

* fix test
This commit is contained in:
Gabriela Araujo Britto 2021-08-26 16:33:06 -07:00 committed by GitHub
parent 7fc1cb4b36
commit 9f025b90a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View file

@ -1500,7 +1500,10 @@ namespace ts.Completions {
log("getCompletionData: Semantic work: " + (timestamp() - semanticStart));
const contextualType = previousToken && getContextualType(previousToken, position, sourceFile, typeChecker);
const literals = mapDefined(contextualType && (contextualType.isUnion() ? contextualType.types : [contextualType]), t => t.isLiteral() ? t.value : undefined);
const literals = mapDefined(
contextualType && (contextualType.isUnion() ? contextualType.types : [contextualType]),
t => t.isLiteral() && !(t.flags & TypeFlags.EnumLiteral) ? t.value : undefined);
const recommendedCompletion = previousToken && contextualType && getRecommendedCompletion(previousToken, contextualType, typeChecker);
return {

View file

@ -0,0 +1,36 @@
/// <reference path="fourslash.ts" />
////enum E {
//// v
////}
////const enum ES {
//// v = "str",
//// x = "str2"
////}
////const e: E = /*a*/;
////const es: ES = /*b*/;
verify.completions({
marker: "a",
isNewIdentifierLocation: true,
excludes: ["0"],
includes: [
{
name: "E",
isRecommended: true,
sortText: completion.SortText.LocationPriority,
}
],
}, {
marker: "b",
isNewIdentifierLocation: true,
excludes: [`"str"`, `"str2"`],
includes: [
{
name: "ES",
isRecommended: true,
sortText: completion.SortText.LocationPriority,
}
],
});