Refactor coroutine agent searching process master
authorNikita Nazarov <nikita.nazarov@jetbrains.com>
Wed, 4 Aug 2021 12:55:54 +0000 (15:55 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 4 Aug 2021 19:09:41 +0000 (19:09 +0000)
(cherry picked from commit 28acc65c61c51328c15e7eed5da5f0ddccfbebaa)

IJ-MR-12657

GitOrigin-RevId: 13c078b28983d5ca6f786df3fbc4fa65366e4fb1

plugins/kotlin/jvm-debugger/coroutines/kotlin.jvm-debugger.coroutines.iml
plugins/kotlin/jvm-debugger/coroutines/src/org/jetbrains/kotlin/idea/debugger/coroutine/CoroutineAgentConnector.kt

index c35b306680c3ea63be9d37c13d16763e75c3ea5a..5f0db253424546765714a595622c68ea565f8496 100644 (file)
@@ -39,5 +39,6 @@
     <orderEntry type="module" module-name="intellij.java.debugger.impl" />
     <orderEntry type="module" module-name="intellij.platform.core.ui" />
     <orderEntry type="module" module-name="intellij.platform.ide.util.io" />
+    <orderEntry type="module" module-name="intellij.platform.smRunner" />
   </component>
 </module>
\ No newline at end of file
index 5cf98dd817bd41861b4ab59595cbe19d5904d03b..be59df3a572f694244e716d4ba3f0f4b6972b862 100644 (file)
@@ -1,12 +1,12 @@
 // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 package org.jetbrains.kotlin.idea.debugger.coroutine
 
+import com.intellij.execution.JavaTestConfigurationWithDiscoverySupport
 import com.intellij.execution.configurations.JavaParameters
 import com.intellij.execution.configurations.ModuleBasedConfiguration
 import com.intellij.execution.configurations.RunConfigurationBase
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.projectRoots.JdkUtil
-import com.intellij.openapi.vfs.VirtualFile
 import com.intellij.openapi.vfs.newvfs.ArchiveFileSystem
 import com.intellij.psi.JavaPsiFacade
 import com.intellij.psi.search.GlobalSearchScope
@@ -41,7 +41,9 @@ internal object CoroutineAgentConnector {
     private fun findKotlinxCoroutinesCoreJar(project: Project, configuration: RunConfigurationBase<*>?): KotlinxCoroutinesSearchResult {
         val matchResult = project
             .getJarVirtualFiles(project, configuration, kotlinxCoroutinesPackageName)
-            .matchToPackageRegexInProject(project, kotlinxCoroutinesCoreJarRegex)
+            .asSequence()
+            .mapNotNull { kotlinxCoroutinesCoreJarRegex.matchEntire(it) }
+            .firstOrNull()
 
         if (matchResult == null || matchResult.groupValues.size < 3) {
             return KotlinxCoroutinesSearchResult(null, CoroutineDebuggerMode.DISABLED)
@@ -52,28 +54,25 @@ internal object CoroutineAgentConnector {
         )
     }
 
-    private fun List<VirtualFile>.matchToPackageRegexInProject(project: Project, regex: Regex): MatchResult? {
-        var matchResult: MatchResult?
-        val projectScope = GlobalSearchScope.allScope(project)
-        for (file in this) {
-            val jarPath = file.path.getParentJarPath() ?: continue
-            matchResult = regex.matchEntire(jarPath)
-            if (matchResult != null && projectScope.contains(file)) {
-                return matchResult
-            }
-        }
-        return null
-    }
-
-    private fun Project.getJarVirtualFiles(project: Project, configuration: RunConfigurationBase<*>?, packageName: String): List<VirtualFile> {
+    private fun Project.getJarVirtualFiles(
+        project: Project,
+        configuration: RunConfigurationBase<*>?,
+        packageName: String
+    ): List<String> {
         val kotlinxCoroutinesPackage = JavaPsiFacade.getInstance(this)
             .findPackage(packageName)
             ?: return emptyList()
         var scope = GlobalSearchScope.allScope(project)
         if (configuration is ModuleBasedConfiguration<*, *>) {
-            configuration.configurationModule.module?.let { scope = it.getModuleRuntimeScope(true) }
+            configuration.configurationModule.module?.let {
+                scope = it.getModuleRuntimeScope(
+                    configuration is JavaTestConfigurationWithDiscoverySupport
+                )
+            }
+        }
+        return kotlinxCoroutinesPackage.getDirectories(scope).mapNotNull {
+            it.virtualFile.path.getParentJarPath()
         }
-        return kotlinxCoroutinesPackage.getDirectories(scope).mapNotNull { it.virtualFile }
     }
 
     private fun String.getParentJarPath(): String? {