@@ -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+
17681777void CompletionLookup::addEnumElementRef (const EnumElementDecl *EED,
17691778 DeclVisibilityKind Reason,
17701779 DynamicLookupInfo dynamicLookupInfo,
@@ -2277,25 +2286,34 @@ 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 ;
22972303}
22982304
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+
22992317bool CompletionLookup::tryFunctionCallCompletions (
23002318 Type ExprType, const ValueDecl *VD,
23012319 std::optional<SemanticContextKind> SemanticContext) {
@@ -2373,6 +2391,9 @@ bool CompletionLookup::tryUnwrappedCompletions(Type ExprType, bool isIUO) {
23732391 }
23742392 if (NumBytesToEraseForOptionalUnwrap <=
23752393 CodeCompletionResult::MaxNumBytesToErase) {
2394+ // Add '.isolation' to @isolated(any) functions.
2395+ tryFunctionIsolationCompletion (Unwrapped);
2396+
23762397 if (!tryTupleExprCompletions (Unwrapped)) {
23772398 lookupVisibleMemberDecls (*this , Unwrapped, DotLoc,
23782399 CurrDeclContext,
@@ -2448,6 +2469,10 @@ void CompletionLookup::getValueExprCompletions(Type ExprType, ValueDecl *VD,
24482469 ExprType = OptionalType::get (ExprType);
24492470
24502471 // Handle special cases
2472+
2473+ // Add '.isolation' to @isolated(any) functions.
2474+ tryFunctionIsolationCompletion (ExprType);
2475+
24512476 bool isIUO = VD && VD->isImplicitlyUnwrappedOptional ();
24522477 if (tryFunctionCallCompletions (ExprType, IsDeclUnapplied ? VD : nullptr ))
24532478 return ;
0 commit comments