use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SKeyNode in project sts4 by spring-projects.
the class AbstractYamlAssistContext method getCustomAssistRegion.
protected DocumentRegion getCustomAssistRegion(YamlDocument doc, SNode node, int offset) {
if (node.getNodeType() == SNodeType.KEY) {
SKeyNode keyNode = (SKeyNode) node;
if (keyNode.isInValue(offset)) {
int valueStart = keyNode.getColonOffset() + 1;
// assumes we only look at the current line, good enough for now
int valueEnd = keyNode.getNodeEnd();
DocumentRegion region = new DocumentRegion(doc.getDocument(), valueStart, valueEnd);
if (region.startsWith(" ")) {
region = region.subSequence(1);
}
return region;
}
}
// TODO Reaching here might mean support for calling the custom assistant isn't
return null;
// implemented for this kind of context yet. It will have to be expanded upon
// as the need for it arises in real use-cases.
}
use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SKeyNode in project sts4 by spring-projects.
the class YamlPathEdits method createPath.
/**
* Create the necessary edits to ensure that a given property
* path exists, placing cursor in the right place also to start
* start typing the property value.
* <p>
* This also handles cases where all or some of the path already
* exists. In the former case no edits are performed only cursor
* movement. In the latter case, the right place to start inserting
* the 'missing' portion of the path is found and the edits
* are created there.
*/
public void createPath(SChildBearingNode node, YamlPath path, String appendText) throws Exception {
// This code doesn't handle selection of subddocuments
// or creation of new subdocuments so must not call it on
// ROOT node but start at an appropriate SDocNode (or below)
Assert.isLegal(node.getNodeType() != SNodeType.ROOT);
if (!path.isEmpty()) {
YamlPathSegment s = path.getSegment(0);
if (s.getType() == YamlPathSegmentType.VAL_AT_KEY) {
String key = s.toPropString();
SKeyNode existing = node.getChildWithKey(key);
if (existing == null) {
createNewPath(node, path, appendText);
} else {
createPath(existing, path.tail(), appendText);
}
}
} else {
// whole path already exists. Just try to move cursor somewhere
// sensible in the existing tail-end-node of the path.
SNode child = node.getFirstRealChild();
if (child != null) {
moveCursorTo(child.getStart());
} else if (node.getNodeType() == SNodeType.KEY) {
SKeyNode keyNode = (SKeyNode) node;
int colonOffset = keyNode.getColonOffset();
char c = doc.getChar(colonOffset + 1);
if (c == ' ') {
// cursor after the ": "
moveCursorTo(colonOffset + 2);
} else {
// cursor after the ":"
moveCursorTo(colonOffset + 1);
}
}
}
}
use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SKeyNode in project sts4 by spring-projects.
the class YamlStructureParserTest method assertValueRange.
private void assertValueRange(MockYamlEditor editor, SRootNode root, String nodeText, String expectedValue) throws Exception {
int start = editor.getText().indexOf(nodeText);
SKeyNode node = (SKeyNode) root.find(start);
int valueRangeStart;
int valueRangeEnd;
if (expectedValue == null) {
valueRangeStart = valueRangeEnd = start + nodeText.length();
} else {
valueRangeStart = editor.getRawText().lastIndexOf(expectedValue);
valueRangeEnd = valueRangeStart + expectedValue.length();
assertEquals(expectedValue, editor.textBetween(valueRangeStart, valueRangeEnd));
}
assertTrue(node.isInValue(valueRangeStart));
assertFalse(node.isInValue(valueRangeStart - 1));
assertTrue(node.isInValue(valueRangeEnd));
assertFalse(node.isInValue(valueRangeEnd + 1));
}
use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SKeyNode in project sts4 by spring-projects.
the class YamlCompletionEngine method isBarrenKey.
private boolean isBarrenKey(SNode node) {
try {
if (node.getNodeType() == SNodeType.KEY) {
SKeyNode keyNode = (SKeyNode) node;
String value = keyNode.getSimpleValue();
return value.trim().isEmpty();
}
} catch (Exception e) {
Log.log(e);
}
return false;
}
use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SKeyNode in project sts4 by spring-projects.
the class YamlStructureParserTest method assertKey.
private void assertKey(MockYamlEditor editor, SRootNode root, String nodeText, String expectedKey) throws Exception {
int start = editor.getText().indexOf(nodeText);
SKeyNode node = (SKeyNode) root.find(start);
String key = node.getKey();
assertEquals(expectedKey, key);
// test the key range as well
int startOfKeyRange = node.getStart();
int keyRangeLen = key.length();
int endOfKeyRange = startOfKeyRange + keyRangeLen;
assertTrue(node.isInKey(startOfKeyRange));
assertFalse(node.isInKey(startOfKeyRange - 1));
assertTrue(node.isInKey(endOfKeyRange));
assertFalse(node.isInKey(endOfKeyRange + 1));
}
Aggregations