Repository: zeppelin
Updated Branches:
  refs/heads/branch-0.8 4cf07f7a8 -> 9721d174a


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

(cherry picked from commit de17d2b8758d9ce83beb1e3e54645de4d831ea1f)
Signed-off-by: Jeff Zhang <zjf...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/9721d174
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/9721d174
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/9721d174

Branch: refs/heads/branch-0.8
Commit: 9721d174a206369c91c684692bc67ab066d3d8c1
Parents: 4cf07f7
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:31 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/9721d174/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 05bb659..a3e4d22 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
@@ -279,6 +279,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/9721d174/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 a9b5304..7fcf6e8 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)
   }

Reply via email to