Skip to content

Commit 71743d6

Browse files
authored
Merge pull request #11297 from benlangmuir/cc-generic-where-assoc-1
[code-completion] Partly fix completion of associatedtypes in where clauses
2 parents 9328a43 + 46504db commit 71743d6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,15 @@ void Parser::parseDeclDelayed() {
25262526
Scope S(this, DelayedState->takeScope());
25272527
ContextChange CC(*this, DelayedState->ParentContext);
25282528

2529-
parseDecl(ParseDeclOptions(DelayedState->Flags), [](Decl *D) { });
2529+
parseDecl(ParseDeclOptions(DelayedState->Flags), [&](Decl *D) {
2530+
if (auto *parent = DelayedState->ParentContext) {
2531+
if (auto *NTD = dyn_cast<NominalTypeDecl>(parent)) {
2532+
NTD->addMember(D);
2533+
} else if (auto *ED = dyn_cast<ExtensionDecl>(parent)) {
2534+
ED->addMember(D);
2535+
}
2536+
}
2537+
});
25302538
}
25312539

25322540
/// \brief Parse an 'import' declaration, doing no token skipping on error.
@@ -3296,8 +3304,11 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
32963304
if (Tok.is(tok::kw_where)) {
32973305
auto whereStatus = parseProtocolOrAssociatedTypeWhereClause(
32983306
TrailingWhere, /*isProtocol=*/false);
3299-
if (whereStatus.shouldStopParsing())
3307+
Status |= whereStatus;
3308+
if (whereStatus.hasCodeCompletion() && !CodeCompletion) {
3309+
// Trigger delayed parsing, no need to continue.
33003310
return whereStatus;
3311+
}
33013312
}
33023313

33033314
if (!Flags.contains(PD_InProtocol)) {

test/IDE/complete_where_clause.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ protocol P2 {
109109

110110
// P2: Begin completions
111111
// P2-DAG: Decl[GenericTypeParam]/CurrNominal: Self[#Self#];
112-
// FIXME: Should complete T.
112+
// P2-DAG: Decl[AssociatedType]/CurrNominal: T;
113+
// P2-DAG: Decl[AssociatedType]/CurrNominal: U;
113114
// P2: End completions
114115

116+
// U_DOT: Begin completions
115117
// FIXME: Should complete Q from Assoc.
116-
// U_DOT-NOT: Begin completions
118+
// U_DOT-DAG: Keyword/None: Type[#Self.U.Type#];
119+
// U_DOT-DAG: Keyword/CurrNominal: self[#Self.U#];
120+
// U_DOT: End completions

0 commit comments

Comments
 (0)