use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.
the class YamlCompletionEngine method getCompletions.
@Override
public Collection<ICompletionProposal> getCompletions(TextDocument _doc, int offset) throws Exception {
YamlDocument doc = new YamlDocument(_doc, structureProvider);
if (!doc.isCommented(offset)) {
SRootNode root = doc.getStructure();
SNode current = root.find(offset);
int cursorIndent = doc.getColumn(offset);
int nodeIndent = current.getIndent();
int baseIndent = YamlIndentUtil.minIndent(cursorIndent, nodeIndent);
List<SNode> contextNodes = getContextNodes(doc, current, offset, baseIndent);
if (current.getNodeType() == SNodeType.RAW) {
// relaxed indentation
List<ICompletionProposal> completions = new ArrayList<>();
double deempasizeBy = 0.0;
for (SNode contextNode : contextNodes) {
completions.addAll(getRelaxedCompletions(offset, doc, current, contextNode, baseIndent, deempasizeBy));
deempasizeBy += ScoreableProposal.DEEMP_NEXT_CONTEXT;
}
return completions;
} else {
// precise indentation only
Assert.isLegal(contextNodes.size() <= 1);
for (SNode contextNode : contextNodes) {
return getBaseCompletions(offset, doc, current, contextNode);
}
}
}
return Collections.emptyList();
}
use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.
the class YamlStructureParserTest method testIsInValue.
@Test
public void testIsInValue() throws Exception {
MockYamlEditor editor = new MockYamlEditor("world:\n" + " europe:\n" + " france:\n" + " cheese\n" + " belgium:\n" + // At same level as key, technically this is a syntax error but we tolerate it
" beer\n" + " canada:\n" + " montreal: poutine\n" + " vancouver:\n" + " salmon\n" + "foo:\n" + "moon:\n" + " moonbase-alfa:\n" + " moonstone\n");
SRootNode root = editor.parseStructure();
assertValueRange(editor, root, "montreal: poutine", " poutine");
assertValueRange(editor, root, "europe:", "\n" + " france:\n" + " cheese\n" + " belgium:\n" + " beer");
assertValueRange(editor, root, "foo:", null);
}
use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.
the class YamlStructureParserTest method testTraverseSeqKey.
@Test
public void testTraverseSeqKey() throws Exception {
MockYamlEditor editor = new MockYamlEditor("foo:\n" + "- bar:\n" + " - a\n" + " - key: lol\n" + "- e\n");
SRootNode root = editor.parseStructure();
YamlPath path;
path = pathWith(0, "foo", 0, "bar", 1, "key");
assertEquals("KEY(4): key: lol\n", path.traverse((SNode) root).toString());
}
use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.
the class YamlStructureParserTest method testTreeEnd.
@Test
public void testTreeEnd() throws Exception {
MockYamlEditor editor = new MockYamlEditor("world:\n" + " europe:\n" + " france:\n" + " cheese\n" + " belgium:\n" + // At same level as key, technically this is a syntax error but we tolerate it
" beer\n" + " canada:\n" + " montreal: poutine\n" + " vancouver:\n" + " salmon\n" + "moon:\n" + " moonbase-alfa:\n" + " moonstone\n");
SRootNode root = editor.parseStructure();
SNode node = getNodeAtPath(root, 0, 0, 1);
assertTreeText(editor, node, " canada:\n" + " montreal: poutine\n" + " vancouver:\n" + " salmon\n");
node = getNodeAtPath(root, 0, 0, 0, 1, 0);
assertTreeText(editor, node, "beer");
}
use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.
the class YamlStructureParserTest method testGetKey.
@Test
public void testGetKey() throws Exception {
MockYamlEditor editor = new MockYamlEditor("world:\n" + " europe:\n" + " france:\n" + " cheese\n" + " belgium:\n" + // At same level as key, technically this is a syntax error but we tolerate it
" beer\n" + " canada:\n" + " montreal: poutine\n" + " vancouver:\n" + " salmon\n" + "moon:\n" + " moonbase-alfa:\n" + " moonstone\n");
SRootNode root = editor.parseStructure();
assertKey(editor, root, "world:", "world");
assertKey(editor, root, "europe:", "europe");
assertKey(editor, root, "montreal: poutine", "montreal");
}
Aggregations