diff --git a/build.gradle.kts b/build.gradle.kts index b8d745e..03deea7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { id("idea") id("java") kotlin("kapt") version "1.8.10" - id("org.jetbrains.intellij") version "1.13.3" + id("org.jetbrains.intellij") version "1.15.0" id("org.jetbrains.kotlin.jvm") version "1.8.10" id("org.jetbrains.kotlin.plugin.serialization") version "1.4.32" } @@ -120,9 +120,6 @@ tasks { failureLevel.set( EnumSet.complementOf( EnumSet.of( - // skipping compatibility problems due to potential false positive with EAP v232: - // Method com.squareup.cash.hermit.HermitVFSChangeListener.after(List events) : void references an unresolved class com.intellij.openapi.project.ProjectLocator.Companion. This can lead to **NoSuchClassError** exception at runtime. - RunPluginVerifierTask.FailureLevel.COMPATIBILITY_PROBLEMS, // skipping missing dependencies as com.intellij.java provided by IJ raises a false warning RunPluginVerifierTask.FailureLevel.MISSING_DEPENDENCIES, // skipping experimental API usage, as delaying Gradle execution relies on experimental GradleExecutionAware. diff --git a/src/main/kotlin/com/squareup/cash/hermit/Hermit.kt b/src/main/kotlin/com/squareup/cash/hermit/Hermit.kt index 8ece7ca..a0b1486 100644 --- a/src/main/kotlin/com/squareup/cash/hermit/Hermit.kt +++ b/src/main/kotlin/com/squareup/cash/hermit/Hermit.kt @@ -33,12 +33,12 @@ object Hermit { private val HANDLER_EP_NAME: ExtensionPointName = ExtensionPointName("org.squareup.cash.hermit.idea-plugin.property-handler") - private val projects = ConcurrentHashMap() + private val projects = ConcurrentHashMap() - operator fun invoke(project: Project): State { - val state = project.projectFilePath?.let { projects.getOrPut(it, { State(project) }) } + operator fun invoke(project: Project): HermitState { + val hermitState = project.projectFilePath?.let { projects.getOrPut(it) { HermitState(project) } } // projectFilePath can be null for the default project. Return an empty state for it. - return state ?: State(project) + return hermitState ?: HermitState(project) } fun remove(project: Project) { @@ -46,10 +46,12 @@ object Hermit { project.projectFilePath?.let { projects.remove(it) } } + fun allProjects(): Collection = projects.values + /** * State maintains the Hermit state of a single project */ - class State(private val project: Project) { + class HermitState(val project: Project) { // Is this project a hermit enabled project? private var isHermitProject = false // Has the project been opened in the plugin? diff --git a/src/main/kotlin/com/squareup/cash/hermit/HermitVFSChangeListener.kt b/src/main/kotlin/com/squareup/cash/hermit/HermitVFSChangeListener.kt index a744f3b..cac56b6 100644 --- a/src/main/kotlin/com/squareup/cash/hermit/HermitVFSChangeListener.kt +++ b/src/main/kotlin/com/squareup/cash/hermit/HermitVFSChangeListener.kt @@ -2,7 +2,6 @@ package com.squareup.cash.hermit import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project -import com.intellij.openapi.project.ProjectLocator import com.intellij.openapi.project.guessProjectDir import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.newvfs.BulkFileListener @@ -14,11 +13,17 @@ class HermitVFSChangeListener : BulkFileListener { override fun after(events: MutableList) { val needsUpdating = HashMap() events.forEach { - val file = it.file - if (file != null) { - val project = ProjectLocator.getInstance().guessProjectForFile(file) - if (project != null && file != null && isHermitChange(project, file)) { - needsUpdating[project.name] = project + it.file?.let { file -> + log.debug("Checking if file [${file.path}] is in projects " + + "${Hermit.allProjects().map { state -> state.project.name }}") + Hermit.allProjects().forEach { state -> + val project = state.project + // The project might have been disposed since looking up Hermit.allProjects. + log.debug("Project [${project.name}] is disposed: [${project.isDisposed}]") + if (!project.isDisposed && isHermitChange(project, file)) { + log.debug("Project [${project.name}] needs updating") + needsUpdating[project.name] = project + } } } }