@@ -29,7 +29,9 @@ import java.nio.charset.StandardCharsets
2929import java.nio.file.Paths
3030import javax.swing.*
3131import com.intellij.openapi.components.service
32+ import com.intellij.openapi.module.Module
3233import com.intellij.openapi.module.ModuleManager
34+ import com.intellij.openapi.project.ModuleListener
3335import com.intellij.openapi.roots.ModuleRootManager
3436import com.intellij.openapi.vfs.VirtualFileManager
3537import com.intellij.openapi.vfs.newvfs.BulkFileListener
@@ -39,6 +41,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent
3941import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
4042import com.intellij.ide.ui.LafManagerListener
4143import com.intellij.openapi.vfs.VirtualFile
44+ import com.intellij.util.Function
4245
4346fun showTutorial (project : Project ) {
4447 val tutorialFileName = getTutorialFileName()
@@ -193,6 +196,41 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
193196 }
194197 })
195198
199+ // Handle workspace directories changes
200+ connection.subscribe(
201+ ModuleListener .TOPIC ,
202+ object : ModuleListener {
203+ override fun modulesAdded (project : Project , modules : MutableList <out Module >) {
204+
205+ val allModulePaths = ModuleManager .getInstance(project).modules
206+ .flatMap { module -> ModuleRootManager .getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } }
207+
208+ val topLevelModulePaths = allModulePaths
209+ .filter { modulePath -> allModulePaths.none { it != modulePath && modulePath.startsWith(it) } }
210+
211+ continuePluginService.workspacePaths = topLevelModulePaths.toTypedArray();
212+ }
213+
214+ override fun moduleRemoved (project : Project , module : Module ) {
215+ val removedPaths = ModuleRootManager .getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } ;
216+ continuePluginService.workspacePaths = continuePluginService.workspacePaths?.toList()?.filter { path -> removedPaths.none {removedPath -> path == removedPath }}?.toTypedArray();
217+ }
218+
219+ override fun modulesRenamed (
220+ project : Project ,
221+ modules : MutableList <out Module >,
222+ oldNameProvider : Function <in Module , String >
223+ ) {
224+ val allModulePaths = ModuleManager .getInstance(project).modules
225+ .flatMap { module -> ModuleRootManager .getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } }
226+
227+ val topLevelModulePaths = allModulePaths
228+ .filter { modulePath -> allModulePaths.none { it != modulePath && modulePath.startsWith(it) } }
229+
230+ continuePluginService.workspacePaths = topLevelModulePaths.toTypedArray()
231+ }
232+ }
233+ )
196234
197235 connection.subscribe(FileEditorManagerListener .FILE_EDITOR_MANAGER , object : FileEditorManagerListener {
198236 override fun fileClosed (source : FileEditorManager , file : VirtualFile ) {
0 commit comments