Merge pull request #7160 from rintaro/3.1-codecomplete-override-protocol

[3.1][CodeComplete] Don't emit 'override' in protocol extension
diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp
index 5c997ba..63d1ae7 100644
--- a/lib/IDE/CodeCompletion.cpp
+++ b/lib/IDE/CodeCompletion.cpp
@@ -4139,8 +4139,9 @@
 
     // FIXME: if we're missing 'override', but have the decl introducer we
     // should delete it and re-add both in the correct order.
-    bool missingOverride = Reason == DeclVisibilityKind::MemberOfSuper &&
-                           !hasOverride;
+    bool missingOverride =
+      !hasOverride && Reason == DeclVisibilityKind::MemberOfSuper &&
+      !CurrDeclContext->getAsProtocolOrProtocolExtensionContext();
     if (!hasDeclIntroducer && missingOverride)
       Builder.addOverrideKeyword();
 
@@ -4192,6 +4193,7 @@
       addAccessControl(CD, Builder);
 
     if (!hasOverride && Reason == DeclVisibilityKind::MemberOfSuper &&
+        !CurrDeclContext->getAsProtocolOrProtocolExtensionContext() &&
         CD->isDesignatedInit() && !CD->isRequired())
       Builder.addOverrideKeyword();
 
@@ -4333,6 +4335,8 @@
   void getOverrideCompletions(SourceLoc Loc) {
     if (!CurrDeclContext->getAsNominalTypeOrNominalTypeExtensionContext())
       return;
+    if (isa<ProtocolDecl>(CurrDeclContext))
+      return;
 
     Type CurrTy = CurrDeclContext->getDeclaredTypeInContext();
     if (CurrTy && !CurrTy->is<ErrorType>()) {
diff --git a/test/IDE/complete_override.swift b/test/IDE/complete_override.swift
index 805b7d5..e4244c6 100644
--- a/test/IDE/complete_override.swift
+++ b/test/IDE/complete_override.swift
@@ -78,6 +78,12 @@
 // RUN: %FileCheck %s -check-prefix=CLASS_PEI_PE < %t.txt
 // RUN: %FileCheck %s -check-prefix=WITH_PEI < %t.txt
 
+// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_PA -code-completion-keywords=false > %t.txt
+// RUN: %FileCheck %s -check-prefix=PROTOCOL_PA < %t.txt
+
+// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_PA_EXT -code-completion-keywords=false > %t.txt
+// RUN: %FileCheck %s -check-prefix=PROTOCOL_PA_EXT < %t.txt
+
 // RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NESTED_NOMINAL -code-completion-keywords=false > %t.txt
 // RUN: %FileCheck %s -check-prefix=NESTED_NOMINAL < %t.txt
 
@@ -362,6 +368,24 @@
 }
 // CLASS_PEI_PE: Begin completions, 4 items
 
+protocol TestProtocol_PA : ProtocolA {
+  #^PROTOCOL_PA^#
+}
+// PROTOCOL_PA: found code completion token
+// PROTOCOL_PA-NOT: Begin completions
+
+extension TestProtocol_PA {
+  #^PROTOCOL_PA_EXT^#
+}
+
+// PROTOCOL_PA_EXT: Begin completions
+// PROTOCOL_PA_EXT-DAG: Decl[Constructor]/Super:            init(fromProtocolA: Int) {|}; name=init(fromProtocolA: Int)
+// PROTOCOL_PA_EXT-DAG: Decl[InstanceMethod]/Super:         func protoAFunc() {|}; name=protoAFunc()
+// PROTOCOL_PA_EXT-DAG: Decl[InstanceMethod]/Super:         func protoAFuncOptional() {|}; name=protoAFuncOptional()
+// PROTOCOL_PA_EXT-DAG: Decl[InstanceVar]/Super:            var protoAVarRW: Int; name=protoAVarRW: Int
+// PROTOCOL_PA_EXT-DAG: Decl[InstanceVar]/Super:            var protoAVarRO: Int; name=protoAVarRO: Int
+// PROTOCOL_PA_EXT: End completions
+
 class OuterNominal : ProtocolA {
   class Inner {
     #^NESTED_NOMINAL^#