From 92093a94f43b02130a35c856c42aad753a06c331 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Fri, 8 Jul 2022 10:26:24 +0300 Subject: [PATCH] drop bundled groovy cache between vfs switching GitOrigin-RevId: ec7aeda6f96acb228d2ade788eae0bf0a06e977e --- plugins/groovy/src/META-INF/plugin.xml | 2 ++ .../groovy/bundled/BundledGroovyClassFinder.kt | 2 +- .../plugins/groovy/bundled/bundledGroovy.kt | 13 +++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 7bc2db2a438d..bf68ad239e3b 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -1324,6 +1324,8 @@ + + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/bundled/BundledGroovyClassFinder.kt b/plugins/groovy/src/org/jetbrains/plugins/groovy/bundled/BundledGroovyClassFinder.kt index c6eee257ee58..9dbbde4efdd4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/bundled/BundledGroovyClassFinder.kt +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/bundled/BundledGroovyClassFinder.kt @@ -9,7 +9,7 @@ import org.jetbrains.plugins.groovy.GroovyFileType class BundledGroovyClassFinder(project: Project) : NonClasspathClassFinder(project, GroovyFileType.DEFAULT_EXTENSION) { override fun calcClassRoots(): List { - val root = bundledGroovyJarRoot ?: return emptyList() + val root = bundledGroovyJarRoot.value.get() ?: return emptyList() return listOf(root) } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/bundled/bundledGroovy.kt b/plugins/groovy/src/org/jetbrains/plugins/groovy/bundled/bundledGroovy.kt index ef7ad690ed5e..7b2438092854 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/bundled/bundledGroovy.kt +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/bundled/bundledGroovy.kt @@ -5,11 +5,14 @@ package org.jetbrains.plugins.groovy.bundled import com.intellij.openapi.application.PathManager import com.intellij.openapi.project.Project +import com.intellij.openapi.util.ClearableLazyValue import com.intellij.openapi.util.NlsSafe +import com.intellij.openapi.util.Ref import com.intellij.openapi.util.io.JarUtil.getJarAttribute import com.intellij.openapi.vfs.JarFileSystem import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VirtualFile +import com.intellij.openapi.vfs.newvfs.persistent.PersistentFsConnectionListener import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.GlobalSearchScopesCore import groovy.lang.GroovyObject @@ -28,7 +31,7 @@ private fun doGetBundledGroovyFile(): File { return File(jarPath) } -val bundledGroovyJarRoot: VirtualFile? by lazy(::doGetBundledGroovyRoot) +val bundledGroovyJarRoot: ClearableLazyValue> = ClearableLazyValue.create { Ref.create(doGetBundledGroovyRoot()) } private fun doGetBundledGroovyRoot(): VirtualFile? { val jar = bundledGroovyFile @@ -37,6 +40,12 @@ private fun doGetBundledGroovyRoot(): VirtualFile? { } fun createBundledGroovyScope(project: Project): GlobalSearchScope? { - val root = bundledGroovyJarRoot ?: return null + val root = bundledGroovyJarRoot.value.get() ?: return null return GlobalSearchScopesCore.directoryScope(project, root, true) } + +internal class BundledGroovyPersistentFsConnectionListener: PersistentFsConnectionListener { + override fun beforeConnectionClosed() { + bundledGroovyJarRoot.drop() + } +}