use of org.eclipse.che.api.promises.client.js.JsPromise in project che by eclipse.
the class AbstractDebugger method addHandlers.
private void addHandlers(final MessageBusProvider messageBusProvider) {
eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {
@Override
public void onWsAgentStarted(WsAgentStateEvent event) {
messageBus = messageBusProvider.getMachineMessageBus();
if (!isConnected()) {
return;
}
Promise<DebugSessionDto> promise = service.getSessionInfo(debugSessionDto.getId());
promise.then(new Operation<DebugSessionDto>() {
@Override
public void apply(DebugSessionDto arg) throws OperationException {
debuggerManager.setActiveDebugger(AbstractDebugger.this);
setDebugSession(arg);
DebuggerInfo debuggerInfo = arg.getDebuggerInfo();
String info = debuggerInfo.getName() + " " + debuggerInfo.getVersion();
String address = debuggerInfo.getHost() + ":" + debuggerInfo.getPort();
DebuggerDescriptor debuggerDescriptor = new DebuggerDescriptor(info, address);
JsPromise<Void> promise = Promises.resolve(null);
for (DebuggerObserver observer : observers) {
observer.onDebuggerAttached(debuggerDescriptor, promise);
}
startCheckingEvents();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (!isConnected()) {
invalidateDebugSession();
}
}
});
}
@Override
public void onWsAgentStopped(WsAgentStateEvent event) {
}
});
this.debuggerEventsHandler = new SubscriptionHandler<DebuggerEventDto>(new DebuggerEventUnmarshaller(dtoFactory)) {
@Override
public void onMessageReceived(DebuggerEventDto result) {
if (!isConnected()) {
return;
}
onEventListReceived(result);
}
@Override
public void onErrorReceived(Throwable exception) {
if (!isConnected()) {
return;
}
try {
messageBus.unsubscribe(eventChannel, this);
} catch (WebSocketException e) {
Log.error(AbstractDebugger.class, e);
}
if (exception instanceof ServerException) {
ServerException serverException = (ServerException) exception;
if (HTTPStatus.INTERNAL_ERROR == serverException.getHTTPStatus() && serverException.getMessage() != null && serverException.getMessage().contains("not found")) {
disconnect();
}
}
}
};
}
use of org.eclipse.che.api.promises.client.js.JsPromise in project che by eclipse.
the class OccurrencesProvider method computeOccurrences.
@Override
public JsPromise<OrionOccurrenceOverlay[]> computeOccurrences(OrionOccurrenceContextOverlay context) {
final EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor == null || !(activeEditor instanceof TextEditor)) {
return null;
}
final TextEditor editor = ((TextEditor) activeEditor);
if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) {
return null;
}
final LanguageServerEditorConfiguration configuration = (LanguageServerEditorConfiguration) editor.getConfiguration();
if (configuration.getServerCapabilities().isDocumentHighlightProvider() == null || !configuration.getServerCapabilities().isDocumentHighlightProvider()) {
return null;
}
final Document document = editor.getDocument();
final TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, context.getStart());
// FIXME: the result should be a Promise<List<DocumentHighlightDTO>> but the typefox API returns a single DocumentHighlightDTO
Promise<DocumentHighlightDTO> promise = client.documentHighlight(paramsDTO);
Promise<OrionOccurrenceOverlay[]> then = promise.then(new Function<DocumentHighlightDTO, OrionOccurrenceOverlay[]>() {
@Override
public OrionOccurrenceOverlay[] apply(DocumentHighlightDTO highlight) throws FunctionException {
if (highlight == null) {
return new OrionOccurrenceOverlay[0];
}
final OrionOccurrenceOverlay[] occurrences = new OrionOccurrenceOverlay[1];
final OrionOccurrenceOverlay occurrence = OrionOccurrenceOverlay.create();
// FIXME: this assumes that the language server will
// compute a range based on 'line 1', ie, the whole
// file content is on line 1 and the location to
// highlight is given by the 'character' position
// only.
occurrence.setStart(highlight.getRange().getStart().getCharacter());
occurrence.setEnd(highlight.getRange().getEnd().getCharacter() + 1);
occurrences[0] = occurrence;
return occurrences;
}
});
return (JsPromise<OrionOccurrenceOverlay[]>) then;
}
use of org.eclipse.che.api.promises.client.js.JsPromise in project che by eclipse.
the class HoverProvider method computeHover.
@Override
public JsPromise<OrionHoverOverlay> computeHover(OrionHoverContextOverlay context) {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor == null || !(activeEditor instanceof TextEditor)) {
return null;
}
TextEditor editor = ((TextEditor) activeEditor);
if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) {
return null;
}
LanguageServerEditorConfiguration configuration = (LanguageServerEditorConfiguration) editor.getConfiguration();
if (configuration.getServerCapabilities().isHoverProvider() == null || !configuration.getServerCapabilities().isHoverProvider()) {
return null;
}
Document document = editor.getDocument();
TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, context.getOffset());
Promise<HoverDTO> promise = client.hover(paramsDTO);
Promise<OrionHoverOverlay> then = promise.then(new Function<HoverDTO, OrionHoverOverlay>() {
@Override
public OrionHoverOverlay apply(HoverDTO arg) throws FunctionException {
OrionHoverOverlay hover = OrionHoverOverlay.create();
hover.setType("markdown");
String content = renderContent(arg);
//do not show hover with only white spaces
if (StringUtils.isNullOrWhitespace(content)) {
return null;
}
hover.setContent(content);
return hover;
}
private String renderContent(HoverDTO hover) {
List<String> contents = new ArrayList<String>();
for (MarkedStringDTO dto : hover.getContents()) {
String lang = dto.getLanguage();
if (lang == null || MarkedString.PLAIN_STRING.equals(lang)) {
// plain markdown text
contents.add(dto.getValue());
} else {
// markdown code block
contents.add("```" + lang + "\n" + dto.getValue() + "\n```");
}
}
return Joiner.on("\n\n").join(contents);
}
});
return (JsPromise<OrionHoverOverlay>) then;
}
Aggregations