0

I am creating some macros for a class that extends scala.Dynamic. These macros looks like:

class MyProxy extends scala.Dynamic {
  final def selectDynamic(field: String): MyProxy = macro ...
  final def updateDynamic(field: String)(value: Any): Unit = macro ...
}

These macros works fine. But a MyProxy only allows a set of limited members accessing, and I want these members are listed from Scala IDE's content assist and REPL console's Tab key.

Because MyProxy instances themselves are created by macros, I wonder if there is any attribute like setCodeCompletionType that can be set from the macros that create MyProxy, helping REPL and Scala IDE's code completion (and does not affect the generated Java byte code). Then I would have a macro like this:

def newMyProxyInstanceImpl(c: Context)(...): c.Expr[MyProxy] = {
  import c.universe._
  val tree: Tree = ...
  val codeCompletionHint: Type = RefinedType(...)
  tree.setCodeCompletionType(codeCompletionHint)
  c.Expr(tree)
}

How can I hack the Scala compiler to make this approach work?

Yang Bo
  • 3,586
  • 3
  • 22
  • 35
  • 1
    This behavior is not yet implemented. If you really want to hack scalac then you should ask this question on scala-internals, where all the compiler, macro and IDE gurus are sitting. No one can give you a full answer (which lists all the things to do) here. – kiritsuku May 14 '14 at 14:20
  • Some macro folks check stack overflow as well :) – Eugene Burmako May 14 '14 at 17:49
  • Is a compiler plugin able to inject into the code completion process? – Yang Bo May 14 '14 at 18:50
  • Not sure, probably not, but that you'll have better luck asking at scala-ide-dev – Eugene Burmako May 14 '14 at 20:43
  • In general, macro-powered completion is one of the things I've long been thinking about, but never got time to implement. If you figure out a mechanism to communicate completion info to the IDE please post back here. – Eugene Burmako May 14 '14 at 20:43
  • Can I determine whether the macro is evaluated by IDE, like `if (c.getClass.getPackage.toString.startsWith("scala.tool.eclipse.")) return reify { ??? : { def memberForCodeCompletion0: MyProxy; def memberForCodeCompletion1: MyProxy; } }`? – Yang Bo May 15 '14 at 01:59

0 Answers0