Hi everyone! I'm playing around with writing a c...
# compiler
l
Hi everyone! I'm playing around with writing a compiler plugin for k2, and I recently added custom checks to it. I'm running into the issue with the relocated dependencies in the embeddable kotlin compiler, where I cannot resolve
com/intellij/psi/PsiElement
depending on the context. I got my gradle setup far enough to where I can output my plugin as both variants however I want, but I see no way to actually get it to work; When loading the plugin from gradle, the same compiler plugin has to work in the IDE and the gradle build. But if the gradle plugin refers to the non-embeddable version, it works in the IDE but fails in gradle. If it points to the embeddable version, its the other way around. It was said here before that this will be fixed in some way - is there already a fix for this? Could be that I'm simply missing something. How are the built in compiler plugins solving this? As far as I've seen they also create two different versions, just like I do. But how do they get the IDE to use the right one?
I'm running on the "regular" EAP build:
Build #IU-232.8453.116, built on June 29, 2023
With the following jvm options added:
Copy code
-Didea.kotlin.plugin.use.k2=true
-Dkotlin.k2.only.bundled.compiler.plugins.enabled=false
This is the exception I'm seeing:
d
Please report issue about this: kotl.in/issue As about workarounds: don't use classes from IDEA platform in your plugin Actually it's not a workaround, but general way to go, because it's planned someday to get rid of dependency on IDEA in compiler at all
BTW compiler in CLI mode already doesn't use PSI at all So it's not recommended to check anything on PSI in plugins, because it just won't work in CLI
l
The only place where I'm using the classes from IntelliJ are the errors, which need a PsiElement:
Copy code
val MISSING_TEMPLATE_HANDLER_ERROR by error1<PsiElement, FirClassSymbol<*>>(SourceElementPositioningStrategies.NAME_IDENTIFIER)
I did this because I saw it in the noarg k2 module, is there an alternative to this? That would also solve the issue of course 😄
d
Try use
org.jetbrains.kotlin.psi.KtElement
instead of
com.intellij.psi.PsiElement
l
Aaah! That was the missing piece 😄 Thank you very much! Seems like I was on the right track at least, but I was looking at whether
KtSourceElement
implements
PsiElement
Working with k2 is pretty exciting so far btw, really enjoying it!
d
Nice to hear