Skip to content

Commit 55868df

Browse files
committed
[Completion] Complete .isolation for @isolated(any) functions
This was added in SE-0431. rdar://124615036
1 parent 70ec977 commit 55868df

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

include/swift/IDE/CompletionLookup.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
510510

511511
bool tryTupleExprCompletions(Type ExprType);
512512

513+
/// Try add the completion for '.isolation' for @isolated(any) function types.
514+
void tryFunctionIsolationCompletion(Type ExprType);
515+
513516
bool tryFunctionCallCompletions(
514517
Type ExprType, const ValueDecl *VD,
515518
std::optional<SemanticContextKind> SemanticContext = std::nullopt);
@@ -522,7 +525,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
522525
/// \return true if the given type was Optional .
523526
bool tryUnwrappedCompletions(Type ExprType, bool isIUO);
524527

525-
void getPostfixKeywordCompletions(Type ExprType, Expr *ParsedExpr);
528+
void getPostfixBuiltinCompletions(Type ExprType, Expr *ParsedExpr);
526529

527530
/// Add code completion results after an expression of type \p ExprType.
528531
/// This includes members as well as call patterns if \p ExprType is a

lib/IDE/CompletionLookup.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,18 @@ bool CompletionLookup::tryTupleExprCompletions(Type ExprType) {
23022302
return true;
23032303
}
23042304

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+
23052317
bool CompletionLookup::tryFunctionCallCompletions(
23062318
Type ExprType, const ValueDecl *VD,
23072319
std::optional<SemanticContextKind> SemanticContext) {
@@ -2392,13 +2404,16 @@ bool CompletionLookup::tryUnwrappedCompletions(Type ExprType, bool isIUO) {
23922404
return false;
23932405
}
23942406

2395-
void CompletionLookup::getPostfixKeywordCompletions(Type ExprType,
2407+
void CompletionLookup::getPostfixBuiltinCompletions(Type ExprType,
23962408
Expr *ParsedExpr) {
23972409
if (IsSuperRefExpr)
23982410
return;
23992411

24002412
NeedLeadingDot = !HaveDot;
24012413

2414+
// Add '.isolation' to @isolated(any) functions.
2415+
tryFunctionIsolationCompletion(ExprType);
2416+
24022417
if (!ExprType->getAs<ModuleType>()) {
24032418
addKeyword(getTokenText(tok::kw_self), ExprType->getRValueType(),
24042419
SemanticContextKind::CurrentNominal,

lib/IDE/PostfixCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void PostfixCompletionCallback::collectResults(
432432
Lookup.setClosureActorIsolations(Result.ClosureActorIsolations);
433433
Lookup.setIsStaticMetatype(Result.BaseIsStaticMetaType);
434434
if (!ProcessedBaseTypes.contains(Result.BaseTy)) {
435-
Lookup.getPostfixKeywordCompletions(Result.BaseTy, BaseExpr);
435+
Lookup.getPostfixBuiltinCompletions(Result.BaseTy, BaseExpr);
436436
}
437437
Lookup.setExpectedTypes(Result.ExpectedTypes, Result.IsImpliedResult,
438438
Result.ExpectsNonVoid);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %batch-code-completion
2+
3+
// REQUIRES: concurrency
4+
5+
func test1(_ x: () -> Void) {
6+
x.#^NORMAL_FN^#
7+
// NORMAL_FN: Begin completions, 2 items
8+
// NORMAL_FN-DAG: Keyword[self]/CurrNominal: self[#() -> Void#]; name=self
9+
// NORMAL_FN-DAG: Pattern/CurrModule/Flair[ArgLabels]/Erase[1]: ()[#Void#]; name=()
10+
}
11+
12+
func test2(_ x: @isolated(any) () -> Void) {
13+
x.#^ISOLATED_ANY_FN^#
14+
// ISOLATED_ANY_FN: Begin completions, 3 items
15+
// ISOLATED_ANY_FN-DAG: Pattern/CurrNominal: isolation[#(any Actor)?#]; name=isolation
16+
// ISOLATED_ANY_FN-DAG: Keyword[self]/CurrNominal: self[#@isolated(any) () -> Void#]; name=self
17+
// ISOLATED_ANY_FN-DAG: Pattern/CurrModule/Flair[ArgLabels]/Erase[1]: ()[#Void#]; name=()
18+
}

0 commit comments

Comments
 (0)