AA: remove unnecessary source path retrieval/cache
Instead, use source module's contentScope
This commit is contained in:
committed by
Ilya Kirillov
parent
a68fd25982
commit
47b0e66ca1
+2
-22
@@ -11,39 +11,19 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||
import org.jetbrains.kotlin.analysis.project.structure.ProjectStructureProvider
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.cli.jvm.config.javaSourceRoots
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
internal class ProjectStructureProviderByCompilerConfiguration(
|
||||
private val compilerConfig: CompilerConfiguration,
|
||||
compilerConfig: CompilerConfiguration,
|
||||
project: Project,
|
||||
ktFiles: List<KtFile>,
|
||||
jarFileSystem: CoreJarFileSystem,
|
||||
) : ProjectStructureProvider() {
|
||||
private val sourceFiles: Set<String> by lazy {
|
||||
buildSet {
|
||||
compilerConfig.javaSourceRoots.forEach { srcRoot ->
|
||||
val path = Paths.get(srcRoot)
|
||||
if (Files.isDirectory(path)) {
|
||||
// E.g., project/app/src
|
||||
Files.walk(path)
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach { add(it.toString()) }
|
||||
} else {
|
||||
// E.g., project/app/src/some/pkg/main.kt
|
||||
add(srcRoot)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val sourceModule = KtSourceModuleByCompilerConfiguration(compilerConfig, project, ktFiles, jarFileSystem)
|
||||
|
||||
override fun getKtModuleForKtElement(element: PsiElement): KtModule {
|
||||
val containingFile = element.containingFile.virtualFile
|
||||
return if (containingFile.path in sourceFiles) {
|
||||
return if (containingFile in sourceModule.contentScope) {
|
||||
sourceModule
|
||||
} else {
|
||||
sourceModule.directRegularDependencies.find { libModule -> containingFile in libModule.contentScope }
|
||||
|
||||
Reference in New Issue
Block a user