Search in sources :

Example 1 with TextEditDTO

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

the class LanguageServerFormatter method applyEdits.

private void applyEdits(List<TextEditDTO> edits, Document document) {
    HandlesUndoRedo undoRedo = null;
    if (editor instanceof UndoableEditor) {
        undoRedo = ((UndoableEditor) editor).getUndoRedo();
    }
    try {
        if (undoRedo != null) {
            undoRedo.beginCompoundChange();
        }
        // #2437: apply the text edits from last to first to avoid messing up the document
        Collections.reverse(edits);
        for (TextEditDTO change : edits) {
            RangeDTO range = change.getRange();
            document.replace(range.getStart().getLine(), range.getStart().getCharacter(), range.getEnd().getLine(), range.getEnd().getCharacter(), change.getNewText());
        }
    } catch (final Exception e) {
        Log.error(getClass(), e);
    } finally {
        if (undoRedo != null) {
            undoRedo.endCompoundChange();
        }
    }
}
Also used : HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) TextEditDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextEditDTO) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 TextEditDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextEditDTO)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 HandlesUndoRedo (org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)1 UndoableEditor (org.eclipse.che.ide.api.editor.texteditor.UndoableEditor)1