[Analysis API FIR] rethrow IndexNotReadyException
This commit is contained in:
+2
-1
@@ -14,6 +14,7 @@ import com.intellij.psi.impl.source.resolve.ResolveCache
|
||||
import org.jetbrains.kotlin.analysis.api.KtAllowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.shouldIjPlatformExceptionBeRethrown
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.getElementTextInContext
|
||||
|
||||
object KtFirReferenceResolver : ResolveCache.PolyVariantResolver<KtReference> {
|
||||
@@ -27,7 +28,7 @@ object KtFirReferenceResolver : ResolveCache.PolyVariantResolver<KtReference> {
|
||||
val resolveToPsiElements = try {
|
||||
analyze(ref.expression) { ref.getResolvedToPsi(this) }
|
||||
} catch (e: Throwable) {
|
||||
if (e is ControlFlowException || e is IndexNotReadyException) throw e
|
||||
if (shouldIjPlatformExceptionBeRethrown(e)) throw e
|
||||
|
||||
throw KtReferenceResolveException(ref, e)
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.utils.errors
|
||||
|
||||
import com.intellij.openapi.diagnostic.ControlFlowException
|
||||
import com.intellij.openapi.project.IndexNotReadyException
|
||||
|
||||
public fun shouldIjPlatformExceptionBeRethrown(exception: Throwable): Boolean = when (exception) {
|
||||
is ControlFlowException -> true
|
||||
is IndexNotReadyException -> true
|
||||
else -> false
|
||||
}
|
||||
+3
-5
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.fir.caches
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.project.IndexNotReadyException
|
||||
import com.intellij.openapi.diagnostic.ControlFlowException
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.shouldIjPlatformExceptionBeRethrown
|
||||
|
||||
/**
|
||||
* Lazily calculated value which runs postCompute in the same thread,
|
||||
@@ -101,11 +102,8 @@ internal class ValueWithPostCompute<KEY, VALUE, DATA>(
|
||||
}
|
||||
}
|
||||
|
||||
private fun exceptionShouldBeSavedInCache(e: Throwable): Boolean = when (e) {
|
||||
is IndexNotReadyException -> false
|
||||
is ControlFlowException -> false
|
||||
else -> true
|
||||
}
|
||||
private fun exceptionShouldBeSavedInCache(exception: Throwable): Boolean =
|
||||
!shouldIjPlatformExceptionBeRethrown(exception)
|
||||
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LazyTransfor
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkCanceled
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.findSourceNonLocalFirDeclaration
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.withFirAttachment
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.shouldIjPlatformExceptionBeRethrown
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||
@@ -428,7 +429,7 @@ private fun rethrowWithDetails(
|
||||
fromPhase: FirResolvePhase,
|
||||
toPhase: FirResolvePhase?
|
||||
): Nothing {
|
||||
if (e is ControlFlowException) throw e
|
||||
if (shouldIjPlatformExceptionBeRethrown(e)) throw e
|
||||
errorWithAttachment(
|
||||
buildString {
|
||||
val moduleData = firDeclarationToResolve.llFirModuleData
|
||||
|
||||
Reference in New Issue
Block a user