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