summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-09-24 13:22:29 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-09-24 14:33:19 +1000
commit2c9e506bc32248f9ae4929790a0cb7484a53a66e (patch)
tree67ed4da07b4ad128803bf4bfa5b253fad0417b42
parenta6c1687aa762bc8317fe4995ec1b26bed64865e8 (diff)
downloadscala-2c9e506bc32248f9ae4929790a0cb7484a53a66e.tar.gz
scala-2c9e506bc32248f9ae4929790a0cb7484a53a66e.tar.bz2
scala-2c9e506bc32248f9ae4929790a0cb7484a53a66e.zip
Support completion in erroneous string interpolation.
In the code: ``` s"${fooo<CURSOR" ``` The parser treats `fooo` as a interpolator ID for the quote that we actually intend to end the interpolated string. Inserting a space (in addition to `__CURSOR__` that we already patch in to avoid parsing a partial identifier as a keyword), solves this problem.
-rw-r--r--src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala2
-rw-r--r--test/junit/scala/tools/nsc/interpreter/CompletionTest.scala8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala b/src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala
index 0fb3236966..4b0330aaf7 100644
--- a/src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala
+++ b/src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala
@@ -36,7 +36,7 @@ class PresentationCompilerCompleter(intp: IMain) extends Completion with ScalaCo
// secret handshakes
val slashPrint = """.*// *print *""".r
val slashTypeAt = """.*// *typeAt *(\d+) *(\d+) *""".r
- val Cursor = IMain.DummyCursorFragment
+ val Cursor = IMain.DummyCursorFragment + " "
def print(result: Result) = {
val offset = result.preambleLength
diff --git a/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala b/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala
index 514f30571e..d00a9bf69a 100644
--- a/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala
+++ b/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala
@@ -52,6 +52,14 @@ class CompletionTest {
}
@Test
+ def incompleteStringInterpolation(): Unit = {
+ val intp = newIMain()
+ val completer = new PresentationCompilerCompleter(intp)
+ checkExact(completer, """val x_y_z = 1; s"${x_""", "}\"")("x_y_z")
+ checkExact(completer, """val x_y_z = 1; s"${x_""", "\"")("x_y_z")
+ }
+
+ @Test
def symbolically(): Unit = {
val intp = newIMain()
val completer = new PresentationCompilerCompleter(intp)