Skip to content

[IJ Plugin] Use a coroutines to prevent an IllegalStateException #6460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.apollographql.ijplugin.settings.ProjectSettingsState
import com.apollographql.ijplugin.settings.projectSettingsState
import com.apollographql.ijplugin.telemetry.telemetryService
import com.apollographql.ijplugin.util.dispose
import com.apollographql.ijplugin.util.executeOnPooledThread
import com.apollographql.ijplugin.util.isNotDisposed
import com.apollographql.ijplugin.util.logd
import com.apollographql.ijplugin.util.logw
Expand All @@ -25,6 +24,8 @@ import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.util.CheckedDisposable
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFileManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.gradle.tooling.CancellationTokenSource
import org.gradle.tooling.GradleConnector
import org.gradle.tooling.model.GradleProject
Expand All @@ -36,6 +37,7 @@ import java.io.File
@Service(Service.Level.PROJECT)
class GradleToolingModelService(
private val project: Project,
private val coroutineScope: CoroutineScope,
) : Disposable {
private var gradleHasSyncedDisposable: CheckedDisposable? = null

Expand Down Expand Up @@ -141,7 +143,7 @@ class GradleToolingModelService(
return
}

fetchToolingModelsTask = FetchToolingModelsTask().also { executeOnPooledThread { it.run() } }
fetchToolingModelsTask = FetchToolingModelsTask().also { coroutineScope.launch { it.run() } }
}

private inner class FetchToolingModelsTask : Runnable {
Expand Down
Loading