use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO in project che by eclipse.
the class DtoBuildHelper method createTDPP.
public TextDocumentPositionParamsDTO createTDPP(Document document, TextPosition position) {
TextDocumentPositionParamsDTO paramsDTO = dtoFactory.createDto(TextDocumentPositionParamsDTO.class);
TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
identifierDTO.setUri(document.getFile().getLocation().toString());
PositionDTO positionDTO = dtoFactory.createDto(PositionDTO.class);
positionDTO.setCharacter(position.getCharacter());
positionDTO.setLine(position.getLine());
paramsDTO.setUri(document.getFile().getLocation().toString());
paramsDTO.setTextDocument(identifierDTO);
paramsDTO.setPosition(positionDTO);
return paramsDTO;
}
use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO in project che by eclipse.
the class LanguageServerCodeAssistProcessor method computeCompletionProposals.
@Override
public void computeCompletionProposals(TextEditor editor, final int offset, final boolean triggered, final CodeAssistCallback callback) {
this.lastErrorMessage = null;
TextDocumentPositionParamsDTO documentPosition = dtoBuildHelper.createTDPP(editor.getDocument(), offset);
final TextDocumentIdentifierDTO documentId = documentPosition.getTextDocument();
String currentLine = editor.getDocument().getLineContent(documentPosition.getPosition().getLine());
final String currentWord = getCurrentWord(currentLine, documentPosition.getPosition().getCharacter());
if (!triggered && latestCompletionResult.isGoodFor(documentId, offset, currentWord)) {
// no need to send new completion request
computeProposals(currentWord, offset - latestCompletionResult.getOffset(), callback);
} else {
documentServiceClient.completion(documentPosition).then(new Operation<CompletionListDTO>() {
@Override
public void apply(CompletionListDTO list) throws OperationException {
latestCompletionResult.update(documentId, offset, currentWord, list);
computeProposals(currentWord, 0, callback);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
lastErrorMessage = error.getMessage();
}
});
}
}
use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO in project che by eclipse.
the class LanguageServerSignatureHelp method signatureHelp.
@Override
public Promise<Optional<SignatureHelp>> signatureHelp(Document document, int offset) {
TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, offset);
Promise<SignatureHelpDTO> promise = client.signatureHelp(paramsDTO);
return promise.then(new Function<SignatureHelpDTO, Optional<SignatureHelp>>() {
@Override
public Optional<SignatureHelp> apply(SignatureHelpDTO arg) throws FunctionException {
if (arg == null) {
return Optional.absent();
}
return Optional.<SignatureHelp>of(new SignatureHelpImpl(arg));
}
}).catchError(new Function<PromiseError, Optional<SignatureHelp>>() {
@Override
public Optional<SignatureHelp> apply(PromiseError arg) throws FunctionException {
notificationManager.notify(arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.EMERGE_MODE);
return Optional.absent();
}
});
}
use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO in project che by eclipse.
the class DtoBuildHelper method createTDPP.
public TextDocumentPositionParamsDTO createTDPP(Document document, int cursorOffset) {
TextDocumentPositionParamsDTO paramsDTO = dtoFactory.createDto(TextDocumentPositionParamsDTO.class);
TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
identifierDTO.setUri(document.getFile().getLocation().toString());
PositionDTO positionDTO = dtoFactory.createDto(PositionDTO.class);
TextPosition position = document.getPositionFromIndex(cursorOffset);
positionDTO.setCharacter(position.getCharacter());
positionDTO.setLine(position.getLine());
paramsDTO.setUri(document.getFile().getLocation().toString());
paramsDTO.setTextDocument(identifierDTO);
paramsDTO.setPosition(positionDTO);
return paramsDTO;
}
use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO 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