Search in sources :

Example 1 with SRootNode

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();
}
Also used : SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) SNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode) YamlDocument(org.springframework.ide.vscode.commons.yaml.structure.YamlDocument) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) ArrayList(java.util.ArrayList)

Example 2 with SRootNode

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);
}
Also used : SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) Test(org.junit.Test)

Example 3 with SRootNode

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());
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) Test(org.junit.Test)

Example 4 with SRootNode

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");
}
Also used : SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) SNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode) Test(org.junit.Test)

Example 5 with SRootNode

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");
}
Also used : SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) Test(org.junit.Test)

Aggregations

SRootNode (org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode)12 Test (org.junit.Test)10 SNode (org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode)6 YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)4 ArrayList (java.util.ArrayList)1 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)1 YamlDocument (org.springframework.ide.vscode.commons.yaml.structure.YamlDocument)1