Search code examples
scalaread-eval-print-loop

How to enable tab completion in Scala's MainGenericRunner REPL (interactive interpreter)?


I've added a REPL (read eval print loop) to may Java project1 which is build with maven. The REPL can be started with a script. The relevant parts are

declare -r GRADLE_CLASSPATH="$(gradle :minidns-repl:printClasspath --quiet |tail -n1)"

java \
    -Dscala.usejavacp=true \
    -classpath "${GRADLE_CLASSPATH}" \
    scala.tools.nsc.MainGenericRunner \
    -i minidns-repl/scala.repl

This works so far. The only thing that is missing which would make the REPL perfect is tab completion. I know from Scala that it does support this.

How can I enable it for MainGenericRunner?

1: Feel free to test the REPL:

git clone https://github.com/rtreffer/minidns.git \
  && cd minidns \
  && ./repl`

Then perform a DNS query, e.g. c.query("wikipedia.org", TYPE.A)


Solution

  • Although current scala repl has autocompletion feature right now it is not working very well. (that's aside the issue mentioned by som-snytt).

    If you need the working completions in repl you best bet would be Ammonite REPL which also has some more features then the standard repl.

    NOTE: I haven't tested tab completions in 2.11.8, but it looks like they had been rewritten from scratch and are looking very promising.