Try to diagnose NoDescriptorForDeclarationException in completion
This commit is contained in:
@@ -24,5 +24,6 @@ object IdeaEnvironment : TargetEnvironment("Idea") {
|
||||
override fun configure(container: StorageComponentContainer) {
|
||||
container.useImpl<ResolveElementCache>()
|
||||
container.useImpl<IdeaLocalDescriptorResolver>()
|
||||
container.useImpl<IdeaAbsentDescriptorHandler>()
|
||||
}
|
||||
}
|
||||
+18
-3
@@ -17,18 +17,33 @@
|
||||
package org.jetbrains.kotlin.idea.project
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.stubindex.resolve.PluginDeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.LocalDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.lazy.AbsentDescriptorHandler
|
||||
import org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
|
||||
class IdeaLocalDescriptorResolver(
|
||||
private val resolveElementCache: ResolveElementCache
|
||||
): LocalDescriptorResolver {
|
||||
private val resolveElementCache: ResolveElementCache,
|
||||
private val absentDescriptorHandler: AbsentDescriptorHandler
|
||||
) : LocalDescriptorResolver {
|
||||
override fun resolveLocalDeclaration(declaration: KtDeclaration): DeclarationDescriptor {
|
||||
val context = resolveElementCache.resolveToElement(declaration, BodyResolveMode.FULL)
|
||||
return context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
||||
?: throw NoDescriptorForDeclarationException(declaration)
|
||||
?: absentDescriptorHandler.diagnoseDescriptorNotFound(declaration)
|
||||
}
|
||||
}
|
||||
|
||||
class IdeaAbsentDescriptorHandler(
|
||||
private val declarationProviderFactory: DeclarationProviderFactory
|
||||
) : AbsentDescriptorHandler {
|
||||
override fun diagnoseDescriptorNotFound(declaration: KtDeclaration): DeclarationDescriptor {
|
||||
throw NoDescriptorForDeclarationException(
|
||||
declaration,
|
||||
(declarationProviderFactory as? PluginDeclarationProviderFactory)?.debugToString()
|
||||
)
|
||||
}
|
||||
}
|
||||
+20
@@ -58,4 +58,24 @@ class PluginDeclarationProviderFactory(
|
||||
throw IllegalStateException("Cannot find package fragment for file ${file.name} with package ${file.packageFqName}, " +
|
||||
"vFile ${file.virtualFile}, nonIndexed ${file in nonIndexedFiles}")
|
||||
}
|
||||
|
||||
// trying to diagnose org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException in completion
|
||||
private val onCreationDebugInfo = debugInfo()
|
||||
|
||||
fun debugToString(): String {
|
||||
return "PluginDeclarationProviderFactory\nOn failure:\n${debugInfo()}On creation:\n$onCreationDebugInfo"
|
||||
}
|
||||
|
||||
private fun debugInfo(): String {
|
||||
if (nonIndexedFiles.isEmpty()) return "-no synthetic files-\n"
|
||||
|
||||
return buildString {
|
||||
nonIndexedFiles.forEach {
|
||||
append(it.name)
|
||||
append(" isPhysical=${it.isPhysical}")
|
||||
append(" modStamp=${it.modificationStamp}")
|
||||
appendln()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user