From 81b519286fefd1e1e8421ee5c6e32a23b3217551 Mon Sep 17 00:00:00 2001 From: Sergey Rostov Date: Thu, 30 Aug 2018 09:44:36 +0300 Subject: [PATCH] ScriptDependenciesLoader: Fix freeze on notifyRootsChanged In 4f3f4dd, launch(EDT(project)) was replaced with TransactionGuard.submitTransaction to fix write in write-unsafe context. Unfortunately submitTransaction will call action immediately if we are already on EDT. This causes IDE freeze. By replacing submitTransaction with submitTransactionLater we are postponing work to the end of events queue (as it was before 4f3f4dd). Also in isUnitTestMode we need to call action immediately as it was before 4f3f4dd. #KT-25958 Fixed --- .../script/dependencies/ScriptDependenciesLoader.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/ScriptDependenciesLoader.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/ScriptDependenciesLoader.kt index 545affa5aaa..2078c8d9163 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/ScriptDependenciesLoader.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/ScriptDependenciesLoader.kt @@ -109,13 +109,19 @@ abstract class ScriptDependenciesLoader( protected fun notifyRootsChanged() { if (!shouldNotifyRootsChanged) return - TransactionGuard.submitTransaction(project, Runnable { + val doNotifyRootsChanged = Runnable { runWriteAction { if (project.isDisposed) return@runWriteAction ProjectRootManagerEx.getInstanceEx(project)?.makeRootsChange(EmptyRunnable.getInstance(), false, true) ScriptDependenciesModificationTracker.getInstance(project).incModificationCount() } - }) + } + + if (ApplicationManager.getApplication().isUnitTestMode) { + doNotifyRootsChanged.run() + } else { + TransactionGuard.getInstance().submitTransactionLater(project, doNotifyRootsChanged) + } } }