fix(38138): show suggestions for identifier in class property initializer (#38157)

This commit is contained in:
Alexander T 2020-04-24 23:50:34 +03:00 committed by GitHub
parent ce95d9ca6b
commit 31b81bafe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View file

@ -2685,10 +2685,16 @@ namespace ts.Completions {
return cls;
}
break;
case SyntaxKind.Identifier: // class c extends React.Component { a: () => 1\n compon| }
case SyntaxKind.Identifier: {
// class c { public prop = c| }
if (isPropertyDeclaration(location.parent) && location.parent.initializer === location) {
return undefined;
}
// class c extends React.Component { a: () => 1\n compon| }
if (isFromObjectTypeDeclaration(location)) {
return findAncestor(location, isObjectTypeDeclaration);
}
}
}
if (!contextToken) return undefined;

View file

@ -1,29 +1,32 @@
/// <reference path='fourslash.ts'/>
////class Class1 {
//// protected a = /*1*/
//// private b = /*2*/
//// public c = /*3*/
//// public d = this./*4*/
//// public a = this./*0*/
//// protected b = /*1*/
//// private c = /*2*/
//// public d = /*3*/
////}
////
////class Class2 {
//// a = /*5*/
//// a = /*4*/
////}
////class Class3 {
//// a = /*6*/
//// a = /*5*/
////}
////
////const prop = 'prop';
////class Class4 {
//// [prop] = /*7*/
//// [prop] = /*6*/
////}
const exact = completion.globalsPlus(["Class1", "Class2", "Class3", "prop", "Class4"]);
verify.completions({ marker: ["1"], exact });
verify.completions({ marker: ["2"], exact });
verify.completions({ marker: ["3"], exact });
verify.completions({ marker: ["4"], exact: ['a', 'b', 'c', 'd'], isGlobalCompletion: false });
verify.completions({ marker: ["5"], exact });
verify.completions({ marker: ["6"], exact });
verify.completions({ marker: ["7"], exact });
const markers = ["1", "2", "3", "4", "5", "6"];
verify.completions({ marker: "0", exact: ['a', 'b', 'c', 'd'], isGlobalCompletion: false });
verify.completions({ marker: markers, exact });
for (let marker of markers) {
goTo.marker(marker);
edit.insert("c");
verify.completions({ exact });
}