在Intellij中调试宏注释

时间:2015-07-25 21:02:25

标签: scala debugging intellij-idea scala-macros

在调试宏注释时,IntelliJ会抛出此错误:

test\UseMacro.scala:7: error: macro annotation could not be expanded (the most common reason for that is that you need to enable the macro paradise plugin; another possibility is that you try to use macro annotation in the same compilation run that defines it)
@identity class Test

我有一个使用宏子项目(macroSub)的主项目。宏项目定义简单的@identity宏,主项目使用此项与UseMacro.scala

build.sbt:

lazy val commonSettings = Seq(
  version := "1.0",
  scalaVersion := "2.11.7"
)

lazy val root = (project in file(".")).
  dependsOn(macroSub).
  enablePlugins(PlayScala).
  settings(commonSettings: _*).
  settings(
    name := "root",
    resolvers ++= Seq(
      "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/",
      "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
    ),
    libraryDependencies ++= Seq(
      "com.typesafe.akka" %% "akka-actor" % "2.4-SNAPSHOT",
      "com.typesafe.akka" %% "akka-agent" % "2.4-SNAPSHOT"
    )
  )

lazy val scalaReflect = Def.setting { "org.scala-lang" % "scala-reflect" % scalaVersion.value }

lazy val macroSub = (project in file("macro")).
  settings(commonSettings: _*).
  settings(
    resolvers ++= Seq(
      Resolver.sonatypeRepo("releases")
    ),
    libraryDependencies += scalaReflect.value,
    libraryDependencies += compilerPlugin("org.scalamacros" % "paradise" % "2.1.0-M5" cross CrossVersion.full),
    addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.8")
  )

我可以成功调试普通的宏,但是当我创建一个宏注释时,我有这种错误。我应该如何处理intellij配置和build.sbt以解决该问题并调试宏注释?

1 个答案:

答案 0 :(得分:0)

我无法配置IntelliJ以在我的项目中完全运行宏调试,但是我发现trudolf更容易解决方案,也适用于宏注释:

  
      
  • 启动sbt:sbt -jvm-debug 5005
  •   
  • 创建一个" Remote" "运行/调试配置"在想法(默认为端口5005)
  •   
     

在想法中运行remote-debug配置。这将把它连接到你正在运行的sbt。然后你可以在宏代码中设置断点,当在sbt中运行compile时,idea应该在断点处停止。