mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
Refactor coroutine agent searching process
(cherry picked from commit 28acc65c61c51328c15e7eed5da5f0ddccfbebaa) IJ-MR-12657 GitOrigin-RevId: 13c078b28983d5ca6f786df3fbc4fa65366e4fb1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
60e8658719
commit
cc5d194e27
@@ -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>
|
||||
@@ -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? {
|
||||
|
||||
Reference in New Issue
Block a user