use of org.springframework.ide.vscode.commons.util.text.TextDocument 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.util.text.TextDocument in project sts4 by spring-projects.
the class MockYamlEditor method parseStructure.
public SRootNode parseStructure() throws Exception {
YamlStructureProvider sp = YamlStructureProvider.DEFAULT;
TextDocument _doc = new TextDocument(null, getLanguageId());
_doc.setText(text);
YamlDocument doc = new YamlDocument(_doc, sp);
return sp.getStructure(doc);
}
use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.
the class CommonLanguageTools method getValueType.
/**
* Determine the value type for a give propertyName.
*/
public static Type getValueType(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String propertyName) {
try {
PropertyInfo prop = index.get(propertyName);
if (prop != null) {
return TypeParser.parse(prop.getType());
} else {
prop = CommonLanguageTools.findLongestValidProperty(index, propertyName);
if (prop != null) {
TextDocument doc = new TextDocument(null, LanguageId.PLAINTEXT);
doc.setText(propertyName);
PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, 0, doc.getLength()));
return navigator.navigate(prop.getId().length(), TypeParser.parse(prop.getType()));
}
}
} catch (Exception e) {
Log.log(e);
}
return null;
}
Aggregations