From 804a4cc1ff9fa159c576be7c685dbb81220c11da Mon Sep 17 00:00:00 2001 From: som-snytt Date: Fri, 15 Apr 2016 01:28:18 -0700 Subject: SI-9749 REPL strip lead ws on dot continuation (#5097) Permit leading whitespace before `.` for continued selection. This is just to handle pastes, which will typically include indented text, and not to make dot-continuation especially robust. --- src/repl/scala/tools/nsc/interpreter/Completion.scala | 14 +++++++------- test/files/run/t9749-repl-dot.check | 8 ++++++++ test/files/run/t9749-repl-dot.scala | 10 ++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 test/files/run/t9749-repl-dot.check create mode 100644 test/files/run/t9749-repl-dot.scala diff --git a/src/repl/scala/tools/nsc/interpreter/Completion.scala b/src/repl/scala/tools/nsc/interpreter/Completion.scala index 3d0b9a975c..6f5194d2f9 100644 --- a/src/repl/scala/tools/nsc/interpreter/Completion.scala +++ b/src/repl/scala/tools/nsc/interpreter/Completion.scala @@ -24,11 +24,11 @@ object Completion { case class Candidates(cursor: Int, candidates: List[String]) { } val NoCandidates = Candidates(-1, Nil) - def looksLikeInvocation(code: String) = ( - (code != null) - && (code startsWith ".") - && !(code == ".") - && !(code startsWith "./") - && !(code startsWith "..") - ) + // a leading dot plus something, but not ".." or "./", ignoring leading whitespace + private val dotlike = """\s*\.[^./].*""".r + def looksLikeInvocation(code: String) = code match { + case null => false // insurance + case dotlike() => true + case _ => false + } } diff --git a/test/files/run/t9749-repl-dot.check b/test/files/run/t9749-repl-dot.check new file mode 100644 index 0000000000..5ffec4ce60 --- /dev/null +++ b/test/files/run/t9749-repl-dot.check @@ -0,0 +1,8 @@ + +scala> "3" +res0: String = 3 + +scala> .toInt +res1: Int = 3 + +scala> :quit diff --git a/test/files/run/t9749-repl-dot.scala b/test/files/run/t9749-repl-dot.scala new file mode 100644 index 0000000000..19cecbf444 --- /dev/null +++ b/test/files/run/t9749-repl-dot.scala @@ -0,0 +1,10 @@ + +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = + """ +"3" + .toInt + """ +} -- cgit v1.2.3