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:
parent
7fc1cb4b36
commit
9f025b90a4
|
@ -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 {
|
||||
|
|
36
tests/cases/fourslash/completionsEnum.ts
Normal file
36
tests/cases/fourslash/completionsEnum.ts
Normal 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,
|
||||
}
|
||||
],
|
||||
});
|
Loading…
Reference in a new issue