Skip to content

Commit 31b81ba

Browse files
authored
fix(38138): show suggestions for identifier in class property initializer (#38157)
1 parent ce95d9c commit 31b81ba

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/services/completions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,10 +2685,16 @@ namespace ts.Completions {
26852685
return cls;
26862686
}
26872687
break;
2688-
case SyntaxKind.Identifier: // class c extends React.Component { a: () => 1\n compon| }
2688+
case SyntaxKind.Identifier: {
2689+
// class c { public prop = c| }
2690+
if (isPropertyDeclaration(location.parent) && location.parent.initializer === location) {
2691+
return undefined;
2692+
}
2693+
// class c extends React.Component { a: () => 1\n compon| }
26892694
if (isFromObjectTypeDeclaration(location)) {
26902695
return findAncestor(location, isObjectTypeDeclaration);
26912696
}
2697+
}
26922698
}
26932699

26942700
if (!contextToken) return undefined;
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
/// <reference path='fourslash.ts'/>
22

33
////class Class1 {
4-
//// protected a = /*1*/
5-
//// private b = /*2*/
6-
//// public c = /*3*/
7-
//// public d = this./*4*/
4+
//// public a = this./*0*/
5+
//// protected b = /*1*/
6+
//// private c = /*2*/
7+
//// public d = /*3*/
88
////}
99
////
1010
////class Class2 {
11-
//// a = /*5*/
11+
//// a = /*4*/
1212
////}
1313
////class Class3 {
14-
//// a = /*6*/
14+
//// a = /*5*/
1515
////}
1616
////
1717
////const prop = 'prop';
1818
////class Class4 {
19-
//// [prop] = /*7*/
19+
//// [prop] = /*6*/
2020
////}
2121

2222
const exact = completion.globalsPlus(["Class1", "Class2", "Class3", "prop", "Class4"]);
23-
verify.completions({ marker: ["1"], exact });
24-
verify.completions({ marker: ["2"], exact });
25-
verify.completions({ marker: ["3"], exact });
26-
verify.completions({ marker: ["4"], exact: ['a', 'b', 'c', 'd'], isGlobalCompletion: false });
27-
verify.completions({ marker: ["5"], exact });
28-
verify.completions({ marker: ["6"], exact });
29-
verify.completions({ marker: ["7"], exact });
23+
const markers = ["1", "2", "3", "4", "5", "6"];
24+
25+
verify.completions({ marker: "0", exact: ['a', 'b', 'c', 'd'], isGlobalCompletion: false });
26+
verify.completions({ marker: markers, exact });
27+
28+
for (let marker of markers) {
29+
goTo.marker(marker);
30+
edit.insert("c");
31+
verify.completions({ exact });
32+
}

0 commit comments

Comments
 (0)