diff options
author | Paul Phillips <paulp@improving.org> | 2009-04-07 18:12:28 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-04-07 18:12:28 +0000 |
commit | 339cbf16da2fc92f88274b5f7b5183e4647a17f2 (patch) | |
tree | afda7d8b1c1555295f4b5bc0f7214fc09fb51ebf /src/compiler | |
parent | 150d137d20e6e6e89978be097aaf1bc1e7fc2129 (diff) | |
download | scala-339cbf16da2fc92f88274b5f7b5183e4647a17f2.tar.gz scala-339cbf16da2fc92f88274b5f7b5183e4647a17f2.tar.bz2 scala-339cbf16da2fc92f88274b5f7b5183e4647a17f2.zip |
Expanded set of completion delimiters; filter o...
Expanded set of completion delimiters; filter out private members.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/Interpreter.scala | 23 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/JLineReader.scala | 7 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 01071c1981..4342f96a74 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -848,17 +848,27 @@ class Interpreter(val settings: Settings, out: PrintWriter) { None } + // XXX at the moment this is imperfect because scala's protected semantics + // differ from java's, so protected methods appear public via reflection; + // yet scala enforces the protection. The result is that protected members + // appear in completion yet cannot actually be called. Fixing this + // properly requires a scala.reflect.* API. Fixing it uglily is possible + // too (cast to structural type!) but I deem poor use of energy. + private val filterFlags: Int = { + import java.lang.reflect.Modifier._ + STATIC | PRIVATE | PROTECTED + } + private val methodsCode = """ . + | asInstanceOf[AnyRef].getClass.getMethods . + | filter(x => (x.getModifiers & %d) == 0) . + | map(_.getName) . + | mkString(" ")""".stripMargin.format(filterFlags) + /** The main entry point for tab-completion. When the user types x.<tab> * this method is called with "x" as an argument, and it discovers the * fields and methods of x via reflection and returns their names to jline. */ def membersOfIdentifier(line: String): List[String] = { - val methodsCode = """ . - | asInstanceOf[AnyRef].getClass.getMethods . - | filter(x => !java.lang.reflect.Modifier.isStatic(x.getModifiers)) . - | map(_.getName) . - | mkString(" ")""".stripMargin - val filterMethods = List("", "hashCode", "equals", "wait", "notify", "notifyAll") val res = beQuietDuring { for (name <- nameOfIdent(line) ; req <- requestForName(name)) yield { @@ -880,6 +890,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) { res getOrElse Nil } + /** Another entry point for tab-completion, ids in scope */ def unqualifiedIds(line: String): List[String] = allBoundNames . map(_.toString) . diff --git a/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala b/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala index 0e66a8b06a..0e9d494206 100644 --- a/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala +++ b/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala @@ -24,7 +24,12 @@ class JLineReader(interpreter: Interpreter) extends InteractiveReader { r setBellEnabled false if (interpreter != null) { - val comp = new ArgumentCompletor(new Completion(interpreter)) + // have to specify all delimiters for completion to work nicely + val delims = new ArgumentCompletor.AbstractArgumentDelimiter { + val delimChars = "(){}[],`;'\" \t".toArray + def isDelimiterChar(s: String, pos: Int) = delimChars contains s.charAt(pos) + } + val comp = new ArgumentCompletor(new Completion(interpreter), delims) comp setStrict false r addCompletor comp } |