Debugging normal macros in Intellij works fine as Jan Machacek explained here.
But with a macro annotation I haven't found a way to debug the macro before the process finishes. I tried various settings in Intellij without luck.
Here's a def and annotation macro to debug:
package demo
import scala.language.experimental.macros
import scala.reflect.macros.Context
import scala.annotation.StaticAnnotation
class myAnnotation extends StaticAnnotation {
def macroTransform(annottees: Any*) = macro Test.transformAnnottees
}
object Test {
def transformAnnottees(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
println("Annotation macro") // <-- breakpoint here not reached
c.Expr[Any](annottees.head.tree) // dummy
}
def debug[A]: String = macro Test.debug_impl[A]
def debug_impl[A: c.WeakTypeTag](c: Context): c.Expr[String] = {
import c.universe._
println("Normal macro") // <-- breakpoint here reached
c.Expr[String](Literal(Constant(weakTypeOf[A].toString)))
}
}
And a runner:
package demo
object TestDebugging extends App {
@myAnnotation
class A
val a = new A
println(Test.debug[A]) // "demo.TestDebugging.A"
}
My Run/Debug configuration in Intellij:
- Type: Application
- Main class: scala.tools.nsc.Main
- VM options: -Dscala.usejavacp=true
- Program arguments: -cp demo.Test mymodule/src/test/scala/demo/TestDebugging.scala
- Working directory: /Users/mg/project/testMacroDebugging
- Environment variables: [none]
- Use class path of module: mymodule
- Before launch: Make
As program arguments I also tried
- -cp demo.myAnnotation mymodule/src/test/scala/demo/TestDebugging.scala
So, I basically said to Intellij that I want to debug demo.Test
when running TestDebugging.scala
, right? But when I set a breakpoint in both transformAnnottees
and debug_impl
I only get to debug the latter.
I see both "Annotation macro" and "Normal macro" printing during make, so the annotation is apparently working. What am I missing to debug the annotation macro transformAnnottees
?
(Using Intellij 12.1.6, build 129.1359, JRE 1.6.0_65)
EDIT:
As a debugging alternative to having macroTransform
in the annotation class being called via the annotation, then maybe I could get access to the normal debugging flow if instead called a normal def method
def macroTransform2(annottees: Any*): Any = macro transform
inside the Test
object? That would be for just testing purposes and could be commented out when not debugging. I couldn't find a way to supply the equivalent arguments as the annotation sends (the ClassDef)... Is there a way to get this clumsy hack working or better; avoiding it?
macros
project to have scala.tools.nsc.Main on the class path of thecore
module in the debugger setup. But I still can't step intohelloMacro
in a debug session.-Xplugin:<path to the macro paradise jar> -Xplugin-require:macroparadise
to your program arguments in the debug configuration?