Fix: K/N interop libs are not read by IDEA in certain cases
Issue #KT-27579 Fixed
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.caches
|
||||
|
||||
import com.intellij.ProjectTopics
|
||||
import com.intellij.openapi.components.AbstractProjectComponent
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ModuleRootEvent
|
||||
import com.intellij.openapi.roots.ModuleRootListener
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
|
||||
// This is a workaround until IDEA-200525 is fixed.
|
||||
class ProjectRootModificationTrackerFixer(project: Project) : AbstractProjectComponent(project) {
|
||||
|
||||
override fun initComponent() {
|
||||
myProject.messageBus.connect(myProject).subscribe(
|
||||
ProjectTopics.PROJECT_ROOTS,
|
||||
object : ModuleRootListener {
|
||||
override fun rootsChanged(event: ModuleRootEvent) {
|
||||
// Forcefully increment modification counter. This would cause invalidation of
|
||||
// all caches that depend on ProjectRootModificationTracker tracker.
|
||||
ProjectRootManager.getInstance(myProject).incModificationCount()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
+19
-13
@@ -26,12 +26,12 @@ import org.jetbrains.kotlin.idea.caches.project.getModuleInfosFromIdeaModel
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.library.*
|
||||
import org.jetbrains.kotlin.resolve.ImplicitIntegerCoercion
|
||||
import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
|
||||
import org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform
|
||||
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.konan.util.KonanFactories
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
|
||||
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration
|
||||
import org.jetbrains.kotlin.resolve.ImplicitIntegerCoercion
|
||||
import org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform
|
||||
|
||||
class NativePlatformKindResolution : IdePlatformKindResolution {
|
||||
|
||||
@@ -39,19 +39,25 @@ class NativePlatformKindResolution : IdePlatformKindResolution {
|
||||
return library.getFiles(OrderRootType.CLASSES)
|
||||
.mapNotNull { file -> PathUtil.getLocalPath(file) }
|
||||
.map { path -> File(path) }
|
||||
.filter { file -> file.exists }
|
||||
.map { file -> NativeLibraryInfo(project, library, file) }
|
||||
}
|
||||
|
||||
override fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean {
|
||||
return if (virtualFile.isDirectory) {
|
||||
val dir = virtualFile.findChild("linkdata") ?: return false
|
||||
// False means we hit .knm file
|
||||
!VfsUtil.processFilesRecursively(dir) {
|
||||
it.extension != KLIB_METADATA_FILE_EXTENSION
|
||||
return when {
|
||||
// The virtual file for a library packed in a ZIP file will have path like "/some/path/to/the/file.klib!/",
|
||||
// and therefore will be recognized by VFS as a directory (isDirectory == true).
|
||||
// So, first, let's check the extension.
|
||||
virtualFile.extension == KLIB_FILE_EXTENSION -> true
|
||||
|
||||
virtualFile.isDirectory -> {
|
||||
val linkdataDir = virtualFile.findChild("linkdata") ?: return false
|
||||
// False means we hit .knm file
|
||||
!VfsUtil.processFilesRecursively(linkdataDir) {
|
||||
it.extension != KLIB_METADATA_FILE_EXTENSION
|
||||
}
|
||||
}
|
||||
} else {
|
||||
virtualFile.extension == KLIB_FILE_EXTENSION
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<application-components>
|
||||
|
||||
@@ -67,6 +67,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<application-components>
|
||||
|
||||
@@ -68,6 +68,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<application-components>
|
||||
|
||||
@@ -69,6 +69,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<application-components>
|
||||
|
||||
@@ -67,6 +67,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<application-components>
|
||||
|
||||
@@ -67,6 +67,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<application-components>
|
||||
|
||||
@@ -68,6 +68,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent</implementation-class>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<application-components>
|
||||
|
||||
Reference in New Issue
Block a user