Skip to content

Commit 1f83e66

Browse files
committed
[Completion] NFC: Factor out addBuiltinMemberRef
1 parent 02a8f24 commit 1f83e66

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

include/swift/IDE/CompletionLookup.h

+4
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

+12-6
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,15 @@ void CompletionLookup::addPrecedenceGroupRef(PrecedenceGroupDecl *PGD) {
17651765
builder.setAssociatedDecl(PGD);
17661766
}
17671767

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

22782287
unsigned Index = 0;
22792288
for (auto TupleElt : TT->getElements()) {
2280-
CodeCompletionResultBuilder Builder = makeResultBuilder(
2281-
CodeCompletionResultKind::Pattern, SemanticContextKind::CurrentNominal);
2282-
addLeadingDot(Builder);
2289+
auto Ty = TupleElt.getType();
22832290
if (TupleElt.hasName()) {
2284-
Builder.addBaseName(TupleElt.getName().str());
2291+
addBuiltinMemberRef(TupleElt.getName().str(), Ty);
22852292
} else {
22862293
llvm::SmallString<4> IndexStr;
22872294
{
22882295
llvm::raw_svector_ostream OS(IndexStr);
22892296
OS << Index;
22902297
}
2291-
Builder.addBaseName(IndexStr.str());
2298+
addBuiltinMemberRef(IndexStr, Ty);
22922299
}
2293-
addTypeAnnotation(Builder, TupleElt.getType());
22942300
++Index;
22952301
}
22962302
return true;

0 commit comments

Comments
 (0)