From 30f779b4d9b699800e323eeba31cf04c16b4fbcd Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Tue, 3 Dec 2013 16:38:55 -0800 Subject: SI-8027 REPL double tab regression Where did double tab go? "The shadow knows." The regression was introduced by the last flurry before we were left to wallow in whatever white space remained. Some xs put other xs under erasure. It's clear that somebody's daughter walked into the room and asked for a story, because, shockingly, the case arrows don't line up. We need a plug-in for Jenkins, or I guess Travis, to fail the build if arrows and equals don't align, because it clearly indicates a lapse of some kind. --- src/reflect/scala/reflect/internal/util/StringOps.scala | 16 ++++++++++------ .../scala/tools/nsc/interpreter/JLineCompletion.scala | 5 ++--- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/internal/util/StringOps.scala b/src/reflect/scala/reflect/internal/util/StringOps.scala index 14f349f502..efb8126ff0 100644 --- a/src/reflect/scala/reflect/internal/util/StringOps.scala +++ b/src/reflect/scala/reflect/internal/util/StringOps.scala @@ -23,12 +23,16 @@ trait StringOps { def oempty(xs: String*) = xs filterNot (x => x == null || x == "") def ojoin(xs: String*): String = oempty(xs: _*) mkString " " def longestCommonPrefix(xs: List[String]): String = xs match { - case Nil => "" - case xs if xs contains "" => "" - case x :: xs => - val ch = x charAt 0 - if (xs exists (_.head != ch)) "" - else "" + ch + longestCommonPrefix(xs map (_ substring 1)) + case Nil => "" + case w :: Nil => w + case _ => + def lcp(ss: List[String]): String = { + val w :: ws = ss + if (w == "") "" + else if (ws exists (s => s == "" || (s charAt 0) != (w charAt 0))) "" + else w.substring(0, 1) + lcp(ss map (_ substring 1)) + } + lcp(xs) } /** Like String#trim, but trailing whitespace only. */ diff --git a/src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala b/src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala index 1b3d60d41a..53c7c82e89 100644 --- a/src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala +++ b/src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala @@ -294,7 +294,7 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput // This is jline's entry point for completion. override def complete(buf: String, cursor: Int): Candidates = { verbosity = if (isConsecutiveTabs(buf, cursor)) verbosity + 1 else 0 - repldbg("\ncomplete(%s, %d) last = (%s, %d), verbosity: %s".format(buf, cursor, lastBuf, lastCursor, verbosity)) + repldbg(f"%ncomplete($buf, $cursor%d) last = ($lastBuf, $lastCursor%d), verbosity: $verbosity") // we don't try lower priority completions unless higher ones return no results. def tryCompletion(p: Parsed, completionFunction: Parsed => List[String]): Option[Candidates] = { @@ -307,8 +307,7 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput val advance = longestCommonPrefix(winners) lastCursor = p.position + advance.length lastBuf = (buf take p.position) + advance - repldbg("tryCompletion(%s, _) lastBuf = %s, lastCursor = %s, p.position = %s".format( - p, lastBuf, lastCursor, p.position)) + repldbg(s"tryCompletion($p, _) lastBuf = $lastBuf, lastCursor = $lastCursor, p.position = ${p.position}") p.position } -- cgit v1.2.3