[K/N lib] Implement multiple fixes:
- source code simplifications - more correct work with paths - builtIns module requires dependency on itself
This commit is contained in:
committed by
Mikhail Glukhikh
parent
3c5c21256f
commit
2161451482
@@ -15,7 +15,6 @@ import com.intellij.psi.impl.PsiFileFactoryImpl
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.stubs.PsiFileStub
|
||||
import com.intellij.testFramework.LightVirtualFile
|
||||
import org.jetbrains.kotlin.analyzer.ModuleContent
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
@@ -48,9 +47,6 @@ fun createFileStub(project: Project, text: String): PsiFileStub<*> {
|
||||
|
||||
fun createLoggingErrorReporter(log: Logger) = LoggingErrorReporter(log)
|
||||
|
||||
fun <M : ModuleInfo> destructModuleContent(moduleContent: ModuleContent<M>) =
|
||||
moduleContent.syntheticFiles to moduleContent.moduleContentScope
|
||||
|
||||
fun <M : ModuleInfo> createDeclarationProviderFactory(
|
||||
project: Project,
|
||||
moduleContext: ModuleContext,
|
||||
|
||||
@@ -7,7 +7,6 @@ package org.jetbrains.konan.analyser
|
||||
|
||||
import org.jetbrains.konan.createDeclarationProviderFactory
|
||||
import org.jetbrains.konan.createResolvedModuleDescriptors
|
||||
import org.jetbrains.konan.destructModuleContent
|
||||
import org.jetbrains.kotlin.analyzer.*
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
||||
@@ -41,15 +40,12 @@ class KonanAnalyzerFacade : ResolverForModuleFactory() {
|
||||
targetPlatformVersion: TargetPlatformVersion
|
||||
): ResolverForModule {
|
||||
|
||||
val (syntheticFiles, moduleContentScope) = destructModuleContent(moduleContent)
|
||||
val project = moduleContext.project
|
||||
|
||||
val declarationProviderFactory = createDeclarationProviderFactory(
|
||||
project,
|
||||
moduleContext.project,
|
||||
moduleContext,
|
||||
syntheticFiles,
|
||||
moduleContent.syntheticFiles,
|
||||
moduleContent.moduleInfo,
|
||||
moduleContentScope
|
||||
moduleContent.moduleContentScope
|
||||
)
|
||||
|
||||
val container = createContainerForLazyResolve(
|
||||
|
||||
@@ -8,7 +8,7 @@ package org.jetbrains.konan.analyser
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.util.io.exists
|
||||
import org.jetbrains.konan.KONAN_CURRENT_ABI_VERSION
|
||||
import org.jetbrains.konan.settings.KonanPaths
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
@@ -45,20 +45,19 @@ class KonanPlatformSupport : IdePlatformSupport() {
|
||||
private fun createKonanBuiltIns(sdkContext: GlobalContextImpl): KotlinBuiltIns {
|
||||
|
||||
// TODO: it depends on a random project's stdlib, propagate the actual project here
|
||||
val stdlibLocation = ProjectManager.getInstance().openProjects.asSequence().mapNotNull {
|
||||
val stdlibPath = KonanPaths.getInstance(it).konanStdlib() ?: return@mapNotNull null
|
||||
val stdlibVirtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(stdlibPath.toFile()) ?: return@mapNotNull null
|
||||
stdlibPath to stdlibVirtualFile
|
||||
val stdlibPath = ProjectManager.getInstance().openProjects.asSequence().mapNotNull {
|
||||
KonanPaths.getInstance(it).konanStdlib()?.takeIf { it.exists() }
|
||||
}.firstOrNull()
|
||||
|
||||
if (stdlibLocation != null) {
|
||||
val library = createKonanLibrary(stdlibLocation.first.File(), KONAN_CURRENT_ABI_VERSION)
|
||||
if (stdlibPath != null) {
|
||||
val library = createKonanLibrary(stdlibPath.File(), KONAN_CURRENT_ABI_VERSION)
|
||||
|
||||
val builtInsModule = DefaultDeserializedDescriptorFactory.createDescriptorAndNewBuiltIns(
|
||||
library,
|
||||
LanguageVersionSettingsImpl.DEFAULT,
|
||||
sdkContext.storageManager
|
||||
)
|
||||
builtInsModule.setDependencies(listOf(builtInsModule))
|
||||
|
||||
return builtInsModule.builtIns
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ open class KonanPaths(protected val project: Project) : ProjectComponent {
|
||||
|
||||
open fun konanDist(): Path? {
|
||||
for (provider in KonanModelProvider.EP_NAME.extensions) {
|
||||
return provider.getKonanHome(project)
|
||||
provider.getKonanHome(project)?.let { return it }
|
||||
}
|
||||
return bundledKonanDist()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user