Skip to content

Commit b2db9e3

Browse files
committed
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
1 parent 7954ba8 commit b2db9e3

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/main/kotlin/creator/custom/CustomPlatformStep.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.intellij.ide.wizard.NewProjectWizardBaseData
3333
import com.intellij.ide.wizard.NewProjectWizardStep
3434
import com.intellij.openapi.application.EDT
3535
import com.intellij.openapi.application.asContextElement
36+
import com.intellij.openapi.application.runWriteAction
3637
import com.intellij.openapi.diagnostic.logger
3738
import com.intellij.openapi.observable.properties.GraphProperty
3839
import com.intellij.openapi.observable.util.transform
@@ -54,7 +55,6 @@ import kotlinx.coroutines.Dispatchers
5455
import kotlinx.coroutines.Job
5556
import kotlinx.coroutines.cancel
5657
import kotlinx.coroutines.launch
57-
import kotlinx.coroutines.withContext
5858

5959
/**
6060
* The step to select a custom template repo.
@@ -219,13 +219,15 @@ class CustomPlatformStep(
219219
templateProvidersTextProperty.set(MCDevBundle("creator.step.generic.init_template_providers.message"))
220220
templateProvidersLoadingProperty.set(true)
221221

222+
// For some reason syncRefresh doesn't play nice with writeAction() coroutines so we do it beforehand
223+
application.invokeAndWait(
224+
{ runWriteAction { VirtualFileManager.getInstance().syncRefresh() } },
225+
context.modalityState
226+
)
227+
222228
val dialogCoroutineContext = context.modalityState.asContextElement()
223229
val uiContext = dialogCoroutineContext + Dispatchers.EDT
224-
creatorUiScope.launch(dialogCoroutineContext) {
225-
withContext(uiContext) {
226-
application.runWriteAction { VirtualFileManager.getInstance().syncRefresh() }
227-
}
228-
230+
creatorUiScope.launch(uiContext) {
229231
for ((providerKey, repos) in templateRepos.groupBy { it.provider }) {
230232
val provider = TemplateProvider.get(providerKey)
231233
?: continue
@@ -234,11 +236,9 @@ class CustomPlatformStep(
234236
.getOrLogException(logger<CustomPlatformStep>())
235237
}
236238

237-
withContext(uiContext) {
238-
templateProvidersLoadingProperty.set(false)
239-
// Force refresh to trigger template loading
240-
templateRepoProperty.set(templateRepo)
241-
}
239+
templateProvidersLoadingProperty.set(false)
240+
// Force refresh to trigger template loading
241+
templateRepoProperty.set(templateRepo)
242242
}
243243
}
244244

@@ -248,23 +248,23 @@ class CustomPlatformStep(
248248
templateLoadingTextProperty.set(MCDevBundle("creator.step.generic.load_template.message"))
249249
templateLoadingProperty.set(true)
250250

251+
// For some reason syncRefresh doesn't play nice with writeAction() coroutines so we do it beforehand
252+
application.invokeAndWait(
253+
{ runWriteAction { VirtualFileManager.getInstance().syncRefresh() } },
254+
context.modalityState
255+
)
256+
251257
val dialogCoroutineContext = context.modalityState.asContextElement()
252258
val uiContext = dialogCoroutineContext + Dispatchers.EDT
253259
templateLoadingJob?.cancel("Another template has been selected")
254-
templateLoadingJob = creatorUiScope.launch(dialogCoroutineContext) {
255-
withContext(uiContext) {
256-
application.runWriteAction { VirtualFileManager.getInstance().syncRefresh() }
257-
}
258-
260+
templateLoadingJob = creatorUiScope.launch(uiContext) {
259261
val newTemplates = runCatching { provider() }
260262
.getOrLogException(logger<CustomPlatformStep>())
261263
?: emptyList()
262264

263-
withContext(uiContext) {
264-
templateLoadingProperty.set(false)
265-
noTemplatesAvailable.visible(newTemplates.isEmpty())
266-
availableTemplates = newTemplates
267-
}
265+
templateLoadingProperty.set(false)
266+
noTemplatesAvailable.visible(newTemplates.isEmpty())
267+
availableTemplates = newTemplates
268268
}
269269
}
270270

src/main/kotlin/creator/custom/providers/RemoteTemplateProvider.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import com.github.kittinunf.result.getOrNull
3434
import com.github.kittinunf.result.onError
3535
import com.intellij.ide.util.projectWizard.WizardContext
3636
import com.intellij.openapi.application.PathManager
37+
import com.intellij.openapi.application.writeAction
3738
import com.intellij.openapi.diagnostic.ControlFlowException
3839
import com.intellij.openapi.diagnostic.thisLogger
3940
import com.intellij.openapi.observable.properties.PropertyGraph
@@ -124,7 +125,7 @@ open class RemoteTemplateProvider : TemplateProvider {
124125
return doLoadTemplates(context, repo, remoteRepo.innerPath)
125126
}
126127

127-
protected fun doLoadTemplates(
128+
protected suspend fun doLoadTemplates(
128129
context: WizardContext,
129130
repo: MinecraftSettings.TemplateRepo,
130131
rawInnerPath: String
@@ -140,7 +141,7 @@ open class RemoteTemplateProvider : TemplateProvider {
140141
val rootFile = fs.refreshAndFindFileByPath(archiveRoot)
141142
?: return emptyList()
142143
val modalityState = context.modalityState
143-
rootFile.refreshSync(modalityState)
144+
writeAction { rootFile.refreshSync(modalityState) }
144145

145146
val innerPath = replaceVariables(rawInnerPath)
146147
val repoRoot = if (innerPath.isNotBlank()) {

0 commit comments

Comments
 (0)