use of org.eclipse.che.api.languageserver.shared.lsapi.DocumentHighlightDTO 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;
}
Aggregations