【问题标题】:ILoop Tab CompletionILoop 选项卡完成
【发布时间】:2017-03-12 09:22:20
【问题描述】:

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

我的用例如下所示:

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

除了ILoop,还有什么我应该使用的吗?

【问题讨论】:

  • 您是在scalasbt 或其他类路径下运行吗?

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


【解决方案1】:

它对我来说有点用,模数版本。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    • 2014-08-12
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多