Skip to content

Commit 90a76f9

Browse files
gabrittoBobobUnicorn
authored andcommitted
Don't include literals from enum members in completions (microsoft#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
1 parent 56fdf38 commit 90a76f9

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/services/completions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,10 @@ namespace ts.Completions {
15001500

15011501
log("getCompletionData: Semantic work: " + (timestamp() - semanticStart));
15021502
const contextualType = previousToken && getContextualType(previousToken, position, sourceFile, typeChecker);
1503-
const literals = mapDefined(contextualType && (contextualType.isUnion() ? contextualType.types : [contextualType]), t => t.isLiteral() ? t.value : undefined);
1503+
1504+
const literals = mapDefined(
1505+
contextualType && (contextualType.isUnion() ? contextualType.types : [contextualType]),
1506+
t => t.isLiteral() && !(t.flags & TypeFlags.EnumLiteral) ? t.value : undefined);
15041507

15051508
const recommendedCompletion = previousToken && contextualType && getRecommendedCompletion(previousToken, contextualType, typeChecker);
15061509
return {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////enum E {
4+
//// v
5+
////}
6+
////const enum ES {
7+
//// v = "str",
8+
//// x = "str2"
9+
////}
10+
////const e: E = /*a*/;
11+
////const es: ES = /*b*/;
12+
13+
14+
verify.completions({
15+
marker: "a",
16+
isNewIdentifierLocation: true,
17+
excludes: ["0"],
18+
includes: [
19+
{
20+
name: "E",
21+
isRecommended: true,
22+
sortText: completion.SortText.LocationPriority,
23+
}
24+
],
25+
}, {
26+
marker: "b",
27+
isNewIdentifierLocation: true,
28+
excludes: [`"str"`, `"str2"`],
29+
includes: [
30+
{
31+
name: "ES",
32+
isRecommended: true,
33+
sortText: completion.SortText.LocationPriority,
34+
}
35+
],
36+
});

0 commit comments

Comments
 (0)