diff --git a/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/Utils.kt b/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/Utils.kt index bb13e54f..8b1e3e90 100644 --- a/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/Utils.kt +++ b/plugin/core/src/main/kotlin/com/jetbrains/packagesearch/plugin/core/utils/Utils.kt @@ -11,9 +11,12 @@ import com.intellij.openapi.extensions.AreaInstance import com.intellij.openapi.extensions.ExtensionPointListener import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.extensions.PluginDescriptor +import com.intellij.openapi.externalSystem.model.ProjectSystemId import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataImportListener +import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.fileEditor.FileEditorManagerListener +import com.intellij.openapi.module.Module import com.intellij.openapi.project.DumbService import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer @@ -355,4 +358,7 @@ class ProjectDataImportListenerAdapter(private val project: Project) : ProjectDa } } +val Module.isSourceSet + get() = ExternalSystemApiUtil.getExternalModuleType(this) == "sourceSet" + fun Result.suspendSafe() = onFailure { if (it is CancellationException) throw it } diff --git a/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/GradleModuleTransformer.kt b/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/GradleModuleTransformer.kt index 1a2eafb4..c85e7e16 100644 --- a/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/GradleModuleTransformer.kt +++ b/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/GradleModuleTransformer.kt @@ -18,12 +18,12 @@ import com.jetbrains.packagesearch.plugin.core.utils.smartModeFlow import com.jetbrains.packagesearch.plugin.gradle.utils.awaitExternalSystemInitialization import com.jetbrains.packagesearch.plugin.gradle.utils.getModuleChangesFlow import com.jetbrains.packagesearch.plugin.gradle.utils.initializeProjectFlow -import com.jetbrains.packagesearch.plugin.gradle.utils.isGradleSourceSet +import com.jetbrains.packagesearch.plugin.gradle.utils.isGradle import com.jetbrains.packagesearch.plugin.gradle.utils.isResolveTask import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.FlowCollector import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.filterNot +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map @@ -50,7 +50,7 @@ abstract class AbstractGradleModuleProvider : PackageSearchModuleProvider { nativeModule: NativeModule, ): Flow = merge(project.smartModeFlow, project.isProjectImportingFlow, project.initializeProjectFlow) - .filterNot { nativeModule.isGradleSourceSet } + .filter { nativeModule.isGradle } .mapNotNull { findGradleModuleData(nativeModule) ?.let { ExternalSystemApiUtil.find(it, PackageSearchGradleModel.DATA_NODE_KEY) } @@ -97,5 +97,3 @@ class GradleSyncNotifierService : ExternalSystemTaskNotificationListenerAdapter( } } } - - diff --git a/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt b/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt index 8ba19c33..d56fc74b 100644 --- a/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt +++ b/plugin/gradle/src/main/kotlin/com/jetbrains/packagesearch/plugin/gradle/utils/Utils.kt @@ -1,22 +1,23 @@ package com.jetbrains.packagesearch.plugin.gradle.utils import com.android.tools.idea.gradle.dsl.api.dependencies.ArtifactDependencyModel +import com.intellij.openapi.externalSystem.model.ProjectSystemId import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project import com.jetbrains.packagesearch.plugin.core.extensions.DependencyDeclarationIndexes +import com.jetbrains.packagesearch.plugin.core.utils.isSourceSet import com.jetbrains.packagesearch.plugin.gradle.GradleDependencyModel import kotlin.coroutines.resume import kotlinx.coroutines.suspendCancellableCoroutine import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.plugins.gradle.util.GradleConstants -val Module.isGradleSourceSet: Boolean - get() { - if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, this)) return false - return ExternalSystemApiUtil.getExternalModuleType(this) == GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY - } +private val GRADLE_SYSTEM_ID get() = ProjectSystemId("GRADLE") + +val Module.isGradle + get() = ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, this) && !isSourceSet suspend fun Project.awaitExternalSystemInitialization() = suspendCancellableCoroutine { ExternalProjectsManager.getInstance(this@awaitExternalSystemInitialization) diff --git a/plugin/maven/src/main/kotlin/com/jetbrains/packagesearch/plugin/maven/MavenModuleProvider.kt b/plugin/maven/src/main/kotlin/com/jetbrains/packagesearch/plugin/maven/MavenModuleProvider.kt index 018e479d..ed01df8a 100644 --- a/plugin/maven/src/main/kotlin/com/jetbrains/packagesearch/plugin/maven/MavenModuleProvider.kt +++ b/plugin/maven/src/main/kotlin/com/jetbrains/packagesearch/plugin/maven/MavenModuleProvider.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule import com.jetbrains.packagesearch.plugin.core.extensions.PackageSearchModuleBuilderContext import com.jetbrains.packagesearch.plugin.core.extensions.PackageSearchModuleProvider +import com.jetbrains.packagesearch.plugin.core.utils.isSourceSet import com.jetbrains.packagesearch.plugin.core.utils.smartModeFlow import java.nio.file.Paths import kotlinx.coroutines.flow.Flow @@ -14,20 +15,22 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.take import com.intellij.openapi.module.Module as NativeModule class MavenModuleProvider : PackageSearchModuleProvider { context(PackageSearchModuleBuilderContext) - override fun provideModule(nativeModule: NativeModule): Flow = nativeModule.project - .smartModeFlow - .flatMapLatest { + override fun provideModule(nativeModule: NativeModule): Flow = when { + nativeModule.isSourceSet -> emptyFlow() + else -> project.smartModeFlow.take(1).flatMapLatest { when (val mavenProject = project.findMavenProjectFor(nativeModule)) { null -> emptyFlow() else -> getModuleChangesFlow(Paths.get(mavenProject.file.path)) .map { nativeModule.toPackageSearch(mavenProject) } } } + } override fun getSyncStateFlow(project: Project): Flow = project.service().asStateFlow()