From c0e92ba3509aa4de0c4bdc1fad45b9385affac13 Mon Sep 17 00:00:00 2001 From: Alexander Podkhalyuzin Date: Fri, 24 Aug 2018 12:31:48 +0300 Subject: [PATCH] Added resolve scope enlarger to module infos in Kotlin From now it's possible to enlarge resolve scope for analysis in IDE, the only difference is that it's based on module file. #KT-26313 Fixed --- .../kotlin/idea/caches/project/IdeaModuleInfos.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt index 8573b0e4339..3efae6433e6 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt @@ -16,6 +16,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.util.ModificationTracker import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.ResolveScopeEnlarger import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.util.CachedValueProvider import com.intellij.util.PathUtil @@ -58,6 +59,14 @@ interface IdeaModuleInfo : org.jetbrains.kotlin.idea.caches.resolve.IdeaModuleIn override fun dependencies(): List } +private fun enlargedSearchScope(searchScope: GlobalSearchScope, moduleFile: VirtualFile?): GlobalSearchScope { + if (moduleFile == null) return searchScope + return ResolveScopeEnlarger.EP_NAME.extensions.fold(searchScope) { scope, enlarger -> + val extra = enlarger.getAdditionalResolveScope(moduleFile, scope.project) + if (extra != null) scope.union(extra) else scope + } +} + private fun orderEntryToModuleInfo(project: Project, orderEntry: OrderEntry, forProduction: Boolean): List { fun Module.toInfos() = correspondingModuleInfos().filter { !forProduction || it is ModuleProductionSourceInfo } @@ -161,7 +170,7 @@ data class ModuleProductionSourceInfo internal constructor( override val stableName: Name = module.getStableName() - override fun contentScope(): GlobalSearchScope = ModuleProductionSourceScope(module) + override fun contentScope(): GlobalSearchScope = enlargedSearchScope(ModuleProductionSourceScope(module), module.moduleFile) override fun createCachedValueProvider(f: () -> CachedValueProvider.Result) = CachedValueProvider { f() } } @@ -177,7 +186,7 @@ data class ModuleTestSourceInfo internal constructor(override val module: Module override val displayedName get() = module.name + " (test)" - override fun contentScope(): GlobalSearchScope = ModuleTestSourceScope(module) + override fun contentScope(): GlobalSearchScope = enlargedSearchScope(ModuleTestSourceScope(module), module.moduleFile) override fun modulesWhoseInternalsAreVisible() = module.cached(CachedValueProvider { val list = SmartList() @@ -433,4 +442,4 @@ data class PlatformModuleInfo( } fun IdeaModuleInfo.projectSourceModules(): List? = - (this as? ModuleSourceInfo)?.let(::listOf) ?: (this as? PlatformModuleInfo)?.containedModules \ No newline at end of file + (this as? ModuleSourceInfo)?.let(::listOf) ?: (this as? PlatformModuleInfo)?.containedModules