From e2dbec90c68400078b91de12c3cfdd4614be472b Mon Sep 17 00:00:00 2001 From: Konstantin Nisht Date: Thu, 20 Nov 2025 12:41:37 +0100 Subject: [PATCH] [actions] IJPL-219402: Replace usages of `currentThreadCoroutineScope` in actions with `AnActionEvent#coroutineScope` GitOrigin-RevId: cbb2f4b5242e04fcfeb2d623424e35cbbf91481b --- .../images/actions/EditExternallyAction.kt | 8 ++------ .../SwitchServiceViewImplementationAction.kt | 3 +-- .../src/ConfigureServicesAction.kt | 3 +-- .../internal/CountVfsFileChildrenAction.kt | 5 ++--- .../performancePlugin/actions/SimulateFreeze.kt | 14 +++++++------- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/images/src/org/intellij/images/actions/EditExternallyAction.kt b/images/src/org/intellij/images/actions/EditExternallyAction.kt index 020d6ebc6e3a..bb4b7795a38b 100644 --- a/images/src/org/intellij/images/actions/EditExternallyAction.kt +++ b/images/src/org/intellij/images/actions/EditExternallyAction.kt @@ -6,13 +6,9 @@ import com.intellij.execution.configurations.GeneralCommandLine import com.intellij.execution.util.ExecUtil import com.intellij.ide.util.PropertiesComponent import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.ActionUpdateThread -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.openapi.actionSystem.PlatformCoreDataKeys +import com.intellij.openapi.actionSystem.* import com.intellij.openapi.application.EDT import com.intellij.openapi.diagnostic.thisLogger -import com.intellij.openapi.progress.currentThreadCoroutineScope import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.ui.Messages import com.intellij.openapi.util.Disposer @@ -120,7 +116,7 @@ internal class EditExternallyAction : DumbAwareAction() { private fun performActionWithBackingFile(e: AnActionEvent, imageFile: VirtualFile) { try { val disposable = e.getDisposable() - currentThreadCoroutineScope().launch { + e.coroutineScope.launch { try { val backingFile = imageFile.copyToBackingFile(disposable) actionPerformed(e, backingFile) diff --git a/platform/execution.serviceView/frontend/src/com/intellij/platform/execution/serviceView/frontend/SwitchServiceViewImplementationAction.kt b/platform/execution.serviceView/frontend/src/com/intellij/platform/execution/serviceView/frontend/SwitchServiceViewImplementationAction.kt index 65717de4b041..baa38e9378e5 100644 --- a/platform/execution.serviceView/frontend/src/com/intellij/platform/execution/serviceView/frontend/SwitchServiceViewImplementationAction.kt +++ b/platform/execution.serviceView/frontend/src/com/intellij/platform/execution/serviceView/frontend/SwitchServiceViewImplementationAction.kt @@ -9,7 +9,6 @@ import com.intellij.openapi.actionSystem.remoting.ActionRemoteBehaviorSpecificat import com.intellij.openapi.application.EDT import com.intellij.openapi.application.ex.ApplicationManagerEx import com.intellij.openapi.diagnostic.thisLogger -import com.intellij.openapi.progress.currentThreadCoroutineScope import com.intellij.openapi.project.DumbAwareToggleAction import com.intellij.openapi.ui.Messages import com.intellij.openapi.util.registry.Registry @@ -38,7 +37,7 @@ internal class SwitchServiceViewImplementationAction : DumbAwareToggleAction(), } override fun setSelected(e: AnActionEvent, state: Boolean) { - currentThreadCoroutineScope().launch { + e.coroutineScope.launch { val app = ApplicationManagerEx.getApplicationEx() val restartAllowed = withContext(Dispatchers.EDT) { if (app == null) { diff --git a/platform/execution.serviceView/src/ConfigureServicesAction.kt b/platform/execution.serviceView/src/ConfigureServicesAction.kt index 76f748a06ced..06af6009d123 100644 --- a/platform/execution.serviceView/src/ConfigureServicesAction.kt +++ b/platform/execution.serviceView/src/ConfigureServicesAction.kt @@ -9,7 +9,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.PlatformDataKeys import com.intellij.openapi.actionSystem.remoting.ActionRemoteBehaviorSpecification import com.intellij.openapi.application.EDT -import com.intellij.openapi.progress.currentThreadCoroutineScope import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.wm.ToolWindowId import com.intellij.platform.execution.serviceView.splitApi.ServiceViewRpc @@ -37,7 +36,7 @@ internal class ConfigureServicesAction : DumbAwareAction(), ActionRemoteBehavior (ServiceViewManager.getInstance(project) as ServiceViewManagerImpl).includeToolWindow(toolWindow.id) } else { - currentThreadCoroutineScope().launch { + e.coroutineScope.launch { val settings = ServiceViewRpc.getInstance().loadConfigurationTypes(project.projectId()) ?: return@launch withContext(Dispatchers.EDT) { ConfigureServicesDialog(project, settings).show() diff --git a/platform/lang-impl/src/com/intellij/internal/CountVfsFileChildrenAction.kt b/platform/lang-impl/src/com/intellij/internal/CountVfsFileChildrenAction.kt index b1cb810733c1..107c8a3cef7c 100644 --- a/platform/lang-impl/src/com/intellij/internal/CountVfsFileChildrenAction.kt +++ b/platform/lang-impl/src/com/intellij/internal/CountVfsFileChildrenAction.kt @@ -8,7 +8,6 @@ import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys.VIRTUAL_FILE import com.intellij.openapi.application.runReadAction -import com.intellij.openapi.progress.currentThreadCoroutineScope import com.intellij.openapi.project.DumbAware import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.openapi.vfs.VfsUtilCore @@ -37,7 +36,7 @@ internal class CountVfsFileChildrenAction : AnAction(), DumbAware { val root = VIRTUAL_FILE.getData(e.dataContext) ?: return val project = e.project ?: return - currentThreadCoroutineScope().launch(Dispatchers.Default) { + e.coroutineScope.launch(Dispatchers.Default) { withBackgroundProgress(project, "Counting children on disk recursively...") { reportRawProgress { reporter -> var filesOnDiskCount = 0 @@ -61,7 +60,7 @@ internal class CountVfsFileChildrenAction : AnAction(), DumbAware { } } - currentThreadCoroutineScope().launch(Dispatchers.Default) { + e.coroutineScope.launch(Dispatchers.Default) { val fileIndex = ProjectFileIndex.getInstance(project) val workspaceFileIndex = WorkspaceFileIndex.getInstance(project) withBackgroundProgress(project, "Counting children in VFS recursively...") { diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/actions/SimulateFreeze.kt b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/actions/SimulateFreeze.kt index 4062510fc2f6..467d51d24db1 100644 --- a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/actions/SimulateFreeze.kt +++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/actions/SimulateFreeze.kt @@ -7,12 +7,12 @@ import com.intellij.openapi.application.EDT import com.intellij.openapi.application.readAction import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.progress.ProgressManager -import com.intellij.openapi.progress.currentThreadCoroutineScope import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.ui.InputValidator import com.intellij.openapi.ui.Messages import com.intellij.openapi.util.text.StringUtil import com.intellij.util.application +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Semaphore @@ -34,23 +34,23 @@ internal abstract class SimulateFreezeBase : DumbAwareAction() { override fun checkInput(inputString: String?): Boolean = StringUtil.parseInt(inputString, -1) > 0 override fun canClose(inputString: String?): Boolean = StringUtil.parseInt(inputString, -1) > 0 }) ?: return - simulatedFreeze(durationString.toLong()) + simulatedFreeze(e.coroutineScope, durationString.toLong()) } - protected abstract fun simulatedFreeze(ms: Long) + protected abstract fun simulatedFreeze(scope: CoroutineScope, ms: Long) } internal class SimulateFreeze : SimulateFreezeBase() { - override fun simulatedFreeze(ms: Long) { + override fun simulatedFreeze(scope: CoroutineScope, ms: Long) { Thread.sleep(ms) } } internal class SimulateRWFreeze : SimulateFreezeBase() { - override fun simulatedFreeze(ms: Long) { + override fun simulatedFreeze(scope: CoroutineScope, ms: Long) { val semaphore = Semaphore(1, 1) - currentThreadCoroutineScope().launch { + scope.launch { val counter = AtomicInteger(0) readAction { semaphore.release() @@ -70,7 +70,7 @@ internal class SimulateRWFreeze : SimulateFreezeBase() { } } - currentThreadCoroutineScope().launch { + scope.launch { semaphore.acquire() logger().info("start write-action") withContext(Dispatchers.EDT) {