AA: better error message for file w/o containing module
...instead of throwing NoSuchElementException
This commit is contained in:
committed by
Ilya Kirillov
parent
b67b37cdb3
commit
5596c3ae80
+9
-3
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.project.structure.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.contains
|
||||
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
class KtStaticModuleProvider(
|
||||
private val builtinsModule: KtBuiltinsModule,
|
||||
@@ -31,8 +32,13 @@ class KtStaticModuleProvider(
|
||||
containingFileAsVirtualFile in binaryModule.contentScope
|
||||
}?.let { return it }
|
||||
|
||||
return projectStructure.mainModules
|
||||
.first { module -> element in module.ktModule.contentScope }
|
||||
.ktModule
|
||||
return projectStructure.mainModules.firstOrNull { module ->
|
||||
element in module.ktModule.contentScope
|
||||
}?.ktModule
|
||||
?: throw KotlinExceptionWithAttachments("Cannot find KtModule; see the attachment for more details.")
|
||||
.withAttachment(
|
||||
containingFileAsVirtualFile.path,
|
||||
allModules.joinToString(separator = System.lineSeparator()) { it.asDebugString() }
|
||||
)
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.LLFirBu
|
||||
import org.jetbrains.kotlin.analysis.project.structure.*
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
internal class KtModuleProviderImpl(
|
||||
private val platform: TargetPlatform,
|
||||
@@ -36,6 +37,7 @@ internal class KtModuleProviderImpl(
|
||||
LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(platform).ktModule as KtBuiltinsModule
|
||||
}
|
||||
|
||||
@OptIn(KtModuleStructureInternals::class)
|
||||
override fun getModule(element: PsiElement, contextualModule: KtModule?): KtModule {
|
||||
val containingFileAsPsiFile = element.containingFile
|
||||
?: return ktNotUnderContentRootModuleWithoutPsiFile
|
||||
@@ -56,9 +58,16 @@ internal class KtModuleProviderImpl(
|
||||
return builtinsModule
|
||||
}
|
||||
|
||||
return mainModules.first { module ->
|
||||
containingFileAsVirtualFile.analysisExtensionFileContextModule?.let { return it }
|
||||
|
||||
return mainModules.firstOrNull { module ->
|
||||
containingFileAsVirtualFile in module.contentScope
|
||||
}
|
||||
?: throw KotlinExceptionWithAttachments("Cannot find KtModule; see the attachment for more details.")
|
||||
.withAttachment(
|
||||
containingFileAsVirtualFile.path,
|
||||
mainModules.joinToString(separator = System.lineSeparator()) { it.asDebugString() }
|
||||
)
|
||||
}
|
||||
|
||||
internal val binaryModules: List<KtBinaryModule> by lazy {
|
||||
|
||||
+14
@@ -18,3 +18,17 @@ public var VirtualFile.analysisExtensionFileContextModule: KtModule? by UserData
|
||||
|
||||
@RequiresOptIn("Internal KtModule structure API component which should not be used outside the Analysis API implementation modules as it does not have any compatibility guarantees")
|
||||
public annotation class KtModuleStructureInternals
|
||||
|
||||
public fun KtModule.asDebugString(indent: Int = 0): String = buildString {
|
||||
appendLine("$moduleDescription {")
|
||||
appendLine("contentScope: $contentScope")
|
||||
appendLine("directRegularDependencies:${System.lineSeparator()}")
|
||||
directRegularDependencies.joinTo(this, separator = System.lineSeparator()) { dep ->
|
||||
dep.asDebugString(indent + 1)
|
||||
}
|
||||
appendLine("directDependsOnDependencies:${System.lineSeparator()}")
|
||||
directDependsOnDependencies.joinTo(this, separator = System.lineSeparator()) { dep ->
|
||||
dep.asDebugString(indent + 1)
|
||||
}
|
||||
append("}")
|
||||
}.prependIndent(" ".repeat(indent))
|
||||
|
||||
Reference in New Issue
Block a user