From 7ededbd5e26fbc24759659ea5d8d74cba22a2a7c Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 16 Jun 2016 18:53:27 +0300 Subject: [PATCH] KotlinScriptConfigurationManager: run caching code in smart mode --- .../KotlinScriptConfigurationManager.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/KotlinScriptConfigurationManager.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/KotlinScriptConfigurationManager.kt index 8501df0ddc3..cb88013482f 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/KotlinScriptConfigurationManager.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/KotlinScriptConfigurationManager.kt @@ -53,22 +53,25 @@ class KotlinScriptConfigurationManager( init { reloadScriptDefinitions() - // TODO: sort out read/write action business and if possible make it lazy (e.g. move to getAllScriptsClasspath) - runReadAction { cacheAllScriptsExtraImports() } - project.messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener.Adapter() { - override fun after(events: List) { - val isChanged = scriptExternalImportsProvider?.updateExternalImportsCache(events.mapNotNull { it.file })?.any() ?: false - if (isChanged) { - // TODO: consider more fine-grained update - cacheLock.write { - allScriptsClasspathCache = null - allLibrarySourcesCache = null + dumbService.runWhenSmart { + // TODO: sort out read/write action business and if possible make it lazy (e.g. move to getAllScriptsClasspath) + runReadAction { cacheAllScriptsExtraImports() } + + project.messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener.Adapter() { + override fun after(events: List) { + val isChanged = scriptExternalImportsProvider?.updateExternalImportsCache(events.mapNotNull { it.file })?.any() ?: false + if (isChanged) { + // TODO: consider more fine-grained update + cacheLock.write { + allScriptsClasspathCache = null + allLibrarySourcesCache = null + } + notifyRootsChanged() } - notifyRootsChanged() } - } - }) + }) + } } private var allScriptsClasspathCache: List? = null