[Workspace Model] Register watched roots asynchronously

GitOrigin-RevId: 58f68022c2bcd5fe4e5ef0c76c8e2ba0fe89195a
This commit is contained in:
Alex Plate
2020-05-09 05:25:10 +00:00
committed by intellij-monorepo-bot
parent f56e679445
commit d82cd9980c
@@ -4,6 +4,8 @@ package com.intellij.workspace.legacyBridge.libraries.libraries
import com.google.common.io.Files
import com.intellij.ide.highlighter.ModuleFileType
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.module.impl.getModuleNameByFilePath
@@ -17,6 +19,8 @@ import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent
import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager
import com.intellij.util.ConcurrencyUtil
import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.workspace.api.*
import com.intellij.workspace.bracket
import com.intellij.workspace.ide.WorkspaceModel
@@ -24,6 +28,8 @@ import com.intellij.workspace.ide.WorkspaceModelChangeListener
import com.intellij.workspace.ide.WorkspaceModelTopics
import com.intellij.workspace.ide.getInstance
import org.jetbrains.annotations.ApiStatus
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Future
/**
* Provides rootsChanged events if roots validity was changed.
@@ -44,6 +50,10 @@ class LegacyBridgeRootsWatcher(
private val rootFilePointers = LegacyModelRootsFilePointers(project)
private val myExecutor = if (ApplicationManager.getApplication().isUnitTestMode) ConcurrencyUtil.newSameThreadExecutorService()
else AppExecutorUtil.createBoundedApplicationPoolExecutor("Workspace Model Project Root Manager", 1)
private var myCollectWatchRootsFuture: Future<*> = CompletableFuture.completedFuture(null) // accessed in EDT only
init {
val messageBusConnection = project.messageBus.connect()
WorkspaceModelTopics.getInstance(project).subscribeImmediately(messageBusConnection, object : WorkspaceModelChangeListener {
@@ -76,11 +86,17 @@ class LegacyBridgeRootsWatcher(
s.entities(JavaModuleSettingsEntity::class.java).forEach { javaSettings -> javaSettings.compilerOutputForTests?.let { roots.add(it) } }
rootFilePointers.onModelChange(s)
syncNewRootsToContainer(
newRoots = roots,
newJarDirectories = jarDirectories,
newRecursiveJarDirectories = recursiveJarDirectories
)
myCollectWatchRootsFuture.cancel(false)
myCollectWatchRootsFuture = myExecutor.submit {
ReadAction.run<Throwable> {
syncNewRootsToContainer(
newRoots = roots,
newJarDirectories = jarDirectories,
newRecursiveJarDirectories = recursiveJarDirectories
)
}
}
}
})
messageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener {
@@ -212,6 +228,9 @@ class LegacyBridgeRootsWatcher(
override fun dispose() {
clear()
myCollectWatchRootsFuture.cancel(false)
myExecutor.shutdownNow()
}
companion object {