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 2018/01/13 08:15:02 UTC
zeppelin git commit: ZEPPELIN-3136. IPython Code Completion
Improvement
Repository: zeppelin
Updated Branches:
refs/heads/master 346981b67 -> 7af4fab42
ZEPPELIN-3136. IPython Code Completion Improvement
### What is this PR for?
This is for better code completion support for IPythonInterpreter
### What type of PR is it?
[Improvement ]
### Todos
* [ ] - Task
### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-3136
### How should this be tested?
* Unit test is updated and Manually verified.
### 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 #2725 from zjffdu/ZEPPELIN-3136 and squashes the following commits:
1179fc8 [Jeff Zhang] ZPEPELIN-3136. IPython Code Completion Improvement
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/7af4fab4
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/7af4fab4
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/7af4fab4
Branch: refs/heads/master
Commit: 7af4fab420ed42edbe9f97c1c4d63823ff321c2d
Parents: 346981b
Author: Jeff Zhang <zj...@apache.org>
Authored: Fri Jan 12 11:45:16 2018 +0800
Committer: Jeff Zhang <zj...@apache.org>
Committed: Sat Jan 13 16:14:55 2018 +0800
----------------------------------------------------------------------
.../org/apache/zeppelin/python/IPythonInterpreter.java | 9 +++++++--
.../apache/zeppelin/python/IPythonInterpreterTest.java | 10 +++++-----
.../apache/zeppelin/spark/IPySparkInterpreterTest.java | 2 +-
3 files changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/7af4fab4/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
----------------------------------------------------------------------
diff --git a/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java b/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
index 2184c1f..5ae03f0 100644
--- a/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
+++ b/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
@@ -336,14 +336,19 @@ public class IPythonInterpreter extends Interpreter implements ExecuteResultHand
@Override
public List<InterpreterCompletion> completion(String buf, int cursor,
InterpreterContext interpreterContext) {
+ LOGGER.debug("Call completion for: " + buf);
List<InterpreterCompletion> completions = new ArrayList<>();
CompletionResponse response =
ipythonClient.complete(
CompletionRequest.getDefaultInstance().newBuilder().setCode(buf)
.setCursor(cursor).build());
for (int i = 0; i < response.getMatchesCount(); i++) {
- completions.add(new InterpreterCompletion(
- response.getMatches(i), response.getMatches(i), ""));
+ String match = response.getMatches(i);
+ int lastIndexOfDot = match.lastIndexOf(".");
+ if (lastIndexOfDot != -1) {
+ match = match.substring(lastIndexOfDot + 1);
+ }
+ completions.add(new InterpreterCompletion(match, match, ""));
}
return completions;
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/7af4fab4/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
----------------------------------------------------------------------
diff --git a/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java b/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
index 6451aa3..d89ddac 100644
--- a/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
@@ -196,9 +196,9 @@ public class IPythonInterpreterTest {
context = getInterpreterContext();
completions = interpreter.completion("sys.std", 7, context);
assertEquals(3, completions.size());
- assertEquals("sys.stderr", completions.get(0).getValue());
- assertEquals("sys.stdin", completions.get(1).getValue());
- assertEquals("sys.stdout", completions.get(2).getValue());
+ assertEquals("stderr", completions.get(0).getValue());
+ assertEquals("stdin", completions.get(1).getValue());
+ assertEquals("stdout", completions.get(2).getValue());
// there's no completion for 'a.' because it is not recognized by compiler for now.
context = getInterpreterContext();
@@ -227,14 +227,14 @@ public class IPythonInterpreterTest {
st = "a.co";
completions = interpreter.completion(st, st.length(), context);
assertEquals(1, completions.size());
- assertEquals("a.count", completions.get(0).getValue());
+ assertEquals("count", completions.get(0).getValue());
// cursor is in the middle of code
context = getInterpreterContext();
st = "a.co\b='hello";
completions = interpreter.completion(st, 4, context);
assertEquals(1, completions.size());
- assertEquals("a.count", completions.get(0).getValue());
+ assertEquals("count", completions.get(0).getValue());
// ipython help
context = getInterpreterContext();
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/7af4fab4/spark/src/test/java/org/apache/zeppelin/spark/IPySparkInterpreterTest.java
----------------------------------------------------------------------
diff --git a/spark/src/test/java/org/apache/zeppelin/spark/IPySparkInterpreterTest.java b/spark/src/test/java/org/apache/zeppelin/spark/IPySparkInterpreterTest.java
index 5492274..d2b01ce 100644
--- a/spark/src/test/java/org/apache/zeppelin/spark/IPySparkInterpreterTest.java
+++ b/spark/src/test/java/org/apache/zeppelin/spark/IPySparkInterpreterTest.java
@@ -162,7 +162,7 @@ public class IPySparkInterpreterTest {
// completions
List<InterpreterCompletion> completions = iPySparkInterpreter.completion("sc.ran", 6, getInterpreterContext());
assertEquals(1, completions.size());
- assertEquals("sc.range", completions.get(0).getValue());
+ assertEquals("range", completions.get(0).getValue());
// pyspark streaming
context = getInterpreterContext();