mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Completion] Complete .isolation for @isolated(any) functions
This was added in SE-0431. rdar://124615036
This commit is contained in:
@@ -510,6 +510,9 @@ public:
|
||||
|
||||
bool tryTupleExprCompletions(Type ExprType);
|
||||
|
||||
/// Try add the completion for '.isolation' for @isolated(any) function types.
|
||||
void tryFunctionIsolationCompletion(Type ExprType);
|
||||
|
||||
bool tryFunctionCallCompletions(
|
||||
Type ExprType, const ValueDecl *VD,
|
||||
std::optional<SemanticContextKind> SemanticContext = std::nullopt);
|
||||
|
||||
@@ -2302,6 +2302,18 @@ bool CompletionLookup::tryTupleExprCompletions(Type ExprType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CompletionLookup::tryFunctionIsolationCompletion(Type ExprType) {
|
||||
auto *FT = ExprType->getAs<FunctionType>();
|
||||
if (!FT || !FT->getIsolation().isErased())
|
||||
return;
|
||||
|
||||
// The type of `.isolation` is `(any Actor)?`
|
||||
auto *actorProto = Ctx.getProtocol(KnownProtocolKind::Actor);
|
||||
auto memberTy = OptionalType::get(actorProto->getDeclaredExistentialType());
|
||||
|
||||
addBuiltinMemberRef(Ctx.Id_isolation.str(), memberTy);
|
||||
}
|
||||
|
||||
bool CompletionLookup::tryFunctionCallCompletions(
|
||||
Type ExprType, const ValueDecl *VD,
|
||||
std::optional<SemanticContextKind> SemanticContext) {
|
||||
@@ -2379,6 +2391,9 @@ bool CompletionLookup::tryUnwrappedCompletions(Type ExprType, bool isIUO) {
|
||||
}
|
||||
if (NumBytesToEraseForOptionalUnwrap <=
|
||||
CodeCompletionResult::MaxNumBytesToErase) {
|
||||
// Add '.isolation' to @isolated(any) functions.
|
||||
tryFunctionIsolationCompletion(Unwrapped);
|
||||
|
||||
if (!tryTupleExprCompletions(Unwrapped)) {
|
||||
lookupVisibleMemberDecls(*this, Unwrapped, DotLoc,
|
||||
CurrDeclContext,
|
||||
@@ -2454,6 +2469,10 @@ void CompletionLookup::getValueExprCompletions(Type ExprType, ValueDecl *VD,
|
||||
ExprType = OptionalType::get(ExprType);
|
||||
|
||||
// Handle special cases
|
||||
|
||||
// Add '.isolation' to @isolated(any) functions.
|
||||
tryFunctionIsolationCompletion(ExprType);
|
||||
|
||||
bool isIUO = VD && VD->isImplicitlyUnwrappedOptional();
|
||||
if (tryFunctionCallCompletions(ExprType, IsDeclUnapplied ? VD : nullptr))
|
||||
return;
|
||||
|
||||
24
test/IDE/complete_function_isolation.swift
Normal file
24
test/IDE/complete_function_isolation.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
// RUN: %batch-code-completion
|
||||
|
||||
// REQUIRES: concurrency
|
||||
|
||||
func test1(_ x: () -> Void) {
|
||||
x.#^NORMAL_FN^#
|
||||
// NORMAL_FN: Begin completions, 2 items
|
||||
// NORMAL_FN-DAG: Keyword[self]/CurrNominal: self[#() -> Void#]; name=self
|
||||
// NORMAL_FN-DAG: Pattern/CurrModule/Flair[ArgLabels]/Erase[1]: ()[#Void#]; name=()
|
||||
}
|
||||
|
||||
func test2(_ x: @isolated(any) () -> Void) {
|
||||
x.#^ISOLATED_ANY_FN^#
|
||||
// ISOLATED_ANY_FN: Begin completions, 3 items
|
||||
// ISOLATED_ANY_FN-DAG: Pattern/CurrNominal: isolation[#(any Actor)?#]; name=isolation
|
||||
// ISOLATED_ANY_FN-DAG: Keyword[self]/CurrNominal: self[#@isolated(any) () -> Void#]; name=self
|
||||
// ISOLATED_ANY_FN-DAG: Pattern/CurrModule/Flair[ArgLabels]/Erase[1]: ()[#Void#]; name=()
|
||||
}
|
||||
|
||||
func test3(_ x: (@isolated(any) () -> Void)?) {
|
||||
x.#^ISOLATED_ANY_OPTIONAL_FN^#
|
||||
// ISOLATED_ANY_OPTIONAL_FN-DAG: Pattern/CurrNominal/Erase[1]: ?.isolation[#(any Actor)?#]; name=isolation
|
||||
// ISOLATED_ANY_OPTIONAL_FN-DAG: Keyword[self]/CurrNominal: self[#(@isolated(any) () -> Void)?#]; name=self
|
||||
}
|
||||
Reference in New Issue
Block a user