dsavvinov
06/21/2019, 2:15 PMclass (val x: Int) { ... }
). Those sources obviously can not be compiled to bytecode, and CLI compiler would just reject them. IDE, however, is expected to provide as much insight as possible even on incorrect code, and sometimes even uses some heuristics and assumptions about “most popular cases”.
The main takeaway here is that IDEA doesn’t read compiled binaries of your source in order to provide analysis. That would make performance terrible (imagine that after adding several new lines of code you’d need to wait for recompilation of your project in order to get completion), and would prevent analysis of incomplete code (there’s no way to compile “red” code to binaries).
What does it mean for compiler plugins authors? It means that you have to ship IDEA plugin alongside with your compiler plugin if you want to see correct resolution results in IDE:
- IDEA and CLI compiler indeed share common infrastructure, especially for compiler’s frontend, but as per №1, CLI pipeline doesn’t affect IDE pipeline, so even if you use your plugin in CLI and it works, you’ll still have to bring that logic into IDE somehow
- One might be tempted to say that if CLI compiler with some plugin compiles sources fine and produces correct binaries, then IDE should just read those binaries up and provide correct analysis results. Well, as per №2 — no, that’s not how at least IDEA works, and №2 lists several reasons why. Maybe some other IDE does, but not IDEA.