From 7719a3cc908464d34d602a7a5a23e943059bb714 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 10 Sep 2015 16:24:26 +1000 Subject: Workaround JLine bug for mid-line tab completion Before: ``` scala> {" ".char} charAt chars scala> {" ".char}} ``` I noticed that pressing - re-rendered the line correctly, so I've added this workaround to our customization of the JLine console reader. After: ``` scala> {" ".char} charAt chars scala> {" ".char} ``` We can delete this workaround when JLine 2.13.1 is released, but I haven't heard back about when this might happen. --- .../tools/nsc/interpreter/jline/JLineReader.scala | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala index 5082c99a76..b5db4c2098 100644 --- a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala +++ b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala @@ -10,7 +10,8 @@ package scala.tools.nsc.interpreter.jline import java.util.{Collection => JCollection, List => JList} import _root_.jline.{console => jconsole} -import jconsole.completer.{Completer, ArgumentCompleter} +import jline.console.ConsoleReader +import jline.console.completer.{CompletionHandler, Completer, ArgumentCompleter} import jconsole.history.{History => JHistory} @@ -142,6 +143,27 @@ private class JLineConsoleReader extends jconsole.ConsoleReader with interpreter case NoCompletion => () case _ => this addCompleter completer } + + // This is a workaround for https://github.com/jline/jline2/issues/208 + // and should not be necessary once we upgrade to JLine 2.13.1 + /// + // Test by: + // scala> {" ".char} + // + // And checking we don't get an extra } on the line. + /// + val handler = getCompletionHandler + setCompletionHandler(new CompletionHandler { + override def complete(consoleReader: ConsoleReader, list: JList[CharSequence], i: Int): Boolean = { + try { + handler.complete(consoleReader, list, i) + } finally if (getCursorBuffer.cursor != getCursorBuffer.length()) { + print(" ") + getCursorBuffer.write(' ') + backspace() + } + } + }) setAutoprintThreshold(400) // max completion candidates without warning } } -- cgit v1.2.3