mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Revert "[indexing] IJPL-232427: Do not use legacy Task API for scheduling backgroundable tasks"
This reverts commit f00cf2e2 GitOrigin-RevId: 07e3d16e82366841881bab2c8cf2da6228515ac2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
807e99cb00
commit
66d0f3d8e7
@@ -2,13 +2,12 @@
|
||||
package com.intellij.openapi.project
|
||||
|
||||
import com.intellij.internal.statistic.StructuredIdeActivity
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.progress.coroutineToIndicator
|
||||
import com.intellij.openapi.progress.Task
|
||||
import com.intellij.openapi.progress.impl.ProgressManagerImpl
|
||||
import com.intellij.openapi.progress.impl.ProgressSuspender
|
||||
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase
|
||||
@@ -21,13 +20,8 @@ import com.intellij.openapi.util.NlsContexts.ProgressText
|
||||
import com.intellij.openapi.util.NlsContexts.ProgressTitle
|
||||
import com.intellij.openapi.util.UserDataHolder
|
||||
import com.intellij.openapi.wm.ex.ProgressIndicatorEx
|
||||
import com.intellij.platform.ide.progress.withBackgroundProgress
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.InternalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
@@ -202,27 +196,37 @@ open class MergingQueueGuiExecutor<T : MergeableQueueTask<T>> protected construc
|
||||
}
|
||||
}
|
||||
|
||||
open fun shouldShowProgressIndicator(): Boolean = true
|
||||
|
||||
protected open val taskId: Any? = null
|
||||
|
||||
private val schedulingDispatcher = Dispatchers.IO.limitedParallelism(1)
|
||||
|
||||
@OptIn(InternalCoroutinesApi::class)
|
||||
private fun startInBackgroundWithVisibleOrInvisibleProgress(
|
||||
onCancellation: () -> Unit,
|
||||
task: (ProgressIndicator) -> Unit,
|
||||
) {
|
||||
val actionStarted = AtomicBoolean(false)
|
||||
project.service<ScopeHolder>().scope.launch(schedulingDispatcher) {
|
||||
withBackgroundProgress(project, myProgressTitle) {
|
||||
coroutineToIndicator { indicator ->
|
||||
actionStarted.set(true)
|
||||
task(indicator)
|
||||
val backgroundableTask = object : Task.Backgroundable(project, myProgressTitle, false) {
|
||||
override fun run(visibleIndicator: ProgressIndicator) {
|
||||
actionStarted.set(true)
|
||||
task(visibleIndicator)
|
||||
}
|
||||
|
||||
override fun onCancel() {
|
||||
if (!actionStarted.get()) {
|
||||
onCancellation()
|
||||
}
|
||||
}
|
||||
}.invokeOnCompletion(onCancelling = true) {
|
||||
if (!actionStarted.get()) {
|
||||
onCancellation()
|
||||
}
|
||||
|
||||
override fun getId() = taskId
|
||||
|
||||
override fun isHeadless(): Boolean = false
|
||||
}
|
||||
|
||||
if (shouldShowProgressIndicator()) {
|
||||
ProgressManager.getInstance().run(backgroundableTask)
|
||||
}
|
||||
else {
|
||||
ProgressManager.getInstance().runProcessWithProgressAsynchronously(backgroundableTask, EmptyProgressIndicator())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +343,4 @@ open class MergingQueueGuiExecutor<T : MergeableQueueTask<T>> protected construc
|
||||
companion object {
|
||||
private val LOG = Logger.getInstance(MergingQueueGuiExecutor::class.java)
|
||||
}
|
||||
|
||||
@Service(Service.Level.PROJECT)
|
||||
private class ScopeHolder(val scope: CoroutineScope)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user