From 3171d082a6c126a0930e3b94cb2f791e2d059069 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Oct 2017 10:52:29 -0700 Subject: [PATCH] Handle the case of completion of class member when member name is being edited Fixes #17977 --- src/services/completions.ts | 5 +++ .../completionEntryForClassMembers3.ts | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/cases/fourslash/completionEntryForClassMembers3.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 44ad611de7..c222425693 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1195,6 +1195,11 @@ namespace ts.Completions { if (isClassLike(location)) { return location; } + // class c { method() { } b| } + if (isFromClassElementDeclaration(location) && + (location.parent as ClassElement).name === location) { + return location.parent.parent as ClassLikeDeclaration; + } break; default: diff --git a/tests/cases/fourslash/completionEntryForClassMembers3.ts b/tests/cases/fourslash/completionEntryForClassMembers3.ts new file mode 100644 index 0000000000..a27c5959e6 --- /dev/null +++ b/tests/cases/fourslash/completionEntryForClassMembers3.ts @@ -0,0 +1,32 @@ +/// + +////interface IFoo { +//// bar(): void; +////} +////class Foo1 implements IFoo { +//// zap() { } +//// /*1*/ +////} +////class Foo2 implements IFoo { +//// zap() { } +//// b/*2*/() { } +////} +////class Foo3 implements IFoo { +//// zap() { } +//// b/*3*/: any; +////} +const allowedKeywordCount = verify.allowedClassElementKeywords.length; +function verifyHasBar() { + verify.completionListContains("bar", "(method) IFoo.bar(): void", /*documentation*/ undefined, "method"); + verify.completionListContainsClassElementKeywords(); + verify.completionListCount(allowedKeywordCount + 1); +} + +goTo.marker("1"); +verifyHasBar(); +edit.insert("b"); +verifyHasBar(); +goTo.marker("2"); +verifyHasBar(); +goTo.marker("3"); +verifyHasBar(); \ No newline at end of file