@@ -1764,6 +1764,15 @@ void CompletionLookup::addPrecedenceGroupRef(PrecedenceGroupDecl *PGD) {
1764
1764
builder.setAssociatedDecl (PGD);
1765
1765
}
1766
1766
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
+
1767
1776
void CompletionLookup::addEnumElementRef (const EnumElementDecl *EED,
1768
1777
DeclVisibilityKind Reason,
1769
1778
DynamicLookupInfo dynamicLookupInfo,
@@ -2276,25 +2285,34 @@ bool CompletionLookup::tryTupleExprCompletions(Type ExprType) {
2276
2285
2277
2286
unsigned Index = 0 ;
2278
2287
for (auto TupleElt : TT->getElements ()) {
2279
- CodeCompletionResultBuilder Builder = makeResultBuilder (
2280
- CodeCompletionResultKind::Pattern, SemanticContextKind::CurrentNominal);
2281
- addLeadingDot (Builder);
2288
+ auto Ty = TupleElt.getType ();
2282
2289
if (TupleElt.hasName ()) {
2283
- Builder. addBaseName (TupleElt.getName ().str ());
2290
+ addBuiltinMemberRef (TupleElt.getName ().str (), Ty );
2284
2291
} else {
2285
2292
llvm::SmallString<4 > IndexStr;
2286
2293
{
2287
2294
llvm::raw_svector_ostream OS (IndexStr);
2288
2295
OS << Index;
2289
2296
}
2290
- Builder. addBaseName (IndexStr. str () );
2297
+ addBuiltinMemberRef (IndexStr, Ty );
2291
2298
}
2292
- addTypeAnnotation (Builder, TupleElt.getType ());
2293
2299
++Index;
2294
2300
}
2295
2301
return true ;
2296
2302
}
2297
2303
2304
+ void CompletionLookup::tryFunctionIsolationCompletion (Type ExprType) {
2305
+ auto *FT = ExprType->getAs <FunctionType>();
2306
+ if (!FT || !FT->getIsolation ().isErased ())
2307
+ return ;
2308
+
2309
+ // The type of `.isolation` is `(any Actor)?`
2310
+ auto *actorProto = Ctx.getProtocol (KnownProtocolKind::Actor);
2311
+ auto memberTy = OptionalType::get (actorProto->getDeclaredExistentialType ());
2312
+
2313
+ addBuiltinMemberRef (Ctx.Id_isolation .str (), memberTy);
2314
+ }
2315
+
2298
2316
bool CompletionLookup::tryFunctionCallCompletions (
2299
2317
Type ExprType, const ValueDecl *VD,
2300
2318
std::optional<SemanticContextKind> SemanticContext) {
@@ -2372,6 +2390,9 @@ bool CompletionLookup::tryUnwrappedCompletions(Type ExprType, bool isIUO) {
2372
2390
}
2373
2391
if (NumBytesToEraseForOptionalUnwrap <=
2374
2392
CodeCompletionResult::MaxNumBytesToErase) {
2393
+ // Add '.isolation' to @isolated(any) functions.
2394
+ tryFunctionIsolationCompletion (Unwrapped);
2395
+
2375
2396
if (!tryTupleExprCompletions (Unwrapped)) {
2376
2397
lookupVisibleMemberDecls (*this , Unwrapped, DotLoc,
2377
2398
CurrDeclContext,
@@ -2447,6 +2468,10 @@ void CompletionLookup::getValueExprCompletions(Type ExprType, ValueDecl *VD,
2447
2468
ExprType = OptionalType::get (ExprType);
2448
2469
2449
2470
// Handle special cases
2471
+
2472
+ // Add '.isolation' to @isolated(any) functions.
2473
+ tryFunctionIsolationCompletion (ExprType);
2474
+
2450
2475
bool isIUO = VD && VD->isImplicitlyUnwrappedOptional ();
2451
2476
if (tryFunctionCallCompletions (ExprType, IsDeclUnapplied ? VD : nullptr ))
2452
2477
return ;
0 commit comments