From 1911cbb0776b7929f417171369895a04a78d1677 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Mon, 20 Jan 2020 15:01:40 +0100 Subject: [PATCH] Fixed ProgressIndicatorUtils.kt for 201 #KT-36008 Fixed Relates to #KT-33939 --- .../idea/util/ProgressIndicatorUtils.kt | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/util/ProgressIndicatorUtils.kt b/idea/src/org/jetbrains/kotlin/idea/util/ProgressIndicatorUtils.kt index 7140fba5442..562cf4f24f6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/ProgressIndicatorUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/ProgressIndicatorUtils.kt @@ -5,10 +5,46 @@ package org.jetbrains.kotlin.idea.util +import com.intellij.openapi.progress.ProcessCanceledException +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.progress.ProgressManager +import com.intellij.util.ExceptionUtil +import java.util.concurrent.CancellationException import java.util.concurrent.Future +import java.util.concurrent.TimeUnit +import java.util.concurrent.TimeoutException +/** + * Copied from [com.intellij.openapi.progress.util.ProgressIndicatorUtils] + */ object ProgressIndicatorUtils { @JvmStatic - fun awaitWithCheckCanceled(future: Future) = - com.intellij.openapi.progress.util.ProgressIndicatorUtils.awaitWithCheckCanceled(future) + fun awaitWithCheckCanceled(future: Future) { + val indicator = + ProgressManager.getInstance().progressIndicator + while (true) { + checkCancelledEvenWithPCEDisabled(indicator) + try { + future[10, TimeUnit.MILLISECONDS] + return + } catch (ignore: TimeoutException) { + } catch (e: Throwable) { + val cause = e.cause + if (cause is CancellationException) { + throw ProcessCanceledException(cause) + } else { + ExceptionUtil.rethrowUnchecked(e) + throw RuntimeException(e) + } + } + } + } + + private fun checkCancelledEvenWithPCEDisabled(indicator: ProgressIndicator?) = + indicator?.let { + if (it.isCanceled) { + it.checkCanceled() // maybe it'll throw with some useful additional information + throw ProcessCanceledException() + } + } } \ No newline at end of file