如何使IntelliJ IDEA识别由宏创建的代码? [英] How to make IntelliJ IDEA recognise code created by macros?

查看:1142
本文介绍了如何使IntelliJ IDEA识别由宏创建的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个sbt管理的Scala项目,使用具有宏的Scala项目的实际sbt项目布局,即包含宏的子项目是主项目,是实际应用程序,并且依赖于宏子项目。宏是宏注释,本质上是生成常规类的随播对象。生成的伴随对象在其他成员中声明了apply / unapply方法。

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.

我使用sbt-idea插件来生成一个对应的IntelliJ IDEA项目,我使用sbt控制台从IDEA的sbt-plugin编译和运行我的Scala应用程序。

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.

一切都有效果,除了生成的伴侣对象,更重要的是,他们的成员作为适用/不适用,不被IDEA认可。因此,我得到一个弯曲的线无处不在我,例如,apply方法。

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.

我的设置是IntelliJ IDEA CE 133.471与插件SBT 1.5.1和Scala 0.28.363

My setup is IntelliJ IDEA CE 133.471 with the plugins SBT 1.5.1 and Scala 0.28.363 on Windows 7 x64.

如何让IntelliJ IDEA识别代码(类,对象,

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

其他IDE,例如Eclipse,已知可以更好地工作这样的设置?

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

这个问题(不太详细)基本上是相同的,但还没有得到回复(2014-02-26)。

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

根据JetBrains开发人员,我要求的功能是他们的长期待办事项列表,但不会

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).

推荐答案

使用最新的Scala插件构建,有一个API可以用于编写您自己的插件以支持您的宏: http://blog.jetbrains.com/scala/2015/10/14/intellij-api-to-build-scala-macros-support/

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/

现在,每个人都可以使用这个API,使他们的宏更加友好他们最喜欢的IDE。为此,您必须实现 SyntheticMembersInjector ,并将其注册到plugin.xml文件中:

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>


这篇关于如何使IntelliJ IDEA识别由宏创建的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆