@@ -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+
17671776void CompletionLookup::addEnumElementRef (const EnumElementDecl *EED,
17681777 DeclVisibilityKind Reason,
17691778 DynamicLookupInfo dynamicLookupInfo,
@@ -2276,25 +2285,34 @@ 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 ;
22962302}
22972303
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+
22982316bool CompletionLookup::tryFunctionCallCompletions (
22992317 Type ExprType, const ValueDecl *VD,
23002318 std::optional<SemanticContextKind> SemanticContext) {
@@ -2372,6 +2390,9 @@ bool CompletionLookup::tryUnwrappedCompletions(Type ExprType, bool isIUO) {
23722390 }
23732391 if (NumBytesToEraseForOptionalUnwrap <=
23742392 CodeCompletionResult::MaxNumBytesToErase) {
2393+ // Add '.isolation' to @isolated(any) functions.
2394+ tryFunctionIsolationCompletion (Unwrapped);
2395+
23752396 if (!tryTupleExprCompletions (Unwrapped)) {
23762397 lookupVisibleMemberDecls (*this , Unwrapped, DotLoc,
23772398 CurrDeclContext,
@@ -2447,6 +2468,10 @@ void CompletionLookup::getValueExprCompletions(Type ExprType, ValueDecl *VD,
24472468 ExprType = OptionalType::get (ExprType);
24482469
24492470 // Handle special cases
2471+
2472+ // Add '.isolation' to @isolated(any) functions.
2473+ tryFunctionIsolationCompletion (ExprType);
2474+
24502475 bool isIUO = VD && VD->isImplicitlyUnwrappedOptional ();
24512476 if (tryFunctionCallCompletions (ExprType, IsDeclUnapplied ? VD : nullptr ))
24522477 return ;
0 commit comments