[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.KtAllowAnalysisOnEdt
|
||||||
import org.jetbrains.kotlin.analysis.api.analyze
|
import org.jetbrains.kotlin.analysis.api.analyze
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisOnEdt
|
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisOnEdt
|
||||||
|
import org.jetbrains.kotlin.analysis.utils.errors.shouldIjPlatformExceptionBeRethrown
|
||||||
import org.jetbrains.kotlin.analysis.utils.printer.getElementTextInContext
|
import org.jetbrains.kotlin.analysis.utils.printer.getElementTextInContext
|
||||||
|
|
||||||
object KtFirReferenceResolver : ResolveCache.PolyVariantResolver<KtReference> {
|
object KtFirReferenceResolver : ResolveCache.PolyVariantResolver<KtReference> {
|
||||||
@@ -27,7 +28,7 @@ object KtFirReferenceResolver : ResolveCache.PolyVariantResolver<KtReference> {
|
|||||||
val resolveToPsiElements = try {
|
val resolveToPsiElements = try {
|
||||||
analyze(ref.expression) { ref.getResolvedToPsi(this) }
|
analyze(ref.expression) { ref.getResolvedToPsi(this) }
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (e is ControlFlowException || e is IndexNotReadyException) throw e
|
if (shouldIjPlatformExceptionBeRethrown(e)) throw e
|
||||||
|
|
||||||
throw KtReferenceResolveException(ref, 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.progress.ProcessCanceledException
|
||||||
import com.intellij.openapi.project.IndexNotReadyException
|
import com.intellij.openapi.project.IndexNotReadyException
|
||||||
import com.intellij.openapi.diagnostic.ControlFlowException
|
import com.intellij.openapi.diagnostic.ControlFlowException
|
||||||
|
import org.jetbrains.kotlin.analysis.utils.errors.shouldIjPlatformExceptionBeRethrown
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lazily calculated value which runs postCompute in the same thread,
|
* 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) {
|
private fun exceptionShouldBeSavedInCache(exception: Throwable): Boolean =
|
||||||
is IndexNotReadyException -> false
|
!shouldIjPlatformExceptionBeRethrown(exception)
|
||||||
is ControlFlowException -> false
|
|
||||||
else -> true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@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.checkCanceled
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.findSourceNonLocalFirDeclaration
|
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.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.FirElement
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||||
@@ -428,7 +429,7 @@ private fun rethrowWithDetails(
|
|||||||
fromPhase: FirResolvePhase,
|
fromPhase: FirResolvePhase,
|
||||||
toPhase: FirResolvePhase?
|
toPhase: FirResolvePhase?
|
||||||
): Nothing {
|
): Nothing {
|
||||||
if (e is ControlFlowException) throw e
|
if (shouldIjPlatformExceptionBeRethrown(e)) throw e
|
||||||
errorWithAttachment(
|
errorWithAttachment(
|
||||||
buildString {
|
buildString {
|
||||||
val moduleData = firDeclarationToResolve.llFirModuleData
|
val moduleData = firDeclarationToResolve.llFirModuleData
|
||||||
|
|||||||
Reference in New Issue
Block a user