Hello, I'm trying out compiler plugins and I wonde...
# compiler
g
Hello, I'm trying out compiler plugins and I wonder if
AnalysisHandlerExtension
is the right place for things like returning errors if the class name is not valid (as a simple use case). To do so I've implemented something like this:
Copy code
class CGAnalysisHandlerExtension : AnalysisHandlerExtension {
  override fun doAnalysis(
    project: Project,
    module: ModuleDescriptor,
    projectContext: ProjectContext,
    files: Collection<KtFile>,
    bindingTrace: BindingTrace,
    componentProvider: ComponentProvider
  ): AnalysisResult? {

    files.forEach { file ->
      val fileName = file.name.replace(".kt", "")
      file.children.forEach {
        when (it) {
          is KtClass -> {
            if (it.name != fileName) {
              bindingTrace.report(UNDERSCORE_IS_RESERVED.on(it))
              return AnalysisResult.compilationError(bindingTrace.bindingContext)
            }
          }
        }
      }
    }
    return super.doAnalysis(project, module, projectContext, files, bindingTrace, componentProvider)
  }
}
Doing so I thought I'd see the IDE underline the className in red with its error but the IDE doesn't react to this report, only when compiling and in the Build Output (see screenshot). So my question is the following: What is the missing piece here to have the IDE show the report/error as any other errors, and can't I have this check actually happen when the class is in the "Analyzing..." phase of the IDE? Thanks in advance!
After more research and as I feared, I am indeed supposed to build my own IntelliJ plugin alongside the compiler plugin, is that correct? Seems counter intuitive to me as it's just to present errors, so how can I enable the IDE to be aware of the compiler plugin errors?
Hey @raulraja Sounds like you went deep into this matter, what's your take on this? 😊
r
can’t type much 🛹 🦴 . can use a declaration checker for that. for ide interop look into the FIR extensions
org.jetbrains.kotlin.fir.analysis.extensions.FirAdditionalCheckersExtension
when fir is stable the kotlin ide picks it up and all good
g
Thanks ☺️
@raulraja is there a planned release date for FIR? When implementing that class, do you already see the IDE picking it up, maybe a version from Canary channel?
r
No available IDE version yet afaik but FIR can be activated. Our project uses a dev version of the compiler
@Javier and I are working on it trying to adapt to latest FIR pre release
j
There is no date and it will not be with 1.7.0. Hope we get it with 1.8.0 🙏
g
So around the end of the year? Nice!
🙂 1
j
If we have luck, maybe :)
K 1
g
@raulraja @Javier Thank you both, your project will help me greatly to understand how to implement this 😊
👏 1
🙂 1
r
feel free to rip off code you need from there or ask us questions around here
❤️ 1