Skip to content

Commit 0dd0092

Browse files
committed
[CodeCompletion] Only suggest generic params in where for non-protocol
nominal types
1 parent ea68861 commit 0dd0092

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,6 +3968,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
39683968
DeclVisibilityKind::GenericParameter, {});
39693969
}
39703970

3971+
// For non-protocol nominal type decls, only suggest generic parameters.
3972+
if (auto D = DC->getAsDecl())
3973+
if (isa<NominalTypeDecl>(D) && !isa<ProtocolDecl>(D))
3974+
return;
3975+
39713976
auto typeContext = DC->getInnermostTypeContext();
39723977
if (!typeContext)
39733978
return;

test/IDE/complete_where_clause.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL | %FileCheck %s -check-prefix=PROTOCOL
3333
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_EXT | %FileCheck %s -check-prefix=PROTOCOL
3434
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_SELF | %FileCheck %s -check-prefix=PROTOCOL_SELF
35+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NOMINAL_TYPEALIAS | %FileCheck %s -check-prefix=NOMINAL_TYPEALIAS
36+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NOMINAL_TYPEALIAS_EXT | %FileCheck %s -check-prefix=NOMINAL_TYPEALIAS_EXT
3537

3638
class A1<T1, T2, T3> {}
3739

@@ -177,3 +179,15 @@ protocol P4 where Self.#^PROTOCOL_SELF^# {
177179
// PROTOCOL_SELF-DAG: Decl[TypeAlias]/CurrNominal: IntAlias[#Int#];
178180
// PROTOCOL_SELF-DAG: Keyword/None: Type[#Self.Type#];
179181
// PROTOCOL_SELF: End completions
182+
183+
struct TA1<T: Assoc> where #^NOMINAL_TYPEALIAS^# {
184+
typealias U = T.Q
185+
}
186+
// NOMINAL_TYPEALIAS: Begin completions, 1 items
187+
// NOMINAL_TYPEALIAS-DAG: Decl[GenericTypeParam]/Local: T[#T#];
188+
// NOMINAL_TYPEALIAS: End completions
189+
extension TA1 where #^NOMINAL_TYPEALIAS_EXT^# { }
190+
// NOMINAL_TYPEALIAS_EXT: Begin completions, 2 items
191+
// NOMINAL_TYPEALIAS_EXT-DAG: Decl[GenericTypeParam]/Local: T[#T#];
192+
// NOMINAL_TYPEALIAS_EXT-DAG: Decl[TypeAlias]/CurrNominal: U[#T.Q#];
193+
// NOMINAL_TYPEALIAS_EXT: End completions

0 commit comments

Comments
 (0)