FIR CLI: use VFS for LT files loading
may improve performance in some cases and is consistent with handling of PSI files
This commit is contained in:
@@ -107,6 +107,9 @@ open class VfsBasedProjectEnvironment(
|
||||
baseModuleData: FirModuleData,
|
||||
fileSearchScope: AbstractProjectFileSearchScope
|
||||
) = FirJavaFacade(firSession, baseModuleData, project.createJavaClassFinder(fileSearchScope.asPsiSearchScope()))
|
||||
|
||||
override fun getFileText(filePath: String): String? =
|
||||
localFileSystem.findFileByPath(filePath)?.inputStream?.reader(Charsets.UTF_8)?.readText()
|
||||
}
|
||||
|
||||
private fun AbstractProjectFileSearchScope.asPsiSearchScope() =
|
||||
|
||||
@@ -311,8 +311,14 @@ fun compileModuleToAnalyzedFir(
|
||||
val countFilesAndLines = if (performanceManager == null) null else performanceManager::addSourcesStats
|
||||
|
||||
// raw fir
|
||||
val commonRawFir = commonSession?.buildFirViaLightTree(input.commonSources, diagnosticsReporter, countFilesAndLines)
|
||||
val rawFir = session.buildFirViaLightTree(input.platformSources, diagnosticsReporter, countFilesAndLines)
|
||||
val commonRawFir = commonSession?.buildFirViaLightTree(
|
||||
input.commonSources,
|
||||
environment.projectEnvironment,
|
||||
diagnosticsReporter,
|
||||
countFilesAndLines
|
||||
)
|
||||
val rawFir =
|
||||
session.buildFirViaLightTree(input.platformSources, environment.projectEnvironment, diagnosticsReporter, countFilesAndLines)
|
||||
|
||||
// resolution
|
||||
commonSession?.apply {
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.pipeline
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import com.intellij.openapi.util.text.StringUtilRt
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.builder.PsiHandlingMode
|
||||
@@ -15,12 +14,15 @@ import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.lightTree.LightTree2Fir
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.impl.FirProviderImpl
|
||||
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment
|
||||
import org.jetbrains.kotlin.fir.session.sourcesToPathsMapper
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
fun FirSession.buildFirViaLightTree(
|
||||
files: Collection<File>,
|
||||
projectEnvironment: AbstractProjectEnvironment,
|
||||
diagnosticsReporter: DiagnosticReporter? = null,
|
||||
reportFilesAndLines: ((Int, Int) -> Unit)? = null
|
||||
): List<FirFile> {
|
||||
@@ -30,7 +32,8 @@ fun FirSession.buildFirViaLightTree(
|
||||
val shouldCountLines = (reportFilesAndLines != null)
|
||||
var linesCount = 0
|
||||
val firFiles = files.map { file ->
|
||||
val code = FileUtil.loadFile(file, CharsetToolkit.UTF8, true /* code below relies on conversion */)
|
||||
val text = projectEnvironment.getFileText(file.absolutePath) ?: throw FileNotFoundException(file.path)
|
||||
val code = StringUtilRt.convertLineSeparators(text)
|
||||
if (shouldCountLines) {
|
||||
linesCount += code.count { it == '\n' } // assuming converted line separators
|
||||
}
|
||||
|
||||
+2
@@ -60,4 +60,6 @@ interface AbstractProjectEnvironment {
|
||||
baseModuleData: FirModuleData,
|
||||
fileSearchScope: AbstractProjectFileSearchScope
|
||||
): FirJavaFacade
|
||||
|
||||
fun getFileText(filePath: String): String?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user