Repository: zeppelin Updated Branches: refs/heads/master 14534da9e -> de17d2b87
ZEPPELIN-3858. Code completion doesn't work for spark interpreter when cursor is in the middle of code ### What is this PR for? It is a trivial fix for the code completion of spark interpreter when the cursor is in the middle of code. ### What type of PR is it? [Bug Fix] ### Todos * [ ] - Task ### What is the Jira issue? * https://jira.apache.org/jira/browse/ZEPPELIN-3858 ### How should this be tested? * CI pass ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Jeff Zhang <zjf...@apache.org> Closes #3221 from zjffdu/ZEPPELIN-3858 and squashes the following commits: bb56b723e [Jeff Zhang] ZEPPELIN-3858. Code completion doesn't work for spark interpreter when cursor is in the middle of code Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/de17d2b8 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/de17d2b8 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/de17d2b8 Branch: refs/heads/master Commit: de17d2b8758d9ce83beb1e3e54645de4d831ea1f Parents: 14534da Author: Jeff Zhang <zjf...@apache.org> Authored: Fri Nov 9 17:25:04 2018 +0800 Committer: Jeff Zhang <zjf...@apache.org> Committed: Tue Nov 13 09:27:18 2018 +0800 ---------------------------------------------------------------------- .../java/org/apache/zeppelin/spark/NewSparkInterpreterTest.java | 4 ++++ .../org/apache/zeppelin/spark/BaseSparkScalaInterpreter.scala | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/de17d2b8/spark/interpreter/src/test/java/org/apache/zeppelin/spark/NewSparkInterpreterTest.java ---------------------------------------------------------------------- diff --git a/spark/interpreter/src/test/java/org/apache/zeppelin/spark/NewSparkInterpreterTest.java b/spark/interpreter/src/test/java/org/apache/zeppelin/spark/NewSparkInterpreterTest.java index 82727a1..d69b2f9 100644 --- a/spark/interpreter/src/test/java/org/apache/zeppelin/spark/NewSparkInterpreterTest.java +++ b/spark/interpreter/src/test/java/org/apache/zeppelin/spark/NewSparkInterpreterTest.java @@ -290,6 +290,10 @@ public class NewSparkInterpreterTest { assertEquals(1, completions.size()); assertEquals("range", completions.get(0).name); + // cursor in middle of code + completions = interpreter.completion("sc.ra\n1+1", 5, getInterpreterContext()); + assertEquals(1, completions.size()); + assertEquals("range", completions.get(0).name); // Zeppelin-Display result = interpreter.interpret("import org.apache.zeppelin.display.angular.notebookscope._\n" + http://git-wip-us.apache.org/repos/asf/zeppelin/blob/de17d2b8/spark/spark-scala-parent/src/main/scala/org/apache/zeppelin/spark/BaseSparkScalaInterpreter.scala ---------------------------------------------------------------------- diff --git a/spark/spark-scala-parent/src/main/scala/org/apache/zeppelin/spark/BaseSparkScalaInterpreter.scala b/spark/spark-scala-parent/src/main/scala/org/apache/zeppelin/spark/BaseSparkScalaInterpreter.scala index 0f36c88..183dee6 100644 --- a/spark/spark-scala-parent/src/main/scala/org/apache/zeppelin/spark/BaseSparkScalaInterpreter.scala +++ b/spark/spark-scala-parent/src/main/scala/org/apache/zeppelin/spark/BaseSparkScalaInterpreter.scala @@ -138,7 +138,7 @@ abstract class BaseSparkScalaInterpreter(val conf: SparkConf, protected def completion(buf: String, cursor: Int, context: InterpreterContext): java.util.List[InterpreterCompletion] = { - val completions = scalaCompleter.complete(buf, cursor).candidates + val completions = scalaCompleter.complete(buf.substring(0, cursor), cursor).candidates .map(e => new InterpreterCompletion(e, e, null)) scala.collection.JavaConversions.seqAsJavaList(completions) }