Search in sources :

Example 1 with IndentUtil

use of org.springframework.ide.vscode.commons.languageserver.completion.IndentUtil in project sts4 by spring-projects.

the class JavaSnippetBuilder method createEdit.

public DocumentEdits createEdit(DocumentRegion query, String template) {
    IDocument doc = query.getDocument();
    IndentUtil indentUtil = new IndentUtil(doc);
    DocumentEdits edit = new DocumentEdits(doc);
    String snippet = createSnippet(template);
    String referenceIndent = indentUtil.getReferenceIndent(query.getStart(), doc);
    if (!referenceIndent.contains("\t")) {
        snippet = indentUtil.covertTabsToSpace(snippet);
    }
    String indentedSnippet = indentUtil.applyIndentation(snippet, referenceIndent);
    edit.replace(query.getStart(), query.getEnd(), indentedSnippet);
    return edit;
}
Also used : DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) IndentUtil(org.springframework.ide.vscode.commons.languageserver.completion.IndentUtil) IDocument(org.springframework.ide.vscode.commons.util.text.IDocument)

Aggregations

DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)1 IndentUtil (org.springframework.ide.vscode.commons.languageserver.completion.IndentUtil)1 IDocument (org.springframework.ide.vscode.commons.util.text.IDocument)1