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 ++- test/junit/scala/tools/nsc/interpreter/CompletionTest.scala | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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)) ) diff --git a/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala b/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala index 78ebb7cf9c..7c37be126d 100644 --- a/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala +++ b/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala @@ -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) } -- cgit v1.2.3 From 9bf28eedc435e0fa79b1b5db441ae2326f23cc32 Mon Sep 17 00:00:00 2001 From: Stefan Zeiger Date: Mon, 28 Nov 2016 20:07:28 +0100 Subject: Use https links to JS and CSS in the spec when serving from https The spec is published on a server that supports https (https://www.scala-lang.org/files/archive/spec/2.11/) and this comes up as the default in search results (as it should) but the link to MathJAX is hardcoded to http, which prevents any web browser that cares about security from loading it. This commit changes the links to MathJAX and to the Highlight.js stylesheet to be scheme-relative (like the link to JQuery already was). --- spec/_layouts/default.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/_layouts/default.yml b/spec/_layouts/default.yml index 69791d26ad..d41d045311 100644 --- a/spec/_layouts/default.yml +++ b/spec/_layouts/default.yml @@ -15,9 +15,9 @@ } }); - + - +