Search in sources :

Example 1 with TextDocumentPositionParamsDTO

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;
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Example 2 with TextDocumentPositionParamsDTO

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();
            }
        });
    }
}
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)

Example 3 with TextDocumentPositionParamsDTO

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();
        }
    });
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) Function(org.eclipse.che.api.promises.client.Function) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Optional(com.google.common.base.Optional) SignatureHelpDTO(org.eclipse.che.api.languageserver.shared.lsapi.SignatureHelpDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) SignatureHelp(org.eclipse.che.ide.api.editor.signature.SignatureHelp)

Example 4 with TextDocumentPositionParamsDTO

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;
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Example 5 with TextDocumentPositionParamsDTO

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;
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Document(org.eclipse.che.ide.api.editor.document.Document) OrionOccurrenceOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionOccurrenceOverlay) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) LanguageServerEditorConfiguration(org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration) DocumentHighlightDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentHighlightDTO) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Aggregations

TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)7 TextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)3 List (java.util.List)2 PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)2 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 JsPromise (org.eclipse.che.api.promises.client.js.JsPromise)2 Document (org.eclipse.che.ide.api.editor.document.Document)2 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)2 Optional (com.google.common.base.Optional)1 MarkedString (io.typefox.lsapi.MarkedString)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 CompletionListDTO (org.eclipse.che.api.languageserver.shared.lsapi.CompletionListDTO)1 DocumentHighlightDTO (org.eclipse.che.api.languageserver.shared.lsapi.DocumentHighlightDTO)1 HoverDTO (org.eclipse.che.api.languageserver.shared.lsapi.HoverDTO)1