Skip to content

Commit ec85151

Browse files
committed
[CodeCompletion] Add '.Protocol' completion for protocol in type context
1 parent 01b8fbc commit ec85151

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,11 +3730,15 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37303730
Kind = LookupKind::Type;
37313731
this->BaseType = BaseType;
37323732
NeedLeadingDot = !HaveDot;
3733-
Type MetaBase = MetatypeType::get(BaseType);
3734-
lookupVisibleMemberDecls(*this, MetaBase,
3733+
lookupVisibleMemberDecls(*this, MetatypeType::get(BaseType),
37353734
CurrDeclContext, TypeResolver,
37363735
IncludeInstanceMembers);
3737-
addKeyword("Type", MetaBase);
3736+
if (BaseType->isAnyExistentialType()) {
3737+
addKeyword("Protocol", MetatypeType::get(BaseType));
3738+
addKeyword("Type", ExistentialMetatypeType::get(BaseType));
3739+
} else {
3740+
addKeyword("Type", MetatypeType::get(BaseType));
3741+
}
37383742
}
37393743

37403744
static bool canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,

test/IDE/complete_type.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@
396396
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_ARGS_LOCAL_PARAM | %FileCheck %s -check-prefix=WITH_GLOBAL_TYPES
397397
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_ARGS_LOCAL_RETURN | %FileCheck %s -check-prefix=WITH_GLOBAL_TYPES
398398

399+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_DOT_1 | %FileCheck %s -check-prefix=PROTOCOL_DOT_1
400+
399401
//===--- Helper types that are used in this test
400402

401403
struct FooStruct {
@@ -1082,3 +1084,12 @@ func _testForGenericArg_() {
10821084
func foo1(x: GenStruct<#^GENERIC_ARGS_LOCAL_PARAM^#
10831085
func foo2() -> GenStruct<#^GENERIC_ARGS_LOCAL_RETURN^#
10841086
}
1087+
1088+
func testProtocol() {
1089+
let _: FooProtocol.#^PROTOCOL_DOT_1^#
1090+
// PROTOCOL_DOT_1: Begin completions, 3 items
1091+
// PROTOCOL_DOT_1-DAG: Decl[AssociatedType]/CurrNominal: FooTypeAlias1; name=FooTypeAlias1
1092+
// PROTOCOL_DOT_1-DAG: Keyword/None: Protocol[#FooProtocol.Protocol#]; name=Protocol
1093+
// PROTOCOL_DOT_1-DAG: Keyword/None: Type[#FooProtocol.Type#]; name=Type
1094+
// PROTOCOL_DOT_1: End completions
1095+
}

0 commit comments

Comments
 (0)