KotlinScriptConfigurationManager: run caching code in smart mode

This commit is contained in:
Pavel V. Talanov
2016-06-16 18:53:27 +03:00
parent 1da3efea81
commit 7ededbd5e2
@@ -53,22 +53,25 @@ class KotlinScriptConfigurationManager(
init { init {
reloadScriptDefinitions() 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() { dumbService.runWhenSmart {
override fun after(events: List<VFileEvent>) { // TODO: sort out read/write action business and if possible make it lazy (e.g. move to getAllScriptsClasspath)
val isChanged = scriptExternalImportsProvider?.updateExternalImportsCache(events.mapNotNull { it.file })?.any() ?: false runReadAction { cacheAllScriptsExtraImports() }
if (isChanged) {
// TODO: consider more fine-grained update project.messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener.Adapter() {
cacheLock.write { override fun after(events: List<VFileEvent>) {
allScriptsClasspathCache = null val isChanged = scriptExternalImportsProvider?.updateExternalImportsCache(events.mapNotNull { it.file })?.any() ?: false
allLibrarySourcesCache = null if (isChanged) {
// TODO: consider more fine-grained update
cacheLock.write {
allScriptsClasspathCache = null
allLibrarySourcesCache = null
}
notifyRootsChanged()
} }
notifyRootsChanged()
} }
} })
}) }
} }
private var allScriptsClasspathCache: List<VirtualFile>? = null private var allScriptsClasspathCache: List<VirtualFile>? = null