scala - ILoop 选项卡完成

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

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

我的用例如下所示简单:

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

除了 ILoop 之外,我还应该使用其他东西吗?

最佳答案

这对我有用,模版本。

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

关于scala - ILoop 选项卡完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40322771/

相关文章:

assembly - 使用 Windows WinAPI 函数写入控制台 Unicode (UTF-16) 文本?

scala - 在 Scala 中实现产品类型,并在其各个部分上使用通用更新功能

linux - 在文件夹中的所有文件中插入行号

scala - 如何组合两个具有zio效果和不同类型环境的Http4s路由

delphi - CP_UTF8 是 WriteConsoleA/WriteFile 支持的代码页吗?

haskell - 如何将指定为自由单子(monad)的程序与预期指令的描述进行比较?

c - Brainfuck 解释器不运行某些代码

java - Java 中 .class 文件的用途

scala - Play Framework 2.4.1 : How to get configuration values just after configuration file has been loaded

java - Spark-Cassandra Maven 项目,带有进行 scala-lib 调用的 java 源代码