From 9e4c5eed5fb57791fb727b7b54a771af264db10f Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Fri, 30 Apr 2021 11:12:12 +0300 Subject: [PATCH] FIR IDE: Make `ModuleLibrariesSearchScope` work only on .class sources If this scope will accepts sources, then it will cause problems later (when we will get libraries' sources from indices and will try to resolve them to FIR declaration) --- .../level/api/util/ModuleLibrariesSearchScope.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/util/ModuleLibrariesSearchScope.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/util/ModuleLibrariesSearchScope.kt index aca145b5436..33b0006048b 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/util/ModuleLibrariesSearchScope.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/util/ModuleLibrariesSearchScope.kt @@ -9,19 +9,25 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.roots.JdkOrderEntry import com.intellij.openapi.roots.LibraryOrderEntry import com.intellij.openapi.roots.ModuleRootManager +import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.util.Comparing import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.search.GlobalSearchScope -private class ModuleLibrariesSearchScope(private val module: Module) : GlobalSearchScope(module.project) { +private class ModuleLibrariesSearchScope(module: Module) : GlobalSearchScope(module.project) { + private val projectFileIndex = ProjectRootManager.getInstance(module.project).fileIndex + private val moduleFileIndex = ModuleRootManager.getInstance(module).fileIndex + override fun contains(file: VirtualFile): Boolean { - val orderEntry = ModuleRootManager.getInstance(module).fileIndex.getOrderEntryForFile(file) + // We want this scope to work only on .class files, not on source files + if (!projectFileIndex.isInLibraryClasses(file)) return false + + val orderEntry = moduleFileIndex.getOrderEntryForFile(file) return orderEntry is JdkOrderEntry || orderEntry is LibraryOrderEntry } override fun compare(file1: VirtualFile, file2: VirtualFile): Int { - val fileIndex = ModuleRootManager.getInstance(module).fileIndex - return Comparing.compare(fileIndex.getOrderEntryForFile(file2), fileIndex.getOrderEntryForFile(file1)) + return Comparing.compare(moduleFileIndex.getOrderEntryForFile(file2), moduleFileIndex.getOrderEntryForFile(file1)) } override fun isSearchInModuleContent(aModule: Module): Boolean = false