Alexander Ioffe
01/02/2025, 7:59 PMDiagnosticReporter
and create error/warning IDE underlines from a backend-ir plugin?Javier
01/02/2025, 8:34 PMAlexander Ioffe
01/02/2025, 8:35 PMJavier
01/02/2025, 8:35 PMJavier
01/02/2025, 8:35 PMAlexander Ioffe
01/02/2025, 8:36 PMJavier
01/02/2025, 8:37 PMFirTo***
or something soAlexander Ioffe
01/02/2025, 9:54 PMJavier
01/02/2025, 9:57 PMJavier
01/02/2025, 9:57 PMAlexander Ioffe
01/02/2025, 9:59 PMJavier
01/02/2025, 10:00 PMAlexander Ioffe
01/02/2025, 11:06 PMdmitriy.novozhilov
01/03/2025, 8:19 AMIrPluginContext.messageCollector
recently added in master
It will be available in 2.1.20-Beta2dmitriy.novozhilov
01/03/2025, 8:31 AME.g. using the DiagnosticSink ...
DiagnosticSink
is K1-specific service. K2 (both frontend and backend) uses DiagnosticReporter
and it's inheritor BaseDiagnosticsCollector
(yeah, naming sucks and I plan to rename everything to be reporters)
... or passing backend-data back to FIR plugins?As Javier mentioned above, it's impossible, as FIR plugins won't be called after fir2ir transformation, and IR plugins are called right after fir2ir
Alexander Ioffe
01/03/2025, 1:41 PMAlexander Ioffe
01/15/2025, 4:54 PMval msgCollector = config.get(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
val reporter = DiagnosticReporterFactory.createReporter(msgCollector)
val contextReporter = KtDiagnosticReporterWithImplicitIrBasedContext(reporter, config.languageVersionSettings)
// then later...
<http://contextReporter.at|contextReporter.at>(elem, currentFileRaw).report(MyDiagFactory, msg)
Only when I do this (from a backend-ir plugin) I don't see any warning underlines anywhere.
What am I doing wrong?dmitriy.novozhilov
01/15/2025, 6:22 PMAlexander Ioffe
01/15/2025, 6:24 PMobject Diagnostics {
val DiagFactory: KtDiagnosticFactory1<String> by warning1<PsiElement, String>()
val Renderer = object: ContextIndependentParameterRenderer<String> {
override fun render(obj: String): String = obj
}
object KtMessages : BaseDiagnosticRendererFactory() {
override val MAP =
KtDiagnosticFactoryToRendererMap("Unexpected Stuff").also { map ->
map.put(DiagFactory, "Unexpected Stuff happened: {0}", Renderer)
}
}
}
// and then:
class Registrar: CompilerPluginRegistrar() {
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
RootDiagnosticRendererFactory.registerFactory(KtMessages)
...
}
}
Alexander Ioffe
01/15/2025, 8:10 PMcontextReporter.at(elem.sourceElement(), elem, currentFileRaw).report(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS
...and I'm seeing nothing. I've also tried KtDiagnosticReporterWithContext and a bunch of other things. (Goes without saying that K2 mode is enabled)
Nothing happens. No red or yellow underlines anywhere and no messages about any of this in the compiler. Seems that the report is completely ignored.
@dmitriy.novozhilov Sorry to continue bothering you but any thoughts on where I should be looking in order know why I'm not seeing anything in the IDE?
I know this part of the code is being hit because I put MessageCollector.report right next to it and that's working.dmitriy.novozhilov
01/15/2025, 8:57 PMdmitriy.novozhilov
01/15/2025, 8:59 PMSimpleDiagnosticReporter
)Alexander Ioffe
01/15/2025, 9:31 PMSimpleDiagnosticsCollectorWithSuppress
and the rawReporter of that is DiagnosticReporterFactory
. Then I use the SimpleDiagnosticsCollectorWithSuppress
to create the KtDiagnosticReporterWithImplicitIrBasedContext
.
I tried a whole bunch of different things e.g. checkAndCommitReportsOn i.e:
val srcElem = elem.toSourceElement(currentFileRaw) ?: throw IllegalArgumentException("...")
val ctx = contextReporter.at(srcElem, elem, currentFileRaw)
ctx.report(DiagFactory, msg)
contextReporter.checkAndCommitReportsOn(srcElem, ctx)
I even tried flushing on both the reporters:
ctx.report(DiagFactory, msg)
contextReporter.checkAndCommitReportsOn(srcElem, ctx)
reporter.checkAndCommitReportsOn(srcElem, ctx)
Also tried the ctx with the regular reporter:
val ctx = contextReporter.at(srcElem, elem, currentFileRaw)
reporter.reportOn(srcElem, DiagFactory, msg, ctx)
reporter.checkAndCommitReportsOn(srcElem, ctx)
Nothing is underlined and the compiler reports nothing.
(Ironically reporter.reportToMessageCollector makes it appear immediately but still no red/yellow underlines).Javier
01/15/2025, 10:01 PMAlexander Ioffe
01/15/2025, 10:25 PMAlexander Ioffe
01/15/2025, 10:27 PMAlexander Ioffe
01/16/2025, 3:47 AMAlexander Ioffe
01/16/2025, 4:09 AMAlexander Ioffe
01/16/2025, 4:10 AMdmitriy.novozhilov
01/16/2025, 7:45 AM