use own readAction utility to avoid EDT assertions

IDEA-333285 new readAction APIs assert non-EDT thread. Action Subsystem is not ready for that. The `update` is called on BGT but `beforeActionPerformedUpdate` and `actionPerformed` are called on EDT. We need to support that until `actionPerformed` is redesigned.

GitOrigin-RevId: bd0a5fd92015b89c494d07bf281213571f4bf50a
This commit is contained in:
Gregory.Shrago
2023-09-26 12:18:07 +00:00
committed by intellij-monorepo-bot
parent 11f2ee0a12
commit d78f6c14b4
2 changed files with 11 additions and 6 deletions
@@ -18,7 +18,6 @@ import com.intellij.openapi.actionSystem.impl.ActionMenu.Companion.ALWAYS_VISIBL
import com.intellij.openapi.actionSystem.impl.ActionMenu.Companion.SUPPRESS_SUBMENU
import com.intellij.openapi.application.Application
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.readActionUndispatched
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.progress.blockingContext
@@ -172,8 +171,7 @@ internal class ActionUpdater @JvmOverloads constructor(
}
}
}
if (isEDT) adjustedCall()
else readActionUndispatched(adjustedCall)
readActionUndispatchedForActionExpand(adjustedCall)
}
}
if (PopupMenuPreloader.isToSkipComputeOnEDT(place)) {
@@ -303,7 +301,7 @@ internal class ActionUpdater @JvmOverloads constructor(
private suspend fun ensureSlowDataKeysPreCached(action: Any, targetOperationName: String) {
if (!preCacheSlowDataKeys) return
getSessionDataDeferred(Pair("precache-slow-data@$targetOperationName", null)) {
readActionUndispatched {
readActionUndispatchedForActionExpand {
precacheSlowDataKeys(action, targetOperationName)
}
}.await()
@@ -612,7 +610,7 @@ internal class ActionUpdater @JvmOverloads constructor(
override fun <T : Any> sharedData(key: Key<T>, supplier: Supplier<out T>): T =
updater.computeSessionDataOrThrow(Pair(key.toString(), key)) {
readActionUndispatched {
readActionUndispatchedForActionExpand {
supplier.get()
}
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher
import com.intellij.openapi.progress.CeProcessCanceledException
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.progress.impl.ProgressManagerImpl
import com.intellij.openapi.progress.prepareThreadContext
import com.intellij.openapi.progress.util.PotemkinOverlayProgress
@@ -889,7 +890,7 @@ suspend fun rearrangeByPromoters(actions: List<AnAction>, dataContext: DataConte
try {
service<ActionUpdaterInterceptor>().rearrangeByPromoters(actions, frozenContext) {
withContext(shortcutUpdateDispatcher) {
readActionUndispatched {
readActionUndispatchedForActionExpand {
rearrangeByPromotersImpl(actions, frozenContext)
}
}
@@ -1075,6 +1076,7 @@ private object AltEdtDispatcher : CoroutineDispatcher() {
}
}
// to avoid platform assertions
@Suppress("NOTHING_TO_INLINE")
internal inline fun <R> runBlockingForActionExpand(context: CoroutineContext = EmptyCoroutineContext,
noinline block: suspend CoroutineScope.() -> R): R = prepareThreadContext { ctx ->
@@ -1086,3 +1088,8 @@ internal inline fun <R> runBlockingForActionExpand(context: CoroutineContext = E
throw CeProcessCanceledException(ce)
}
}
// to avoid platform assertions
internal suspend inline fun <R> readActionUndispatchedForActionExpand(noinline block: () -> R): R =
if (!EDT.isCurrentThreadEdt()) readActionUndispatched(block)
else blockingContext { ReadAction.compute<R, Throwable> { block() } }