diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/ProjectRootModificationTrackerFixer.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/ProjectRootModificationTrackerFixer.kt new file mode 100644 index 00000000000..ace5cd5d230 --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/ProjectRootModificationTrackerFixer.kt @@ -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() + } + } + ) + } +} diff --git a/idea/idea-native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt b/idea/idea-native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt index f21f0cf6f9a..a1ca272872d 100644 --- a/idea/idea-native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt +++ b/idea/idea-native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt @@ -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 } } diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index cf0ed5e4e1c..c264fcd947c 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -69,6 +69,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent + + org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer + diff --git a/idea/src/META-INF/plugin.xml.173 b/idea/src/META-INF/plugin.xml.173 index 078ef1815bb..0ff13128267 100644 --- a/idea/src/META-INF/plugin.xml.173 +++ b/idea/src/META-INF/plugin.xml.173 @@ -67,6 +67,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent + + org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer + diff --git a/idea/src/META-INF/plugin.xml.181 b/idea/src/META-INF/plugin.xml.181 index 85f8793388c..33ea02437ed 100644 --- a/idea/src/META-INF/plugin.xml.181 +++ b/idea/src/META-INF/plugin.xml.181 @@ -68,6 +68,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent + + org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer + diff --git a/idea/src/META-INF/plugin.xml.183 b/idea/src/META-INF/plugin.xml.183 index d8e751959a3..4adb6e3fad2 100644 --- a/idea/src/META-INF/plugin.xml.183 +++ b/idea/src/META-INF/plugin.xml.183 @@ -69,6 +69,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent + + org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer + diff --git a/idea/src/META-INF/plugin.xml.as31 b/idea/src/META-INF/plugin.xml.as31 index de2702abf70..5e756a1612d 100644 --- a/idea/src/META-INF/plugin.xml.as31 +++ b/idea/src/META-INF/plugin.xml.as31 @@ -67,6 +67,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent + + org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer + diff --git a/idea/src/META-INF/plugin.xml.as32 b/idea/src/META-INF/plugin.xml.as32 index a3d2b6f1aa9..d6a737ba889 100644 --- a/idea/src/META-INF/plugin.xml.as32 +++ b/idea/src/META-INF/plugin.xml.as32 @@ -67,6 +67,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent + + org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer + diff --git a/idea/src/META-INF/plugin.xml.as33 b/idea/src/META-INF/plugin.xml.as33 index 3a1ab3cdfae..9b519c58a72 100644 --- a/idea/src/META-INF/plugin.xml.as33 +++ b/idea/src/META-INF/plugin.xml.as33 @@ -68,6 +68,9 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent + + org.jetbrains.kotlin.idea.caches.ProjectRootModificationTrackerFixer +