Search in sources :

Example 1 with TextReplace

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();
    }
}
Also used : TextReplace(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits.TextReplace) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) TextEdit(org.eclipse.lsp4j.TextEdit) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Aggregations

TextEdit (org.eclipse.lsp4j.TextEdit)1 TextReplace (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits.TextReplace)1 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)1 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)1