Search in sources :

Example 1 with CompletionListDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.CompletionListDTO 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();
            }
        });
    }
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) CompletionListDTO(org.eclipse.che.api.languageserver.shared.lsapi.CompletionListDTO) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

CompletionListDTO (org.eclipse.che.api.languageserver.shared.lsapi.CompletionListDTO)1 TextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO)1 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1