Search in sources :

Example 1 with TextDocumentContentChangeEventDTO

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

the class FullTextDocumentSynchronize method syncTextDocument.

@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
    Document document = event.getDocument().getDocument();
    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);
    TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class);
    actualChange.setText(event.getDocument().getDocument().getContents());
    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) Document(org.eclipse.che.ide.api.editor.document.Document)

Example 2 with TextDocumentContentChangeEventDTO

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

Aggregations

DidChangeTextDocumentParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO)2 TextDocumentContentChangeEventDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO)2 VersionedTextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO)2 Document (org.eclipse.che.ide.api.editor.document.Document)2 PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)1