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

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

问题描述

我有一个 sbt 管理的 Scala 项目,它使用 通常的 sbt 项目布局 用于带有宏的 Scala 项目,即包含宏的子项目 主项目是实际应用程序并且依赖于宏子项目.宏是宏注释,本质上为定期上课.生成的伴随对象在其他成员中声明了应用/取消应用方法.

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 项目,并使用 IDEA 的 sbt-plugin 中的 sbt 控制台来编译和运行我的 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.

除了生成的伴生对象,更重要的是,它们的成员(例如 apply/unapply)不被 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 和 Windows 7 x64 上的 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 识别由 Scala 宏(准确地说是宏注释)生成的代码(类、对象、方法等)?

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 开发人员说,我要求的功能是他们的长期目标——do list,但不会很快实施(2014-03-05).

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天全站免登陆