summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-04-07 17:20:15 +0000
committerPaul Phillips <paulp@improving.org>2009-04-07 17:20:15 +0000
commit150d137d20e6e6e89978be097aaf1bc1e7fc2129 (patch)
treefa76cc40f84f3da436324dc305a35c6632b838ff /src/compiler
parentbecf900b40e9201e6ab256ace7592d3d53c933ea (diff)
downloadscala-150d137d20e6e6e89978be097aaf1bc1e7fc2129.tar.gz
scala-150d137d20e6e6e89978be097aaf1bc1e7fc2129.tar.bz2
scala-150d137d20e6e6e89978be097aaf1bc1e7fc2129.zip
Improvements to repl completion.
(it was only behind an option to be super conservative) but it can be disabled with -Yno-completion. Now all top level identifiers can be completed upon, so if you define val dingdong = "abc" def dingwhoa = 5 then d.<tab> will complete up to "ding".
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala7
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterLoop.scala9
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Completion.scala22
4 files changed, 29 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 78ac10b021..01071c1981 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -828,7 +828,6 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
}
"""** Power User mode enabled - BEEP BOOP **
- |** Launch scala with -Ycompletion for <tab> **
|** New vals! Try interpreter.<tab> **
|** New defs! Try mkType("T", "String") **
|** New cmds! :help to discover them **""".stripMargin
@@ -881,6 +880,12 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
res getOrElse Nil
}
+ def unqualifiedIds(line: String): List[String] =
+ allBoundNames .
+ map(_.toString) .
+ filter(!isSynthVarName(_)) .
+ filter(_ startsWith line)
+
// debugging
private var debuggingOutput = false
def DBG(s: String) = if (debuggingOutput) out println s else ()
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
index 52097e0ebf..944a978ec7 100644
--- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
@@ -207,7 +207,8 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
*/
val futLine = scala.concurrent.ops.future(readOneLine)
bindSettings()
- processLine(futLine())
+ if (!processLine(futLine()))
+ return out.println("Leaving already? That hurts, it really does.")
// loops until false, then returns
while (processLine(readOneLine)) { }
@@ -331,10 +332,10 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
case None =>
val emacsShell = System.getProperty("env.emacs", "") != ""
- // tab completion off by default for now
+ // the interpeter is passed as an argument to expose tab completion info
if (settings.Xnojline.value || emacsShell) new SimpleReader
- else if (settings.completion.value) InteractiveReader.createDefault(interpreter)
- else InteractiveReader.createDefault()
+ else if (settings.noCompletion.value) InteractiveReader.createDefault()
+ else InteractiveReader.createDefault(interpreter)
}
loadFiles(settings)
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 6026186010..a05a6dd157 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -651,7 +651,7 @@ trait ScalacSettings
val check = PhasesSetting ("-Ycheck", "Check the tree at the end of")
val Xcloselim = BooleanSetting ("-Yclosure-elim", "Perform closure elimination")
val Xcodebase = StringSetting ("-Ycodebase", "codebase", "Specify the URL containing the Scala libraries", "")
- val completion = BooleanSetting ("-Ycompletion", "Enable tab-completion in the REPL")
+ val noCompletion = BooleanSetting ("-Yno-completion", "Disable tab-completion in the REPL")
val Xdce = BooleanSetting ("-Ydead-code", "Perform dead code elimination")
val debug = BooleanSetting ("-Ydebug", "Output debugging messages")
val debugger = BooleanSetting ("-Ydebugger", "Enable interactive debugger")
diff --git a/src/compiler/scala/tools/nsc/interpreter/Completion.scala b/src/compiler/scala/tools/nsc/interpreter/Completion.scala
index 7e2c8a9f04..cf804f4669 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Completion.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Completion.scala
@@ -13,16 +13,28 @@ import jline._
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
+ override def complete(_buffer: String, cursor: Int, candidates: JList[_]): Int = {
+ val buffer = if (_buffer == null) "" else _buffer
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
+ def completeMembers(needsDot: Boolean): Int = {
+ def withDot(s: String) = if (needsDot) "." + s else s
+ val members = interpreter membersOfIdentifier path
+ members.filter(_ startsWith stub).foreach(x => clist add withDot(x))
+ buffer.length - stub.length
+ }
+
+ // if there is no dot, complete on unqualified identifiers; otherwise, id's members
+ lazy val ids = interpreter unqualifiedIds path
+ if (lastDot >= 0) completeMembers(false)
+ else ids match {
+ case Nil => 0
+ case x :: Nil if x == path => completeMembers(true) // only one id matches, insert the dot
+ case xs => xs foreach (x => clist add x) ; 0
+ }
}
}