Is it possible to generate code in FIR which is th...
# compiler
t
Is it possible to generate code in FIR which is then recognised by the IDE? I would like to add constructors automatically for user convenience.
j
What do you mean with recognized? Everything generated with FIR extensions will be available in the IDE, so you can call that constructor even without syncing the IDE. But if you tries to go to the sources, you can’t as “they don’t exist”. For this last there is a youtrack issue.
t
When I generate code with backend IR, the IDE does not realise that it's there until the class is compiled. I haven't worked with FIR yet and I was wondering how it works. Also, I don't know the current status of FIR. Does it work with the latest stable IntelliJ or do I have to use a development or EAP version or something?
j
With FIR that would be accessible from the IDE, one example is generating a function (with empty/no body) and later add the body in IR. An example about this is what Kotlin Serialization does, when you finish to write the
@Serializable
annotation over a
Foo
class, you find in the IDE
Foo.serializer()
, if you comment the annotation, the function is not generated, so it "disappears". FIR is not working in the latest EAP for third party plugins (not sure for JetBrains ones tho), so you must clone the IntelliJ Community repo, and execute the configuration
IDEA (K2 Kotlin)
. When the IDE is built and it is running, you must change this key,
kotlin.k2.only.bundled.compiler.plugins.enabled -> false
, in the Registry (you can find it by looking for
Registry
in the
Actions
tab from the dialog populated with shift + shift)
t
Thank you! I think I will postpone this until FIR gets a bit more stable.
👍 1