Skip to content

Commit 07382fe

Browse files
committed
[CodeComplete] Don't emit 'override' in protocol extension
Also, don't emit any inherited decls in protocol declaration.
1 parent 13dd70a commit 07382fe

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,8 +4139,9 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41394139

41404140
// FIXME: if we're missing 'override', but have the decl introducer we
41414141
// should delete it and re-add both in the correct order.
4142-
bool missingOverride = Reason == DeclVisibilityKind::MemberOfSuper &&
4143-
!hasOverride;
4142+
bool missingOverride =
4143+
!hasOverride && Reason == DeclVisibilityKind::MemberOfSuper &&
4144+
!CurrDeclContext->getAsProtocolOrProtocolExtensionContext();
41444145
if (!hasDeclIntroducer && missingOverride)
41454146
Builder.addOverrideKeyword();
41464147

@@ -4192,6 +4193,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41924193
addAccessControl(CD, Builder);
41934194

41944195
if (!hasOverride && Reason == DeclVisibilityKind::MemberOfSuper &&
4196+
!CurrDeclContext->getAsProtocolOrProtocolExtensionContext() &&
41954197
CD->isDesignatedInit() && !CD->isRequired())
41964198
Builder.addOverrideKeyword();
41974199

@@ -4333,6 +4335,8 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
43334335
void getOverrideCompletions(SourceLoc Loc) {
43344336
if (!CurrDeclContext->getAsNominalTypeOrNominalTypeExtensionContext())
43354337
return;
4338+
if (isa<ProtocolDecl>(CurrDeclContext))
4339+
return;
43364340

43374341
Type CurrTy = CurrDeclContext->getDeclaredTypeInContext();
43384342
if (CurrTy && !CurrTy->is<ErrorType>()) {

test/IDE/complete_override.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
// RUN: %FileCheck %s -check-prefix=CLASS_PEI_PE < %t.txt
7979
// RUN: %FileCheck %s -check-prefix=WITH_PEI < %t.txt
8080

81+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_PA -code-completion-keywords=false > %t.txt
82+
// RUN: %FileCheck %s -check-prefix=PROTOCOL_PA < %t.txt
83+
84+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_PA_EXT -code-completion-keywords=false > %t.txt
85+
// RUN: %FileCheck %s -check-prefix=PROTOCOL_PA_EXT < %t.txt
86+
8187
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NESTED_NOMINAL -code-completion-keywords=false > %t.txt
8288
// RUN: %FileCheck %s -check-prefix=NESTED_NOMINAL < %t.txt
8389

@@ -362,6 +368,24 @@ class TestClass_PEI_PE : ProtocolEImpl, ProtocolE {
362368
}
363369
// CLASS_PEI_PE: Begin completions, 4 items
364370

371+
protocol TestProtocol_PA : ProtocolA {
372+
#^PROTOCOL_PA^#
373+
}
374+
// PROTOCOL_PA: found code completion token
375+
// PROTOCOL_PA-NOT: Begin completions
376+
377+
extension TestProtocol_PA {
378+
#^PROTOCOL_PA_EXT^#
379+
}
380+
381+
// PROTOCOL_PA_EXT: Begin completions
382+
// PROTOCOL_PA_EXT-DAG: Decl[Constructor]/Super: init(fromProtocolA: Int) {|}; name=init(fromProtocolA: Int)
383+
// PROTOCOL_PA_EXT-DAG: Decl[InstanceMethod]/Super: func protoAFunc() {|}; name=protoAFunc()
384+
// PROTOCOL_PA_EXT-DAG: Decl[InstanceMethod]/Super: func protoAFuncOptional() {|}; name=protoAFuncOptional()
385+
// PROTOCOL_PA_EXT-DAG: Decl[InstanceVar]/Super: var protoAVarRW: Int; name=protoAVarRW: Int
386+
// PROTOCOL_PA_EXT-DAG: Decl[InstanceVar]/Super: var protoAVarRO: Int; name=protoAVarRO: Int
387+
// PROTOCOL_PA_EXT: End completions
388+
365389
class OuterNominal : ProtocolA {
366390
class Inner {
367391
#^NESTED_NOMINAL^#

0 commit comments

Comments
 (0)