ILoop标签完成

时间:2016-10-29 19:20:37

标签: scala console interpreter read-eval-print-loop tab-completion

我正在创建scala.tools.nsc.interpreter.ILoop的一个非常简单的扩展,目的是添加一些额外的绑定,但即使在最基本的用例中,tab-completion似乎也不起作用。如果我输入代码,它会解释并按预期工作,但我没有tab-completion。是否需要定义某些特定内容才能在交互式解释器(REPL)中启用制表符完成?

我的用例非常简单:

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

我应该使用ILoop以外的其他内容吗?

1 个答案:

答案 0 :(得分:2)

它对我有用,模数版。

$ 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

来源:

$ 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
}
*/