Search in sources :

Example 1 with PositionDTO

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

the class IncrementalTextDocumentSynchronize method syncTextDocument.

@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
    Document document = event.getDocument().getDocument();
    TextPosition startPosition = document.getPositionFromIndex(event.getOffset());
    TextPosition endPosition;
    if (event.getRemoveCharCount() != 0) {
        endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter() + event.getRemoveCharCount());
    } else {
        endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter());
    }
    DidChangeTextDocumentParamsDTO changeDTO = dtoFactory.createDto(DidChangeTextDocumentParamsDTO.class);
    String uri = document.getFile().getLocation().toString();
    changeDTO.setUri(uri);
    VersionedTextDocumentIdentifierDTO versionedDocId = dtoFactory.createDto(VersionedTextDocumentIdentifierDTO.class);
    versionedDocId.setUri(uri);
    versionedDocId.setVersion(version);
    changeDTO.setTextDocument(versionedDocId);
    RangeDTO range = dtoFactory.createDto(RangeDTO.class);
    PositionDTO start = dtoFactory.createDto(PositionDTO.class);
    start.setLine(startPosition.getLine());
    start.setCharacter(startPosition.getCharacter());
    PositionDTO end = dtoFactory.createDto(PositionDTO.class);
    end.setLine(endPosition.getLine());
    end.setCharacter(endPosition.getCharacter());
    range.setStart(start);
    range.setEnd(end);
    TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class);
    actualChange.setRange(range);
    actualChange.setText(event.getText());
    changeDTO.setContentChanges(Collections.singletonList(actualChange));
    textDocumentService.didChange(changeDTO);
}
Also used : VersionedTextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO) TextDocumentContentChangeEventDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO) DidChangeTextDocumentParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Example 2 with PositionDTO

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

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

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

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

the class FindReferencesAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    //TODO replace this
    if (!(activeEditor instanceof TextEditor)) {
        return;
    }
    TextEditor textEditor = ((TextEditor) activeEditor);
    String path = activeEditor.getEditorInput().getFile().getLocation().toString();
    ReferenceParamsDTO paramsDTO = dtoFactory.createDto(ReferenceParamsDTO.class);
    PositionDTO positionDTO = dtoFactory.createDto(PositionDTO.class);
    positionDTO.setLine(textEditor.getCursorPosition().getLine());
    positionDTO.setCharacter(textEditor.getCursorPosition().getCharacter());
    TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifierDTO.setUri(path);
    ReferenceContextDTO contextDTO = dtoFactory.createDto(ReferenceContextDTO.class);
    contextDTO.setIncludeDeclaration(true);
    paramsDTO.setUri(path);
    paramsDTO.setPosition(positionDTO);
    paramsDTO.setTextDocument(identifierDTO);
    paramsDTO.setContext(contextDTO);
    Promise<List<LocationDTO>> promise = client.references(paramsDTO);
    presenter.openLocation(promise);
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) ReferenceContextDTO(org.eclipse.che.api.languageserver.shared.lsapi.ReferenceContextDTO) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) ReferenceParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.ReferenceParamsDTO) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Aggregations

PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)5 TextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO)4 List (java.util.List)2 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)2 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)2 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)2 Collections.singletonList (java.util.Collections.singletonList)1 DidChangeTextDocumentParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO)1 DocumentRangeFormattingParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DocumentRangeFormattingParamsDTO)1 ReferenceContextDTO (org.eclipse.che.api.languageserver.shared.lsapi.ReferenceContextDTO)1 ReferenceParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.ReferenceParamsDTO)1 TextDocumentContentChangeEventDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO)1 VersionedTextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 Document (org.eclipse.che.ide.api.editor.document.Document)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1