summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/interpreter/Completion.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-03-05 19:33:14 +0000
committerPaul Phillips <paulp@improving.org>2009-03-05 19:33:14 +0000
commit9bedaaa81711cf077437d2868442431b1b15ee8d (patch)
tree21ead30ccb233813d20031d825152b8ab6eb5808 /src/compiler/scala/tools/nsc/interpreter/Completion.scala
parent276ed222116522b4966c36f38df70a10131dde0d (diff)
downloadscala-9bedaaa81711cf077437d2868442431b1b15ee8d.tar.gz
scala-9bedaaa81711cf077437d2868442431b1b15ee8d.tar.bz2
scala-9bedaaa81711cf077437d2868442431b1b15ee8d.zip
Another big Interpreter patch, this one mostly ...
Another big Interpreter patch, this one mostly attacking InterpreterLoop. This adds opening cuts of a number of features: tab completion for repl identifiers (requires using -Ycompletion for now), a :power repl command that enables power user commands, and more. I'll document it properly once it's a bit less experimental.
Diffstat (limited to 'src/compiler/scala/tools/nsc/interpreter/Completion.scala')
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Completion.scala28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/Completion.scala b/src/compiler/scala/tools/nsc/interpreter/Completion.scala
new file mode 100644
index 0000000000..7e2c8a9f04
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/interpreter/Completion.scala
@@ -0,0 +1,28 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2009 LAMP/EPFL
+ * @author Paul Phillips
+ */
+// $Id$
+
+package scala.tools.nsc.interpreter
+
+import jline._
+
+// REPL completor - queries supplied interpreter for valid completions
+// based on current contents of buffer.
+class Completion(val interpreter: Interpreter) extends Completor {
+ import java.util.{ List => JList }
+
+ override def complete(buffer: String, cursor: Int, candidates: JList[_]): Int = {
+ if (buffer == null) return 0
+ val clist = candidates.asInstanceOf[JList[String]]
+ val lastDot = buffer.lastIndexOf('.')
+ val (path, stub) =
+ if (lastDot < 0) (buffer, "")
+ else (buffer.substring(0, lastDot), buffer.substring(lastDot + 1))
+
+ val members = interpreter membersOfIdentifier path
+ members.filter(_ startsWith stub).foreach(x => clist add x)
+ buffer.length - stub.length
+ }
+}