Delegate to global cache when building ModuleResolverProvider for synthetic files
This commit is contained in:
+34
-11
@@ -65,9 +65,9 @@ public class KotlinCacheService(val project: Project) {
|
|||||||
fun globalResolveSessionProvider(
|
fun globalResolveSessionProvider(
|
||||||
platform: TargetPlatform,
|
platform: TargetPlatform,
|
||||||
dependencies: Collection<Any>,
|
dependencies: Collection<Any>,
|
||||||
|
moduleFilter: (IdeaModuleInfo) -> Boolean,
|
||||||
reuseDataFromCache: KotlinResolveCache? = null,
|
reuseDataFromCache: KotlinResolveCache? = null,
|
||||||
syntheticFiles: Collection<JetFile> = listOf(),
|
syntheticFiles: Collection<JetFile> = listOf()
|
||||||
moduleFilter: (IdeaModuleInfo) -> Boolean = { true }
|
|
||||||
): () -> CachedValueProvider.Result<ModuleResolverProvider> = {
|
): () -> CachedValueProvider.Result<ModuleResolverProvider> = {
|
||||||
val analyzerFacade = AnalyzerFacadeProvider.getAnalyzerFacade(platform)
|
val analyzerFacade = AnalyzerFacadeProvider.getAnalyzerFacade(platform)
|
||||||
val delegateResolverProvider = reuseDataFromCache?.moduleResolverProvider ?: EmptyModuleResolverProvider
|
val delegateResolverProvider = reuseDataFromCache?.moduleResolverProvider ?: EmptyModuleResolverProvider
|
||||||
@@ -94,20 +94,43 @@ public class KotlinCacheService(val project: Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getGlobalCache(platform: TargetPlatform) = globalCachesPerPlatform[platform]!!.modulesCache
|
private fun getGlobalCache(platform: TargetPlatform) = globalCachesPerPlatform[platform]!!.modulesCache
|
||||||
|
private fun getGlobalLibrariesCache(platform: TargetPlatform) = globalCachesPerPlatform[platform]!!.librariesCache
|
||||||
|
|
||||||
private val syntheticFileCaches = object : SLRUCache<JetFile, KotlinResolveCache>(2, 3) {
|
private val syntheticFileCaches = object : SLRUCache<JetFile, KotlinResolveCache>(2, 3) {
|
||||||
override fun createValue(file: JetFile?): KotlinResolveCache {
|
override fun createValue(file: JetFile?): KotlinResolveCache {
|
||||||
val targetPlatform = TargetPlatformDetector.getPlatform(file!!)
|
val targetPlatform = TargetPlatformDetector.getPlatform(file!!)
|
||||||
return KotlinResolveCache(
|
val syntheticFileModule = file.getModuleInfo()
|
||||||
project,
|
return when {
|
||||||
globalResolveSessionProvider(
|
syntheticFileModule is ModuleSourceInfo -> {
|
||||||
targetPlatform,
|
val dependentModules = syntheticFileModule.getDependentModules()
|
||||||
syntheticFiles = listOf(file),
|
KotlinResolveCache(
|
||||||
reuseDataFromCache = globalCachesPerPlatform[targetPlatform]!!.librariesCache,
|
project,
|
||||||
moduleFilter = { !it.isLibraryClasses() },
|
globalResolveSessionProvider(
|
||||||
dependencies = listOf(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
|
targetPlatform,
|
||||||
|
syntheticFiles = listOf(file),
|
||||||
|
reuseDataFromCache = getGlobalCache(targetPlatform),
|
||||||
|
moduleFilter = { it in dependentModules },
|
||||||
|
dependencies = listOf(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
else -> {
|
||||||
|
if (syntheticFileModule.isLibraryClasses()) {
|
||||||
|
LOG.error("Creating cache with synthetic file ($file) in classes of library $syntheticFileModule")
|
||||||
|
}
|
||||||
|
KotlinResolveCache(
|
||||||
|
project,
|
||||||
|
globalResolveSessionProvider(
|
||||||
|
targetPlatform,
|
||||||
|
syntheticFiles = listOf(file),
|
||||||
|
reuseDataFromCache = getGlobalLibrariesCache(targetPlatform),
|
||||||
|
moduleFilter = { it == syntheticFileModule },
|
||||||
|
dependencies = listOf(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -48,7 +48,8 @@ fun createModuleResolverProvider(
|
|||||||
val globalContext = (delegateProvider as? ModuleResolverProviderImpl)?.globalContext ?: GlobalContext()
|
val globalContext = (delegateProvider as? ModuleResolverProviderImpl)?.globalContext ?: GlobalContext()
|
||||||
|
|
||||||
val syntheticFilesByModule = syntheticFiles.groupBy { it.getModuleInfo() }
|
val syntheticFilesByModule = syntheticFiles.groupBy { it.getModuleInfo() }
|
||||||
allModuleInfos.addAll(syntheticFilesByModule.keySet())
|
val syntheticFilesModules = syntheticFilesByModule.keySet()
|
||||||
|
allModuleInfos.addAll(syntheticFilesModules)
|
||||||
|
|
||||||
val modulesToCreateResolversFor = allModuleInfos.filter(moduleFilter)
|
val modulesToCreateResolversFor = allModuleInfos.filter(moduleFilter)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user