From ef4ee615501842fd2a62ffc262db0eace71e02c9 Mon Sep 17 00:00:00 2001 From: Lamberto Basti Date: Wed, 21 Feb 2024 11:14:01 +0100 Subject: [PATCH] Implement cancellation for external system initialization (#81) Modified the Project.awaitExternalSystemInitialization() function in Utils.kt to enable cancellation using suspendCancellableCoroutine instead of suspendCoroutine. Co-authored-by: Lamberto Basti --- package-search-api-models | 2 +- .../com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-search-api-models b/package-search-api-models index 8f144648..aef27525 160000 --- a/package-search-api-models +++ b/package-search-api-models @@ -1 +1 @@ -Subproject commit 8f14464807da90ce08980e589d9d805e6b9d8e76 +Subproject commit aef275250b832e73fa12ce9ce94a7b242d925468 diff --git a/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt b/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt index 6ab3ed6b..8ba19c33 100644 --- a/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt +++ b/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt @@ -8,7 +8,7 @@ import com.intellij.openapi.project.Project import com.jetbrains.packagesearch.plugin.core.extensions.DependencyDeclarationIndexes import com.jetbrains.packagesearch.plugin.gradle.GradleDependencyModel import kotlin.coroutines.resume -import kotlin.coroutines.suspendCoroutine +import kotlinx.coroutines.suspendCancellableCoroutine import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.plugins.gradle.util.GradleConstants @@ -18,7 +18,7 @@ val Module.isGradleSourceSet: Boolean return ExternalSystemApiUtil.getExternalModuleType(this) == GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY } -suspend fun Project.awaitExternalSystemInitialization() = suspendCoroutine { +suspend fun Project.awaitExternalSystemInitialization() = suspendCancellableCoroutine { ExternalProjectsManager.getInstance(this@awaitExternalSystemInitialization) .runWhenInitialized { it.resume(Unit) } }