User: rednesto Date: 25 Nov 24 15:58 Revision: b2db9e38bd1653518938cbc96064b6a899503208 Summary: Fix #2400 fix #2394 In 2024.3 we hit a WA assertion error for some reason when using syncRefresh in a coroutine, so move the calls out of them for the time being TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9780&personal=false Index: src/main/kotlin/creator/custom/CustomPlatformStep.kt =================================================================== --- src/main/kotlin/creator/custom/CustomPlatformStep.kt (revision 7954ba84d905cc0ae052e322bcd4d5680d4bb53c) +++ src/main/kotlin/creator/custom/CustomPlatformStep.kt (revision b2db9e38bd1653518938cbc96064b6a899503208) @@ -33,6 +33,7 @@ import com.intellij.ide.wizard.NewProjectWizardStep import com.intellij.openapi.application.EDT import com.intellij.openapi.application.asContextElement +import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.observable.properties.GraphProperty import com.intellij.openapi.observable.util.transform @@ -54,7 +55,6 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.cancel import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext /** * The step to select a custom template repo. @@ -219,13 +219,15 @@ templateProvidersTextProperty.set(MCDevBundle("creator.step.generic.init_template_providers.message")) templateProvidersLoadingProperty.set(true) + // For some reason syncRefresh doesn't play nice with writeAction() coroutines so we do it beforehand + application.invokeAndWait( + { runWriteAction { VirtualFileManager.getInstance().syncRefresh() } }, + context.modalityState + ) + val dialogCoroutineContext = context.modalityState.asContextElement() val uiContext = dialogCoroutineContext + Dispatchers.EDT - creatorUiScope.launch(dialogCoroutineContext) { - withContext(uiContext) { - application.runWriteAction { VirtualFileManager.getInstance().syncRefresh() } - } - + creatorUiScope.launch(uiContext) { for ((providerKey, repos) in templateRepos.groupBy { it.provider }) { val provider = TemplateProvider.get(providerKey) ?: continue @@ -234,13 +236,11 @@ .getOrLogException(logger()) } - withContext(uiContext) { - templateProvidersLoadingProperty.set(false) - // Force refresh to trigger template loading - templateRepoProperty.set(templateRepo) - } - } + templateProvidersLoadingProperty.set(false) + // Force refresh to trigger template loading + templateRepoProperty.set(templateRepo) + } + } - } private fun loadTemplatesInBackground(provider: suspend () -> Collection) { selectedTemplate = EmptyLoadedTemplate @@ -248,25 +248,25 @@ templateLoadingTextProperty.set(MCDevBundle("creator.step.generic.load_template.message")) templateLoadingProperty.set(true) + // For some reason syncRefresh doesn't play nice with writeAction() coroutines so we do it beforehand + application.invokeAndWait( + { runWriteAction { VirtualFileManager.getInstance().syncRefresh() } }, + context.modalityState + ) + val dialogCoroutineContext = context.modalityState.asContextElement() val uiContext = dialogCoroutineContext + Dispatchers.EDT templateLoadingJob?.cancel("Another template has been selected") - templateLoadingJob = creatorUiScope.launch(dialogCoroutineContext) { - withContext(uiContext) { - application.runWriteAction { VirtualFileManager.getInstance().syncRefresh() } - } - + templateLoadingJob = creatorUiScope.launch(uiContext) { val newTemplates = runCatching { provider() } .getOrLogException(logger()) ?: emptyList() - withContext(uiContext) { - templateLoadingProperty.set(false) - noTemplatesAvailable.visible(newTemplates.isEmpty()) - availableTemplates = newTemplates - } - } + templateLoadingProperty.set(false) + noTemplatesAvailable.visible(newTemplates.isEmpty()) + availableTemplates = newTemplates + } + } - } override fun setupProject(project: Project) { templateProcessor.generateFiles(project, selectedTemplate) Index: src/main/kotlin/creator/custom/providers/RemoteTemplateProvider.kt =================================================================== --- src/main/kotlin/creator/custom/providers/RemoteTemplateProvider.kt (revision 7954ba84d905cc0ae052e322bcd4d5680d4bb53c) +++ src/main/kotlin/creator/custom/providers/RemoteTemplateProvider.kt (revision b2db9e38bd1653518938cbc96064b6a899503208) @@ -34,6 +34,7 @@ import com.github.kittinunf.result.onError import com.intellij.ide.util.projectWizard.WizardContext import com.intellij.openapi.application.PathManager +import com.intellij.openapi.application.writeAction import com.intellij.openapi.diagnostic.ControlFlowException import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.observable.properties.PropertyGraph @@ -124,7 +125,7 @@ return doLoadTemplates(context, repo, remoteRepo.innerPath) } - protected fun doLoadTemplates( + protected suspend fun doLoadTemplates( context: WizardContext, repo: MinecraftSettings.TemplateRepo, rawInnerPath: String @@ -140,7 +141,7 @@ val rootFile = fs.refreshAndFindFileByPath(archiveRoot) ?: return emptyList() val modalityState = context.modalityState - rootFile.refreshSync(modalityState) + writeAction { rootFile.refreshSync(modalityState) } val innerPath = replaceVariables(rawInnerPath) val repoRoot = if (innerPath.isNotBlank()) {