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