Skip to content

Commit 2300a99

Browse files
authored
Merge pull request #15614 from Microsoft/completionListForClassElementDeclarations
When writing class elements show completion with allowed keywords and inheritted properties
2 parents 0455aaf + 303d7b2 commit 2300a99

15 files changed

+1054
-84
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,6 @@ namespace ts {
685685
return type.flags & TypeFlags.Object ? (<ObjectType>type).objectFlags : 0;
686686
}
687687

688-
function getCheckFlags(symbol: Symbol): CheckFlags {
689-
return symbol.flags & SymbolFlags.Transient ? (<TransientSymbol>symbol).checkFlags : 0;
690-
}
691-
692688
function isGlobalSourceFile(node: Node) {
693689
return node.kind === SyntaxKind.SourceFile && !isExternalOrCommonJsModule(<SourceFile>node);
694690
}
@@ -14047,25 +14043,6 @@ namespace ts {
1404714043
return s.valueDeclaration ? s.valueDeclaration.kind : SyntaxKind.PropertyDeclaration;
1404814044
}
1404914045

14050-
function getDeclarationModifierFlagsFromSymbol(s: Symbol): ModifierFlags {
14051-
if (s.valueDeclaration) {
14052-
const flags = getCombinedModifierFlags(s.valueDeclaration);
14053-
return s.parent && s.parent.flags & SymbolFlags.Class ? flags : flags & ~ModifierFlags.AccessibilityModifier;
14054-
}
14055-
if (getCheckFlags(s) & CheckFlags.Synthetic) {
14056-
const checkFlags = (<TransientSymbol>s).checkFlags;
14057-
const accessModifier = checkFlags & CheckFlags.ContainsPrivate ? ModifierFlags.Private :
14058-
checkFlags & CheckFlags.ContainsPublic ? ModifierFlags.Public :
14059-
ModifierFlags.Protected;
14060-
const staticModifier = checkFlags & CheckFlags.ContainsStatic ? ModifierFlags.Static : 0;
14061-
return accessModifier | staticModifier;
14062-
}
14063-
if (s.flags & SymbolFlags.Prototype) {
14064-
return ModifierFlags.Public | ModifierFlags.Static;
14065-
}
14066-
return 0;
14067-
}
14068-
1406914046
function getDeclarationNodeFlagsFromSymbol(s: Symbol): NodeFlags {
1407014047
return s.valueDeclaration ? getCombinedNodeFlags(s.valueDeclaration) : 0;
1407114048
}

src/compiler/utilities.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,6 +4235,29 @@ namespace ts {
42354235
return options.watch && options.hasOwnProperty("watch");
42364236
}
42374237

4238+
export function getCheckFlags(symbol: Symbol): CheckFlags {
4239+
return symbol.flags & SymbolFlags.Transient ? (<TransientSymbol>symbol).checkFlags : 0;
4240+
}
4241+
4242+
export function getDeclarationModifierFlagsFromSymbol(s: Symbol): ModifierFlags {
4243+
if (s.valueDeclaration) {
4244+
const flags = getCombinedModifierFlags(s.valueDeclaration);
4245+
return s.parent && s.parent.flags & SymbolFlags.Class ? flags : flags & ~ModifierFlags.AccessibilityModifier;
4246+
}
4247+
if (getCheckFlags(s) & CheckFlags.Synthetic) {
4248+
const checkFlags = (<TransientSymbol>s).checkFlags;
4249+
const accessModifier = checkFlags & CheckFlags.ContainsPrivate ? ModifierFlags.Private :
4250+
checkFlags & CheckFlags.ContainsPublic ? ModifierFlags.Public :
4251+
ModifierFlags.Protected;
4252+
const staticModifier = checkFlags & CheckFlags.ContainsStatic ? ModifierFlags.Static : 0;
4253+
return accessModifier | staticModifier;
4254+
}
4255+
if (s.flags & SymbolFlags.Prototype) {
4256+
return ModifierFlags.Public | ModifierFlags.Static;
4257+
}
4258+
return 0;
4259+
}
4260+
42384261
export function levenshtein(s1: string, s2: string): number {
42394262
let previous: number[] = new Array(s2.length + 1);
42404263
let current: number[] = new Array(s2.length + 1);

src/harness/fourslash.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,6 +3417,18 @@ namespace FourSlashInterface {
34173417

34183418
export class VerifyNegatable {
34193419
public not: VerifyNegatable;
3420+
public allowedClassElementKeywords = [
3421+
"public",
3422+
"private",
3423+
"protected",
3424+
"static",
3425+
"abstract",
3426+
"readonly",
3427+
"get",
3428+
"set",
3429+
"constructor",
3430+
"async"
3431+
];
34203432

34213433
constructor(protected state: FourSlash.TestState, private negative = false) {
34223434
if (!negative) {
@@ -3453,6 +3465,12 @@ namespace FourSlashInterface {
34533465
this.state.verifyCompletionListIsEmpty(this.negative);
34543466
}
34553467

3468+
public completionListContainsClassElementKeywords() {
3469+
for (const keyword of this.allowedClassElementKeywords) {
3470+
this.completionListContains(keyword, keyword, /*documentation*/ undefined, "keyword");
3471+
}
3472+
}
3473+
34563474
public completionListIsGlobal(expected: boolean) {
34573475
this.state.verifyCompletionListIsGlobal(expected);
34583476
}

0 commit comments

Comments
 (0)