How to make IntelliJ IDEA recognise code created b

2019-04-28 20:55发布

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 IDEA 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 IntelliJ IDEA CE 133.471 with the plugins SBT 1.5.1 and Scala 0.28.363 on Windows 7 x64.

Questions

How do I get IntelliJ IDEA to recognise code (classes, objects, methods, ...) that has been generated by Scala macros (macro annotations, to be precise)?

Are other IDEs, e.g., Eclipse, known to work better in such a setting?

Related

This question (which is less detailed) essentially asks the same, but has not gotten a reply yet (2014-02-26).

According to a JetBrains developer the feature I requested is on their long-term to-do list, but won't be implemented any time soon (2014-03-05).

2条回答
老娘就宠你
2楼-- · 2019-04-28 21:39

With the latest Scala plugin build, there is an API which can be used to write your own plugin to support your macros: http://blog.jetbrains.com/scala/2015/10/14/intellij-api-to-build-scala-macros-support/

Now, everyone can use this API to make their macros more friendly to their favorite IDE. To do that, you have to implement SyntheticMembersInjector, and register it in the plugin.xml file:

<extensions defaultExtensionNs="org.intellij.scala">
  <syntheticMemberInjector implementation="org.jetbrains.example.injector.Injector"/>
</extensions>
查看更多
小情绪 Triste *
3楼-- · 2019-04-28 21:47

Seems like there's limited support if any.

Quote by this link: http://blog.jetbrains.com/scala/2014/01/23/heading-to-the-perfect-scala-code-analysis/

Alexander Podkhalyuzin says:    

January 30, 2014 at 10:13 am

We started support for Scala macros, but it’s not a simple task, so I can’t promise it will be done soon.

Best regards, Alexander Podkhalyuzin.

查看更多
登录 后发表回答