use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO 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;
}
use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO in project che by eclipse.
the class FindDefinitionAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
TextEditor textEditor = ((TextEditor) activeEditor);
TextDocumentPositionParamsDTO paramsDTO = dtoBuildHelper.createTDPP(textEditor.getDocument(), textEditor.getCursorPosition());
final Promise<List<LocationDTO>> promise = client.definition(paramsDTO);
promise.then(new Operation<List<LocationDTO>>() {
@Override
public void apply(List<LocationDTO> arg) throws OperationException {
if (arg.size() == 1) {
presenter.onLocationSelected(arg.get(0));
} else {
presenter.openLocation(promise);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
presenter.showError(arg);
}
});
}
Aggregations