diff --git a/java/java-tests/testSrc/com/intellij/roots/AutomaticModuleUnloaderTest.kt b/java/java-tests/testSrc/com/intellij/roots/AutomaticModuleUnloaderTest.kt index 46d56343d34b..ba03a0b2b43d 100644 --- a/java/java-tests/testSrc/com/intellij/roots/AutomaticModuleUnloaderTest.kt +++ b/java/java-tests/testSrc/com/intellij/roots/AutomaticModuleUnloaderTest.kt @@ -88,6 +88,23 @@ class AutomaticModuleUnloaderTest : ModuleTestCase() { doTest("b", listOf("c"), {}, "b", "c") } + fun `test deleted iml file`() = runBlocking { + createModule("a") + createModule("b") + val deletedIml = createModule("deleted") + val moduleManager = ModuleManager.getInstance(project) + moduleManager.setUnloadedModules(listOf("a")) + createModule("c") + + val moduleFiles = createNewModuleFiles(listOf("d")) {} + reloadProjectWithNewModules(moduleFiles) { + File(deletedIml.moduleFilePath).delete() + } + + ModuleTestCase.assertSameElements(moduleManager.unloadedModuleDescriptions.map { it.name }, "a", "d") + } + + private suspend fun doTest(initiallyUnloaded: String, newModulesName: List, setup: (Map) -> Unit, @@ -125,13 +142,14 @@ class AutomaticModuleUnloaderTest : ModuleTestCase() { return moduleFiles } - private suspend fun reloadProjectWithNewModules(moduleFiles: List) { + private suspend fun reloadProjectWithNewModules(moduleFiles: List, beforeReload: () -> Unit = {}) { val moduleManager = ModuleManagerImpl.getInstanceImpl(myProject) val modulePaths = LinkedHashSet() moduleManager.modules.forEach { it.stateStore.save() } moduleManager.modules.mapTo(modulePaths) { ModulePath(it.moduleFilePath, null) } moduleManager.unloadedModuleDescriptions.mapTo(modulePaths) { (it as UnloadedModuleDescriptionImpl).modulePath } moduleFiles.mapTo(modulePaths) { ModulePath(FileUtil.toSystemIndependentName(it.absolutePath), null) } + beforeReload() moduleManager.loadStateFromModulePaths(modulePaths) } diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/AutomaticModuleUnloader.kt b/platform/lang-impl/src/com/intellij/openapi/module/impl/AutomaticModuleUnloader.kt index 794d896db14b..dd23db60ce0c 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/AutomaticModuleUnloader.kt +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/AutomaticModuleUnloader.kt @@ -42,7 +42,7 @@ class AutomaticModuleUnloader(private val project: Project) : PersistentStateCom val newLoadedNames = oldLoadedWithDependencies.mapTo(LinkedHashSet()) { it.name } val toLoad = modulesToLoad.filter { it.moduleName in newLoadedNames && it.moduleName !in oldLoaded} - val toUnload = modulesToLoad.filter { it.moduleName !in newLoadedNames } + val toUnload = modulesToLoad.filter { it.moduleName !in newLoadedNames && it.moduleName in moduleDescriptions} loadedModulesListStorage.modules.clear() modulesToLoad.filter { it.moduleName in newLoadedNames }.mapTo(loadedModulesListStorage.modules) { it.moduleName } val change = UnloadedModulesListChange(toLoad, toUnload, toUnload.map { moduleDescriptions[it.moduleName]!! })