Skip to content

Commit

Permalink
Merge pull request #5553 from retronym/ticket/SD-271
Browse files Browse the repository at this point in the history
Improve performance of REPL autocompletion
  • Loading branch information
retronym committed Nov 29, 2016
2 parents 73687e9 + 76155fa commit 57290a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/interactive/scala/tools/nsc/interactive/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
Expand Down
8 changes: 8 additions & 0 deletions test/junit/scala/tools/nsc/interpreter/CompletionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ class CompletionTest {
checkExact(completer, "case class D(a: Int, b: Int) { this.a")("a", "asInstanceOf")
}

@Test
def performanceOfLenientMatch(): Unit = {
val intp = newIMain()
val completer = new PresentationCompilerCompleter(intp)
val ident: String = "thisIsAReallyLongMethodNameWithManyManyManyManyChunks"
checkExact(completer, s"($ident: Int) => tia")(ident)
}

def checkExact(completer: PresentationCompilerCompleter, before: String, after: String = "")(expected: String*): Unit = {
assertEquals(expected.toSet, completer.complete(before, after).candidates.toSet)
}
Expand Down

0 comments on commit 57290a1

Please sign in to comment.