use of org.eclipse.che.api.languageserver.shared.lsapi.MarkedStringDTO 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