ZEPPELIN-3001: Disable ace editor code completion when back-end interpreter support completion

Change-Id: I315ff17c6f50ad3ad912a38366833823e5241574
This commit is contained in:
Prabhjyot Singh 2018-03-20 16:18:44 +05:30
parent 2a5960bd50
commit adaabcbf92
No known key found for this signature in database
GPG key ID: E8B414FA26357220
2 changed files with 43 additions and 1 deletions

View file

@ -1393,7 +1393,13 @@ public class NotebookServer extends WebSocketServlet
}
final Note note = notebook.getNote(getOpenNoteId(conn));
List<InterpreterCompletion> candidates = note.completion(paragraphId, buffer, cursor);
List<InterpreterCompletion> candidates;
try {
candidates = note.completion(paragraphId, buffer, cursor);
} catch (RuntimeException e) {
LOG.info("Fail to get completion", e);
candidates = new ArrayList<>();
}
resp.put("completions", candidates);
conn.send(serializeMessage(resp));
}

View file

@ -709,6 +709,42 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
$scope.aceLoaded = function(_editor) {
let langTools = ace.require('ace/ext/language_tools');
let Range = ace.require('ace/range').Range;
let filteredList = ace.require('ace/autocomplete').FilteredList;
// ref: https://github.com/ajaxorg/ace/blob/5021d0193d9f2bba5a978d0b1d7a4f73d18ce713/lib/ace/autocomplete.js#L454
filteredList.prototype.setFilter = function(str) {
let matches;
if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0) {
matches = this.filtered;
} else {
matches = this.all;
}
this.filterText = str;
matches = this.filterCompletions(matches, this.filterText);
matches = matches.sort(function(a, b) {
return b.exactMatch - a.exactMatch || b.score - a.score;
});
let prev = null;
// Meta empty means item is supplied from backend
let isMetaEmpty = false;
if (matches[0] !== undefined && matches[0]['meta'] === '') {
isMetaEmpty = true;
}
matches = matches.filter(function(item) {
if (isMetaEmpty && item.meta !== '') {
return false;
}
let caption = item.snippet || item.caption || item.value;
if (caption === prev) {
return false;
}
prev = caption;
return true;
});
this.filtered = matches;
};
_editor.$blockScrolling = Infinity;
$scope.editor = _editor;