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 {
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<VFileEvent>) {
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<VFileEvent>) {
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<VirtualFile>? = null