Repository: zeppelin
Updated Branches:
  refs/heads/master 6bb4b5ba8 -> 73f258ca7


[ZEPPELIN-1086] Auto Completion for Interpreter.

### What is this PR for?
This PR is to support auto-completion for interpreter.

### What type of PR is it?
Improvement

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1086

### How should this be tested?
Type ```% + 'Ctrl+.' ``` in your paragraph.
please refer to screen shot.

### Screenshots (if appropriate)
![o](https://cloud.githubusercontent.com/assets/3348133/16543637/a84a0f70-4119-11e6-9790-d5b3913fe536.gif)

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: astroshim <[email protected]>

Closes #1117 from astroshim/ZEPPELIN-1086 and squashes the following commits:

bca1e7d [astroshim] Merge branch 'master' into ZEPPELIN-1086
3d40d22 [astroshim] remove blank line
349403b [astroshim] fix bug and add interpreter info to completion
b3731e5 [astroshim] Merge branch 'master' into ZEPPELIN-1086
268d8e4 [astroshim] rebase
aabdf48 [astroshim] Merge branch 'master' into ZEPPELIN-1086
ce16585 [astroshim] remove bodyCursor
08cc5e5 [astroshim] fix cursor value
4f16112 [astroshim] fix cursor position


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

Branch: refs/heads/master
Commit: 73f258ca7fffffbd0f72bb073acacf4657f518e6
Parents: 6bb4b5b
Author: astroshim <[email protected]>
Authored: Thu Jul 14 22:34:23 2016 +0900
Committer: Alexander Bezzubov <[email protected]>
Committed: Fri Jul 22 18:16:57 2016 +0900

----------------------------------------------------------------------
 .../org/apache/zeppelin/notebook/Paragraph.java | 29 +++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/73f258ca/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
----------------------------------------------------------------------
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 7317406..561d84b 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
@@ -24,7 +24,6 @@ import 
org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
 import org.apache.zeppelin.user.AuthenticationInfo;
 import org.apache.zeppelin.user.Credentials;
 import org.apache.zeppelin.user.UserCredentials;
-import org.apache.zeppelin.user.UsernamePassword;
 import org.apache.zeppelin.display.GUI;
 import org.apache.zeppelin.display.Input;
 import org.apache.zeppelin.interpreter.*;
@@ -209,11 +208,39 @@ public class Paragraph extends Job implements 
Serializable, Cloneable {
     return getRepl(getRequiredReplName());
   }
 
+  public List<InterpreterCompletion> getInterpreterCompletion() {
+    List<InterpreterCompletion> completion = new LinkedList();
+    for (InterpreterSetting intp: 
factory.getInterpreterSettings(note.getId())){
+      List<InterpreterSetting.InterpreterInfo> intInfo = 
intp.getInterpreterInfos();
+      if (intInfo.size() > 1) {
+        for (InterpreterSetting.InterpreterInfo info : intInfo){
+          String name = intp.getGroup() + "." + info.getName();
+          completion.add(new InterpreterCompletion(name, name));
+        }
+      } else {
+        completion.add(new InterpreterCompletion(intp.getGroup(), 
intp.getGroup()));
+      }
+    }
+    return completion;
+  }
+
   public List<InterpreterCompletion> completion(String buffer, int cursor) {
+    String lines[] = buffer.split(System.getProperty("line.separator"));
+    if (lines.length > 0
+      && lines[0].startsWith("%")
+      && cursor <= lines[0].trim().length()) {
+
+      int idx = lines[0].indexOf(' ');
+      if (idx < 0 || (idx > 0 && cursor <= idx)) {
+        return getInterpreterCompletion();
+      }
+    }
+
     String replName = getRequiredReplName(buffer);
     if (replName != null && cursor > replName.length()) {
       cursor -= replName.length() + 1;
     }
+
     String body = getScriptBody(buffer);
     Interpreter repl = getRepl(replName);
     if (repl == null) {

Reply via email to