Kotlin Analysis API Documentation Help

KaDiagnosticWithPsi

A KaDiagnostic reported on a PsiElement of type PSI.

This is the element type of a KaDiagnostics query, so every diagnostic obtained from diagnostic collection knows the PSI it is attached to.

Hierarchy

Inherits from KaDiagnostic.

interface KaDiagnosticWithPsi<out PSI : PsiElement> : KaDiagnostic

The generated KaFirDiagnostic<PSI> interface inherits from KaDiagnosticWithPsi<PSI> and has a subinterface per diagnostic kind, with the parameters of that diagnostic exposed as typed properties:

val wrongTargets = file.diagnostics() .filterIsInstance<KaFirDiagnostic.WrongAnnotationTarget>()

Those interfaces are annotated @KaUnstableDiagnosticApi and have no compatibility guarantees. See Selecting diagnostics by kind for the trade-off against factoryName.

Members

val psi: PSI

The PSI element the diagnostic is reported on. For a diagnostic from a query with the default directOnly(false), this is the queried element itself or any element below it.

val textRanges: Collection<TextRange>

The text ranges where the diagnostic occurs, in the offsets of the containing file, and contained within the range of the psi element. A diagnostic is not necessarily reported on the whole element — the ranges are what an editor would underline.

val diagnosticClass: KClass<out KaDiagnosticWithPsi<PSI>>

The class of the diagnostic, narrowed from KaDiagnostic.diagnosticClass.

20 August 2026