diff --git a/src/services/completions.ts b/src/services/completions.ts index bb08fe7d54..a1e98a03d8 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -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; diff --git a/tests/cases/fourslash/completionsClassPropertiesAssignment.ts b/tests/cases/fourslash/completionsClassPropertiesAssignment.ts index a3be4038c3..cb9aa111df 100644 --- a/tests/cases/fourslash/completionsClassPropertiesAssignment.ts +++ b/tests/cases/fourslash/completionsClassPropertiesAssignment.ts @@ -1,29 +1,32 @@ /// ////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 }); +}