How to make IntelliJ recognise code created by macros?
For the record: I originally postedthis question at Stackoverflow, but did't get any replies so far.
Background: I have an sbt-managed Scala project that uses the usual sbt project layout for Scala projects with macros, i.e., a subproject that contains the macros a main project that is the actual application and that depends on the macro subproject. The macros are macro annotations which, in essence, generate companion objects for regular classes. The generated companion objects declare, amongst other members, apply/unapply methods.
I used the sbt-idea plugin to generate a corresponding IntelliJ project, and I use the sbt console from IDEA's sbt-plugin to compile and run my Scala application.
Everything works more or less fine, except that the generated companion objects, and more importantly, their members such as apply/unapply, are not recognised by IDEA. Thus, I get a squiggly line everywhere I, e.g., an apply method.
My setup is IDEA CE 133.471 with the plugins SBT 1.5.1 and Scala 0.28.363 on Windows 7 x64.
Question: How do I get IntelliJ to recognise code (classes, objects, methods, ...) that has been generated by Scala macros (macro annotations, to be precise)?
Please sign in to leave a comment.
Right now we haven't solution for it. The same is for language plugins. I have plans to implement small language to add possibility dynamically patch Scala plugin with writing plugins to Scala plugin, but it's not yet implemented as it's not really popular solution to use macro annotations or language plugins. So people who are using such features should implement plugin for Scala too.
Things will change in future, but I can't promise any date.
Best regards,
Alexander Podkhalyuzin.
Thanks for your clarifications! I agree that macros which change the signature of classes/methods/etc. are probably not the most popular Scala feature, but it would be nice to have IDE-support for generated code as well. In any case, thanks for your great work on the Scala plugin!
wouldn't it made sense to "just compile everything", and if it worked, the generated code can be used by the scala plugin as a library, just like any other dependency?
the only other way i see is to re-implement macros inside the scala plugin completely, or integrate the presentation compiler for this
Does Project Palladium (http://scalareflect.org/) not apply here - which I understand Alexander is already engaged with?
Project palladium is exactly place where we want to implement our ideas.
Best regards,
Alexander Podkhalyuzin.
We are working on macros interpreter. It will be possible to use it in compiler for one-pass compiler (to have macros and macros usage in the same module) as well as we will use it for highlighting in IDEA.
Your way will be most probably sluggish. We will start from interpreter then we will see how it works and what we can improve even more.
Best regards,
Alexander Podkhayuzin.
I did not know about Project Palladium, thanks for bringing it to my attention. Exciting times for Scala macros :-)
What do you mean by saying 'So people who are using such features should implement plugin for Scala too.'? Do you mean implementing a plugin that would somehow cooperate with Scala plugin to support custom extensions? How to achieve that?
We are working on some settings script (initial support at the end of June?), which will enable generated methods support dynamically without any needs to add your own IntelliJ IDEA plugin.
Best regards,
Alexander Podkhalyuzin.
Dear Alexander,
any news on this issue? I haven't yet updated to IDEA 14.x, but would it make a difference with respect to macros?
Thanks,
Malte
There is no difference in macros support between IDEA 14 and IDEA 13 versions. I hope something will be done in this direction before IDEA 15, so IDEA 14 release will contain support for macros.
Moreover we will add some hardcoded cases (for example shapeless) before IDEA 14 release.
Best regards,
Alexander Podkhalyuzin.