PluginDeclarationProviderFactory: improve diagnostic
Attempting to catch EA-103048
This commit is contained in:
+28
-5
@@ -19,9 +19,11 @@ package org.jetbrains.kotlin.idea.stubindex.resolve
|
|||||||
import com.intellij.openapi.components.service
|
import com.intellij.openapi.components.service
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import com.intellij.psi.stubs.StubIndex
|
||||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||||
import org.jetbrains.kotlin.idea.caches.PerModulePackageCacheService
|
import org.jetbrains.kotlin.idea.caches.PerModulePackageCacheService
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ModuleSourceInfo
|
import org.jetbrains.kotlin.idea.caches.resolve.ModuleSourceInfo
|
||||||
|
import org.jetbrains.kotlin.idea.stubindex.KotlinExactPackagesIndex
|
||||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||||
import org.jetbrains.kotlin.idea.stubindex.SubpackagesIndexService
|
import org.jetbrains.kotlin.idea.stubindex.SubpackagesIndexService
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
@@ -70,11 +72,18 @@ class PluginDeclarationProviderFactory(
|
|||||||
override fun diagnoseMissingPackageFragment(file: KtFile) {
|
override fun diagnoseMissingPackageFragment(file: KtFile) {
|
||||||
val packageFqName = file.packageFqName
|
val packageFqName = file.packageFqName
|
||||||
val subpackagesIndex = SubpackagesIndexService.getInstance(project)
|
val subpackagesIndex = SubpackagesIndexService.getInstance(project)
|
||||||
throw IllegalStateException("Cannot find package fragment for file ${file.name} with package $packageFqName, " +
|
val moduleSourceInfo = moduleInfo as? ModuleSourceInfo
|
||||||
"vFile ${file.virtualFile}, nonIndexed ${file in nonIndexedFiles} " +
|
val virtualFile = file.virtualFile
|
||||||
"packageExists=${PackageIndexUtil.packageExists(packageFqName, indexedFilesScope, project)} in $indexedFilesScope," +
|
throw IllegalStateException("""
|
||||||
"SPI.packageExists=${subpackagesIndex.packageExists(packageFqName)} SPI=$subpackagesIndex " +
|
Cannot find package fragment for file ${file.name} with package '$packageFqName':
|
||||||
"OOCB count ${file.manager.modificationTracker.outOfCodeBlockModificationCount}}")
|
vFile: $virtualFile,
|
||||||
|
nonIndexed files: $nonIndexedFiles, isNonIndexed: ${file in nonIndexedFiles},
|
||||||
|
scope = $indexedFilesScope, isInScope = ${virtualFile in indexedFilesScope},
|
||||||
|
packageExists = ${PackageIndexUtil.packageExists(packageFqName, indexedFilesScope, project)}, cachedPackageExists = ${moduleSourceInfo?.let { project.service<PerModulePackageCacheService>().packageExists(packageFqName, it) }},
|
||||||
|
oldPackageExists = ${oldPackageExists(packageFqName) ?: "threw exception"},
|
||||||
|
SPI.packageExists = ${subpackagesIndex.packageExists(packageFqName)}, SPI = $subpackagesIndex, OOCB count ${file.manager.modificationTracker.outOfCodeBlockModificationCount},
|
||||||
|
ModuleModificationCount = ${moduleSourceInfo?.createModificationTracker()?.modificationCount},
|
||||||
|
packageFqNameByTree = '${file.packageFqNameByTree}', packageDirectiveText = '${file.packageDirective?.text}'""")
|
||||||
}
|
}
|
||||||
|
|
||||||
// trying to diagnose org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException in completion
|
// trying to diagnose org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException in completion
|
||||||
@@ -84,6 +93,20 @@ class PluginDeclarationProviderFactory(
|
|||||||
return "PluginDeclarationProviderFactory\nOn failure:\n${debugInfo()}On creation:\n$onCreationDebugInfo"
|
return "PluginDeclarationProviderFactory\nOn failure:\n${debugInfo()}On creation:\n$onCreationDebugInfo"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun oldPackageExists(packageFqName: FqName): Boolean? = try {
|
||||||
|
var result = false
|
||||||
|
StubIndex.getInstance().processElements<String, KtFile>(
|
||||||
|
KotlinExactPackagesIndex.getInstance().key, packageFqName.asString(), project, indexedFilesScope, KtFile::class.java
|
||||||
|
) {
|
||||||
|
result = true
|
||||||
|
false
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
catch (e: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
private fun debugInfo(): String {
|
private fun debugInfo(): String {
|
||||||
if (nonIndexedFiles.isEmpty()) return "-no synthetic files-\n"
|
if (nonIndexedFiles.isEmpty()) return "-no synthetic files-\n"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user