Search in sources :

Example 1 with TextDocumentIdentifierDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO in project che by eclipse.

the class GoToSymbolAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    DocumentSymbolParamsDTO paramsDTO = dtoFactory.createDto(DocumentSymbolParamsDTO.class);
    TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifierDTO.setUri(editorAgent.getActiveEditor().getEditorInput().getFile().getLocation().toString());
    paramsDTO.setTextDocument(identifierDTO);
    activeEditor = (TextEditor) editorAgent.getActiveEditor();
    cursorPosition = activeEditor.getDocument().getCursorPosition();
    client.documentSymbol(paramsDTO).then(new Operation<List<SymbolInformationDTO>>() {

        @Override
        public void apply(List<SymbolInformationDTO> arg) throws OperationException {
            cachedItems = arg;
            presenter.run(GoToSymbolAction.this);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify("Can't fetch document symbols.", arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
        }
    });
}
Also used : SymbolInformationDTO(org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO) DocumentSymbolParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentSymbolParamsDTO) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 2 with TextDocumentIdentifierDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO 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 3 with TextDocumentIdentifierDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO in project che by eclipse.

the class LanguageServerFormatter method formatRange.

private void formatRange(TextRange selectedRange, Document document) {
    DocumentRangeFormattingParamsDTO params = dtoFactory.createDto(DocumentRangeFormattingParamsDTO.class);
    TextDocumentIdentifierDTO identifier = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifier.setUri(document.getFile().getLocation().toString());
    params.setTextDocument(identifier);
    params.setOptions(getFormattingOptions());
    RangeDTO range = dtoFactory.createDto(RangeDTO.class);
    PositionDTO start = dtoFactory.createDto(PositionDTO.class);
    PositionDTO end = dtoFactory.createDto(PositionDTO.class);
    start.setLine(selectedRange.getFrom().getLine());
    start.setCharacter(selectedRange.getFrom().getCharacter());
    end.setLine(selectedRange.getTo().getLine());
    end.setCharacter(selectedRange.getTo().getCharacter());
    range.setStart(start);
    range.setEnd(end);
    params.setRange(range);
    Promise<List<TextEditDTO>> promise = client.rangeFormatting(params);
    handleFormatting(promise, document);
}
Also used : TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) List(java.util.List) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO) DocumentRangeFormattingParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentRangeFormattingParamsDTO)

Example 4 with TextDocumentIdentifierDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO in project che by eclipse.

the class LanguageServerFormatter method formatFullDocument.

private void formatFullDocument(Document document) {
    DocumentFormattingParamsDTO params = dtoFactory.createDto(DocumentFormattingParamsDTO.class);
    TextDocumentIdentifierDTO identifier = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifier.setUri(document.getFile().getLocation().toString());
    params.setTextDocument(identifier);
    params.setOptions(getFormattingOptions());
    Promise<List<TextEditDTO>> promise = client.formatting(params);
    handleFormatting(promise, document);
}
Also used : TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) List(java.util.List) DocumentFormattingParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentFormattingParamsDTO)

Example 5 with TextDocumentIdentifierDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO 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

TextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO)7 List (java.util.List)4 PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)4 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)3 Collections.singletonList (java.util.Collections.singletonList)2 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 PromiseError (org.eclipse.che.api.promises.client.PromiseError)2 ArrayList (java.util.ArrayList)1 CompletionListDTO (org.eclipse.che.api.languageserver.shared.lsapi.CompletionListDTO)1 DocumentFormattingParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DocumentFormattingParamsDTO)1 DocumentRangeFormattingParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DocumentRangeFormattingParamsDTO)1 DocumentSymbolParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DocumentSymbolParamsDTO)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 ReferenceContextDTO (org.eclipse.che.api.languageserver.shared.lsapi.ReferenceContextDTO)1 ReferenceParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.ReferenceParamsDTO)1 SymbolInformationDTO (org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1