From 76155fa4e9ef103de4b8283097f6cde18c6f1e08 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 22 Nov 2016 21:06:40 +1000 Subject: Improve performance of REPL autocompletion The code used to fuzzily match, e.g, `declasses` with `getDeclaredClasses` was exploring fruitless parts of the search space. The enclosed test case was hanging the REPL. This commit improves this by performing a prefix match of the unconsumed input against the current chunk of the candidate before exploring the `inits`. Fixes scala/scala-dev#271 --- src/interactive/scala/tools/nsc/interactive/Global.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/interactive/scala/tools') diff --git a/src/interactive/scala/tools/nsc/interactive/Global.scala b/src/interactive/scala/tools/nsc/interactive/Global.scala index 27a02c46a2..5c00d67888 100644 --- a/src/interactive/scala/tools/nsc/interactive/Global.scala +++ b/src/interactive/scala/tools/nsc/interactive/Global.scala @@ -1202,7 +1202,8 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") case Nil => entered.isEmpty && matchCount > 0 case head :: tail => val enteredAlternatives = Set(entered, entered.capitalize) - head.inits.filter(_.length <= entered.length).exists(init => + val n = (head, entered).zipped.count {case (c, e) => c == e || (c.isUpper && c == e.toUpper)} + head.take(n).inits.exists(init => enteredAlternatives.exists(entered => lenientMatch(entered.stripPrefix(init), tail, matchCount + (if (init.isEmpty) 0 else 1)) ) -- cgit v1.2.3