use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits.TextReplace in project sts4 by spring-projects.
the class VscodeCompletionEngineAdapter method adaptEdits.
private static Optional<TextEdit> adaptEdits(TextDocument doc, DocumentEdits edits) {
try {
TextReplace replaceEdit = edits.asReplacement(doc);
if (replaceEdit == null) {
// The original edit does nothing.
return Optional.empty();
} else {
TextDocument newDoc = doc.copy();
edits.apply(newDoc);
TextEdit vscodeEdit = new TextEdit();
vscodeEdit.setRange(doc.toRange(replaceEdit.start, replaceEdit.end - replaceEdit.start));
if (Boolean.getBoolean("lsp.completions.indentation.enable")) {
vscodeEdit.setNewText(replaceEdit.newText);
} else {
vscodeEdit.setNewText(vscodeIndentFix(doc, vscodeEdit.getRange().getStart(), replaceEdit.newText));
}
// TODO: cursor offset within newText? for now we assume its always at the end.
return Optional.of(vscodeEdit);
}
} catch (Exception e) {
LOG.get().error("{}", e);
return Optional.empty();
}
}
Aggregations