darkfrog darkfrog - 1 month ago 9
Scala Question

ILoop Tab Completion

I am creating a very simple extension of

scala.tools.nsc.interpreter.ILoop
with the intent of adding some additional bindings, but even in the most basic use-case the tab-completion does not seem to work. If I type in code it interprets and works as expected, but I no tab-completion. Is there something specific that needs to be defined in order for tab-completion to be enabled in the interactive interpreter (REPL)?

My use-case is as simple as the following:

val repl = new ILoop
repl.process(new Settings {
usejavacp.value = true
deprecation.value = true
})


Is there something other than
ILoop
I should be using?

Answer

It kind of works for me, modulo version.

$ scalacm myintp.scala && scalam myintp.Test
Welcome to Scala 2.12.0-RC2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions for evaluation. Or try :help.

scala> 42
res0: Int = 42

scala> 42.
!=   <    >>>         doubleValue   isNaN           isValidShort   shortValue       toDouble        toShort      
%    <<   ^           floatValue    isNegInfinity   isWhole        signum           toFloat         unary_+      
&    <=   abs         floor         isPosInfinity   longValue      to               toHexString     unary_-      
*    ==   byteValue   getClass      isValidByte     max            toBinaryString   toInt           unary_~      
+    >    ceil        intValue      isValidChar     min            toByte           toLong          underlying   
-    >=   compare     isInfinite    isValidInt      round          toChar           toOctalString   until        
/    >>   compareTo   isInfinity    isValidLong     self           toDegrees        toRadians       |            

scala> 42.s
self   shortValue   signum   synchronized

scala> 42.self
res1: Int = 42

scala> :quit

Source:

$ cat myintp.scala
package myintp

import scala.tools.nsc._
import scala.tools.nsc.interpreter._

/* 2.12 */
object Test extends App {
  val ss = new Settings {
    usejavacp.value = true
    deprecation.value = true
  }
  def repl = new ILoop {
    override def createInterpreter(): Unit = {
      super.createInterpreter()
    }
  }
  repl process ss
}

/* 2.11
object Test extends App {
  def repl = new ILoop {
    override def createInterpreter(): Unit = {
      def binder: Unit = intp beQuietDuring {
        intp directBind ("foo", "bar")
        intp bind ("baz", "boo")
      }
      super.createInterpreter()
      intp initialize binder
    }
  }
  repl process new Settings
}
*/

/* 2.9
object Test extends App {
  def repl = new ILoop {
    def binder: Unit = intp beQuietDuring {
      intp bind ("baz", "boo")
    }
    override def loop(): Unit = {
      binder
      super.loop()
    }
  }
  repl process new Settings
}
*/