Scripts: drop sdk caches on project root change event
Otherwise old invalid roots may be saved
This commit is contained in:
+19
-14
@@ -1,26 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.core.script
|
||||
|
||||
import com.intellij.ProjectTopics
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.ModuleRootEvent
|
||||
import com.intellij.openapi.roots.ModuleRootListener
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
@@ -48,6 +40,15 @@ class ScriptsCompilationConfigurationCache(private val project: Project) {
|
||||
const val MAX_SCRIPTS_CACHED = 50
|
||||
}
|
||||
|
||||
init {
|
||||
val connection = project.messageBus.connect()
|
||||
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
|
||||
override fun rootsChanged(event: ModuleRootEvent) {
|
||||
clearCaches()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private val cacheLock = ReentrantReadWriteLock()
|
||||
|
||||
private val scriptDependenciesCache = SLRUCacheWithLock<ScriptCompilationConfigurationResult>()
|
||||
@@ -126,6 +127,11 @@ class ScriptsCompilationConfigurationCache(private val project: Project) {
|
||||
}
|
||||
|
||||
private fun onChange(files: List<VirtualFile>) {
|
||||
clearCaches()
|
||||
updateHighlighting(files)
|
||||
}
|
||||
|
||||
private fun clearCaches() {
|
||||
this::allSdks.clearValue()
|
||||
this::allNonIndexedSdks.clearValue()
|
||||
|
||||
@@ -143,7 +149,6 @@ class ScriptsCompilationConfigurationCache(private val project: Project) {
|
||||
.single()
|
||||
|
||||
kotlinScriptDependenciesClassFinder.clearCache()
|
||||
updateHighlighting(files)
|
||||
}
|
||||
|
||||
private fun updateHighlighting(files: List<VirtualFile>) {
|
||||
|
||||
Reference in New Issue
Block a user