Skip to content

Commit 36cd7b5

Browse files
authored
Merge pull request #7140 from rintaro/codecomplete-override-protocol
[CodeComplete] Don't emit 'override' in protocol extension
2 parents e7a16bf + 6f167e9 commit 36cd7b5

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
@@ -4140,8 +4140,9 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41404140

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

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

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

@@ -4334,6 +4336,8 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
43344336
void getOverrideCompletions(SourceLoc Loc) {
43354337
if (!CurrDeclContext->getAsNominalTypeOrNominalTypeExtensionContext())
43364338
return;
4339+
if (isa<ProtocolDecl>(CurrDeclContext))
4340+
return;
43374341

43384342
Type CurrTy = CurrDeclContext->getDeclaredTypeInContext();
43394343
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)