You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2020/11/04 01:50:19 UTC

[zeppelin] branch master updated: [ZEPPELIN-5113]. Cursor of code completion is incorrect in some cases

This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/master by this push:
     new 234d236  [ZEPPELIN-5113]. Cursor of code completion is incorrect in some cases
234d236 is described below

commit 234d236803535d830484429f5ccc5c4633558e70
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Wed Oct 28 16:40:05 2020 +0800

    [ZEPPELIN-5113]. Cursor of code completion is incorrect in some cases
    
    ### What is this PR for?
    
    The cursor of code completion is incorrect in some cases, this cause the code completion broken in some cases.
    
    e.g.
    ```
    %spark.pyspark
    
    spark.
    ```
    
    This PR fix the issue by find the right cursor starting after the interpreter text.
    
    ### What type of PR is it?
    [Bug Fix ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5113
    
    ### How should this be tested?
    * Unit test is added and also manually tested.
    https://travis-ci.org/github/zjffdu/zeppelin/builds/739546111
    
    ### 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 <zj...@apache.org>
    
    Closes #3956 from zjffdu/ZEPPELIN-5113 and squashes the following commits:
    
    161fe1553 [Jeff Zhang] [ZEPPELIN-5113]. Cursor of code completion is incorrect in some cases
---
 .../org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java    | 5 +++++
 .../src/main/java/org/apache/zeppelin/notebook/Paragraph.java        | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java
index 3a16670..e1c2931 100644
--- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java
+++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java
@@ -431,6 +431,11 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi {
       assertEquals(Status.FINISHED, p.getStatus());
       assertEquals("name_abc\n", p.getReturn().message().get(0).getData());
 
+      // test code completion
+      String code = "%spark.pyspark spark.";
+      List<InterpreterCompletion> completions = note.completion(p.getId(), code, code.length(), AuthenticationInfo.ANONYMOUS);
+      assertTrue(completions.size() > 0);
+
       if (isSpark1()) {
         // run sqlContext test
         p = note.addNewParagraph(anonymous);
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
index 1938298..66535ff 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
@@ -288,7 +288,10 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
     if (this.scriptText.isEmpty()) {
       return 0;
     }
-    int countCharactersBeforeScript = buffer.indexOf(this.scriptText);
+    // Try to find the right cursor from this startPos, otherwise you may get the wrong cursor.
+    // e.g.  %spark.pyspark  spark.
+    int startPos = this.intpText == null ? 0 : this.intpText.length();
+    int countCharactersBeforeScript = buffer.indexOf(this.scriptText, startPos);
     if (countCharactersBeforeScript > 0) {
       cursor -= countCharactersBeforeScript;
     }