Skip to content

Commit

Permalink
Fix #2400 fix #2394
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RedNesto committed Nov 25, 2024
1 parent 7954ba8 commit b2db9e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
42 changes: 21 additions & 21 deletions src/main/kotlin/creator/custom/CustomPlatformStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.intellij.ide.wizard.NewProjectWizardBaseData
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
Expand All @@ -54,7 +55,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
* The step to select a custom template repo.
Expand Down Expand Up @@ -219,13 +219,15 @@ class CustomPlatformStep(
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
Expand All @@ -234,11 +236,9 @@ class CustomPlatformStep(
.getOrLogException(logger<CustomPlatformStep>())
}

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)
}
}

Expand All @@ -248,23 +248,23 @@ class CustomPlatformStep(
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<CustomPlatformStep>())
?: emptyList()

withContext(uiContext) {
templateLoadingProperty.set(false)
noTemplatesAvailable.visible(newTemplates.isEmpty())
availableTemplates = newTemplates
}
templateLoadingProperty.set(false)
noTemplatesAvailable.visible(newTemplates.isEmpty())
availableTemplates = newTemplates
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.github.kittinunf.result.getOrNull
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
Expand Down Expand Up @@ -124,7 +125,7 @@ open class RemoteTemplateProvider : TemplateProvider {
return doLoadTemplates(context, repo, remoteRepo.innerPath)
}

protected fun doLoadTemplates(
protected suspend fun doLoadTemplates(
context: WizardContext,
repo: MinecraftSettings.TemplateRepo,
rawInnerPath: String
Expand All @@ -140,7 +141,7 @@ open class RemoteTemplateProvider : TemplateProvider {
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()) {
Expand Down

0 comments on commit b2db9e3

Please sign in to comment.