Skip to content

Commit a13c9d2

Browse files
committed
[Completion] NFC: Factor out addBuiltinMemberRef
1 parent 4058a08 commit a13c9d2

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

include/swift/IDE/CompletionLookup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
441441

442442
void addPrecedenceGroupRef(PrecedenceGroupDecl *PGD);
443443

444+
/// Add a builtin member reference pattern. This is used for members that
445+
/// do not have associated decls, e.g tuple access and '.isolation'.
446+
void addBuiltinMemberRef(StringRef Name, Type TypeAnnotation);
447+
444448
void addEnumElementRef(const EnumElementDecl *EED, DeclVisibilityKind Reason,
445449
DynamicLookupInfo dynamicLookupInfo,
446450
bool HasTypeContext);

lib/IDE/CompletionLookup.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,15 @@ void CompletionLookup::addPrecedenceGroupRef(PrecedenceGroupDecl *PGD) {
17641764
builder.setAssociatedDecl(PGD);
17651765
}
17661766

1767+
void CompletionLookup::addBuiltinMemberRef(StringRef Name,
1768+
Type TypeAnnotation) {
1769+
CodeCompletionResultBuilder Builder = makeResultBuilder(
1770+
CodeCompletionResultKind::Pattern, SemanticContextKind::CurrentNominal);
1771+
addLeadingDot(Builder);
1772+
Builder.addBaseName(Name);
1773+
addTypeAnnotation(Builder, TypeAnnotation);
1774+
}
1775+
17671776
void CompletionLookup::addEnumElementRef(const EnumElementDecl *EED,
17681777
DeclVisibilityKind Reason,
17691778
DynamicLookupInfo dynamicLookupInfo,
@@ -2276,20 +2285,17 @@ bool CompletionLookup::tryTupleExprCompletions(Type ExprType) {
22762285

22772286
unsigned Index = 0;
22782287
for (auto TupleElt : TT->getElements()) {
2279-
CodeCompletionResultBuilder Builder = makeResultBuilder(
2280-
CodeCompletionResultKind::Pattern, SemanticContextKind::CurrentNominal);
2281-
addLeadingDot(Builder);
2288+
auto Ty = TupleElt.getType();
22822289
if (TupleElt.hasName()) {
2283-
Builder.addBaseName(TupleElt.getName().str());
2290+
addBuiltinMemberRef(TupleElt.getName().str(), Ty);
22842291
} else {
22852292
llvm::SmallString<4> IndexStr;
22862293
{
22872294
llvm::raw_svector_ostream OS(IndexStr);
22882295
OS << Index;
22892296
}
2290-
Builder.addBaseName(IndexStr.str());
2297+
addBuiltinMemberRef(IndexStr, Ty);
22912298
}
2292-
addTypeAnnotation(Builder, TupleElt.getType());
22932299
++Index;
22942300
}
22952301
return true;

0 commit comments

Comments
 (0)