Hi all, I Just upgraded to IntelliJ IDEA 2024.3 an...
# compiler
b
Hi all, I Just upgraded to IntelliJ IDEA 2024.3 and there are a lot of incompatabilities between the standard kotlin 2.0.21 compiler and the compiler that is running inside the IDE I have a FIR plugin that adds a superclass and the function computeAdditionalSupertypes which in kotlin 2.0.21 should return List<FirResolvedTypeRef> is required to return list of cone types if running in the ide (but then List<FirResolvedTypeRef> if running via gradle) also the class ConeNullability does not exists if runing in the IDE but does if running through gradle and also i saw that FirResolvedTypeRef.type does not exists in the IDE how can i fix my plugin so that it can run on both the IDE and gradle after the upgrade to IntelliJ IDEA 2024.3?
y
Have you enabled K2 mode in the Kotlin IntelliJ plugin?
b
Yes
d
IDE plugin uses dev versions of the kotlin compiler for the code analysis, and for now there is no way to preserve the compatibility between these versions and release versions of the compiler. This is the reason why compiler plugins loading is disabled in the IDE by default
You can check what exact version of the Kotlin is bundled into IDEA in the About window and use the bootstrap compiler of some version close to this one for your plugin
b
@dmitriy.novozhilov Thanks, so if i will replace the dependency to the dev version, doesnt it means that compilation by gradle will stop working? is there any plans to synchronize the versions - or you are planning to drop support for 3rd party FIR compiler plugins?
d
compilation by gradle will stop working
It will unless you will use the dev compiler for gradle compilation too
is there any plans to synchronize the versions
We are considering it, but not in the nearest future And even they will be synchronized (e.g. 2.1.20 compiler for 2025.1 IDEA) there still will be problems, if your projects uses not the latest compiler (if you didn't manage to update it yet, for example) The ideal solution for this problem is to have the stable compiler API surface, which is also kinda planned but without any estimates
you are planning to drop support for 3rd party FIR compiler plugins?
No such plans
b
I Understand, how does this problem being solved in the official plugins? does they have two versions? one for the standard compiler and one for the IDE?
d
Yes, official plugins of dev versions are bundled into the IDE together with the compiler So when IDE sees that some compiler plugin is enabled in the build, it enables the bundled one in the IDE The same approach was used for years with K1
b
I Understand - so i will try doing the same - have two versions, detect if running in the IDE or not and then use a classloader to load the correct classes
👍 1
If someone have the same problems, this is what i do for now instead of creating two versions: in FirSupertypeGenerationExtension apply the following function on the list you are returning from computeAdditionalSupertypes :
Copy code
// first detect somewhere in your class if you are running with an old version (i.e., gradle execution):
private val isOldVersion =
        FirSupertypeGenerationExtension::class.members.firstOrNull { it.name == "computeAdditionalSupertypes" }?.returnType?.arguments?.firstOrNull()?.type?.classifier == FirResolvedTypeRef::class

// define an adapter function - we will call it "hack" so that we will not forget to delete it when moving to kotlin 2.1+
fun <T> hack(input: List<FirResolvedTypeRef>) = (if (isOldVersion) input else input.map { it.coneType }) as List<T>

// we can then apply "hack" on the return value of computeAdditionalSupertypes
override fun computeAdditionalSupertypes( ... ): List<FirResolvedTypeRef> {
    val toReturn: List<FirResolvedTypeRef> = ...
    return hack(toReturn)
}
in addition, when you are trying to get coneTypes via the type method (e.g., using FirResolvedTypeRef.type) replace it with coneType method
I had to some slight modifications here and there but it was eventually solvable..