use of org.eclipse.che.ide.api.editor.events.CompletionRequestHandler in project che by eclipse.
the class OrionEditorInit method configureCodeAssist.
/**
* Configure the editor's code assistant.
* @param documentHandle the handle on the document
*/
private void configureCodeAssist(final DocumentHandle documentHandle) {
if (this.codeAssistantFactory == null) {
return;
}
final Map<String, CodeAssistProcessor> processors = configuration.getContentAssistantProcessors();
if (processors != null && !processors.isEmpty()) {
LOG.info("Creating code assistant.");
final CodeAssistant codeAssistant = this.codeAssistantFactory.create(this.textEditor, this.configuration.getPartitioner());
for (String key : processors.keySet()) {
codeAssistant.setCodeAssistantProcessor(key, processors.get(key));
}
final KeyBindingAction action = new KeyBindingAction() {
@Override
public boolean action() {
showCompletion(codeAssistant, true);
return true;
}
};
final HasKeyBindings hasKeyBindings = this.textEditor.getHasKeybindings();
hasKeyBindings.addKeyBinding(new KeyBinding(true, false, false, false, KeyCode.SPACE, action), CONTENT_ASSIST);
// handle CompletionRequest events that come from text operations instead of simple key binding
documentHandle.getDocEventBus().addHandler(CompletionRequestEvent.TYPE, new CompletionRequestHandler() {
@Override
public void onCompletionRequest(final CompletionRequestEvent event) {
showCompletion(codeAssistant, false);
}
});
} else {
final KeyBindingAction action = new KeyBindingAction() {
@Override
public boolean action() {
showCompletion();
return true;
}
};
final HasKeyBindings hasKeyBindings = this.textEditor.getHasKeybindings();
if (UserAgent.isMac()) {
hasKeyBindings.addKeyBinding(new KeyBinding(false, false, false, true, KeyCode.SPACE, action), CONTENT_ASSIST);
hasKeyBindings.addKeyBinding(new KeyBinding(false, false, true, true, KeyCode.SPACE, action), CONTENT_ASSIST);
} else {
hasKeyBindings.addKeyBinding(new KeyBinding(true, false, false, false, KeyCode.SPACE, action), CONTENT_ASSIST);
}
// handle CompletionRequest events that come from text operations instead of simple key binding
documentHandle.getDocEventBus().addHandler(CompletionRequestEvent.TYPE, new CompletionRequestHandler() {
@Override
public void onCompletionRequest(final CompletionRequestEvent event) {
showCompletion();
}
});
}
}
Aggregations