use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits in project sts4 by spring-projects.
the class YamlCompletionEngine method dedented.
public ScoreableProposal dedented(ICompletionProposal proposal, int numSpacesToRemove, IDocument doc) {
Assert.isLegal(numSpacesToRemove > 0);
int spacesEnd = proposal.getTextEdit().getFirstEditStart();
int spacesStart = spacesEnd - numSpacesToRemove;
int numArrows = numSpacesToRemove / YamlIndentUtil.INDENT_BY;
String spaces = new DocumentRegion(doc, spacesStart, spacesEnd).toString();
YamlIndentUtil indenter = new YamlIndentUtil(doc);
if (spaces.length() == numSpacesToRemove && SPACES.matcher(spaces).matches()) {
ScoreableProposal transformed = new TransformedCompletion(proposal) {
@Override
public String tranformLabel(String originalLabel) {
return Strings.repeat(Unicodes.LEFT_ARROW + " ", numArrows) + originalLabel;
}
@Override
public DocumentEdits transformEdit(DocumentEdits originalEdit) {
originalEdit.firstDelete(spacesStart, spacesEnd);
originalEdit.transformFirstNonWhitespaceEdit((offset, insertText) -> {
String prefix = insertText.substring(0, offset);
String dedented = indenter.applyIndentation(insertText.substring(offset), -numSpacesToRemove);
return prefix + dedented;
});
return originalEdit;
}
@Override
public String getFilterText() {
// to replace. Since we are replacing these removed spaces, they must be part of the filtertext
return spaces + super.getFilterText();
}
};
transformed.deemphasize(DEEMP_DEDENTED_PROPOSAL * numArrows);
return transformed;
}
// in our attempt to de-dent.)
return null;
}
use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits in project sts4 by spring-projects.
the class LanguageServerHarness method perform.
private void perform(WorkspaceEdit workspaceEdit) throws Exception {
Assert.isNull("Versioned WorkspaceEdits not supported", workspaceEdit.getDocumentChanges());
for (Entry<String, List<TextEdit>> entry : workspaceEdit.getChanges().entrySet()) {
String uri = entry.getKey();
TextDocumentInfo document = documents.get(uri);
assertNotNull("Can't apply edits to non-existing document: " + uri, document);
TextDocument workingDocument = new TextDocument(uri, document.getLanguageId());
workingDocument.setText(document.getText());
DocumentEdits edits = new DocumentEdits(workingDocument);
for (TextEdit edit : entry.getValue()) {
Range range = edit.getRange();
edits.replace(document.toOffset(range.getStart()), document.toOffset(range.getEnd()), edit.getNewText());
}
edits.apply(workingDocument);
Editor editor = getOpenEditor(uri);
if (editor != null) {
editor.setRawText(workingDocument.get());
} else {
changeDocument(uri, workingDocument.get());
}
}
}
use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits in project sts4 by spring-projects.
the class RouteContentAssistant method createProposal.
private ICompletionProposal createProposal(CompletionFactory f, DocumentRegion region, int offset, String query, double score, YValueHint domain) {
DocumentEdits edits = new DocumentEdits(region.getDocument());
region = region.subSequence(offset - query.length());
// Add extra space after ':' if needed!
boolean needSpace = region.textBefore(1).charAt(0) == ':';
edits.replace(region.getStart(), region.getEnd(), needSpace ? " " + domain.getValue() : domain.getValue());
return f.valueProposal(domain.getValue(), query, domain.getLabel(), schema.t_route_string, domain.getDocumentation(), score, edits, schema.getTypeUtil());
}
Aggregations