Search in sources :

Example 6 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class YamlHoverInfoProvider method getHoverInfo.

@Override
public Tuple2<Renderable, IRegion> getHoverInfo(IDocument doc, int offset) throws Exception {
    YamlFileAST ast = getAst(doc);
    if (ast != null) {
        IRegion region = getHoverRegion(ast, offset);
        if (region != null) {
            YamlDocument ymlDoc = new YamlDocument(doc, structureProvider);
            YamlAssistContext assistContext = assistContextProvider.getGlobalAssistContext(ymlDoc);
            if (assistContext != null) {
                List<NodeRef<?>> astPath = ast.findPath(offset);
                final YamlPath path = YamlPath.fromASTPath(astPath);
                if (path != null) {
                    YamlPath assistPath = path;
                    if (assistPath.pointsAtKey()) {
                        // When a path points at a key we must tramsform it to a
                        // 'value-terminating path'
                        // to be able to reuse the 'getHoverInfo' method on
                        // YamlAssistContext (as navigation
                        // into 'key' is not defined for YamlAssistContext.
                        String key = path.getLastSegment().toPropString();
                        assistPath = path.dropLast().append(YamlPathSegment.valueAt(key));
                    }
                    assistContext = assistPath.traverse(assistContext);
                    if (assistContext != null) {
                        Renderable info = path.pointsAtValue() ? assistContext.getValueHoverInfo(ymlDoc, new DocumentRegion(doc, region)) : assistContext.getHoverInfo();
                        // Fix for: PT 134914895. If assist context cannot provide an info, then don't return a Tuple.
                        if (info != null) {
                            return Tuples.of(info, region);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : NodeRef(org.springframework.ide.vscode.commons.yaml.ast.NodeRef) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) Renderable(org.springframework.ide.vscode.commons.util.Renderable) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) YamlDocument(org.springframework.ide.vscode.commons.yaml.structure.YamlDocument) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) YamlAssistContext(org.springframework.ide.vscode.commons.yaml.completion.YamlAssistContext) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Example 7 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class YamlSchemaProblems method missingProperties.

public static ReconcileProblem missingProperties(String msg, DynamicSchemaContext dc, Set<String> missingProps, String snippet, int cursorOffset, Node parent, MappingNode map, QuickfixType quickfixType) {
    YamlPath contextPath = dc.getPath();
    List<String> segments = Stream.of(contextPath.getSegments()).map(YamlPathSegment::encode).collect(Collectors.toList());
    String fixTitle = missingProps.size() == 1 ? "Add property '" + CollectionUtil.getAny(missingProps) + "'" : "Add properties: " + missingProps;
    QuickfixData<MissingPropertiesData> fix = new QuickfixData<MissingPropertiesData>(quickfixType, new MissingPropertiesData(dc.getDocument().getUri(), segments, ImmutableList.copyOf(missingProps), snippet, cursorOffset), fixTitle);
    return missingProperty(msg, dc.getDocument(), parent, map).addQuickfix(fix);
}
Also used : QuickfixData(org.springframework.ide.vscode.commons.languageserver.quickfix.Quickfix.QuickfixData) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath)

Example 8 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class BoshDeploymentManifestSchema method getCurrentEntityProperty.

private String getCurrentEntityProperty(DynamicSchemaContext dc, String propName) {
    YamlPath path = dc.getPath();
    YamlFileAST ast = asts.getSafeAst(dc.getDocument(), true);
    if (ast != null) {
        return NodeUtil.asScalar(path.dropLast().thenValAt(propName).traverseToNode(ast));
    }
    return null;
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST)

Example 9 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class ManifestYmlSchema method getEffectiveHealthCheckType.

/**
 * Determines the actual health-check-type that applies to a given node, taking into account
 * inheritance from parent node, and default value.
 */
private String getEffectiveHealthCheckType(YamlFileAST ast, YamlPath path, Node node) {
    String explicit = NodeUtil.getScalarProperty(node, HEALTH_CHECK_TYPE_PROP);
    if (explicit != null) {
        return explicit;
    }
    if (path.size() > 2) {
        // Must consider inherited props!
        YamlPath parentPath = path.dropLast(2);
        Node parent = parentPath.traverseToNode(ast);
        String inherited = NodeUtil.getScalarProperty(parent, HEALTH_CHECK_TYPE_PROP);
        if (inherited != null) {
            return inherited;
        }
    }
    return "port";
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) Node(org.yaml.snakeyaml.nodes.Node)

Example 10 with YamlPath

use of org.springframework.ide.vscode.commons.yaml.path.YamlPath in project sts4 by spring-projects.

the class ConcourseModel method passedJobHasInteractionWithResource.

/**
 * Verification of contraint: a job used in the 'passed' attribute of a step
 * must interact with the resource in question.
 */
public final void passedJobHasInteractionWithResource(DynamicSchemaContext dc, Node parent, Node node, YType type, IProblemCollector problems) {
    YamlPath path = dc.getPath();
    // Expecting a path like this: YamlPath([0], .jobs, [1], .plan, [0], .passed, [0])
    path = path.dropLast();
    if (YamlPathSegment.valueAt("passed").equals(path.getLastSegment())) {
        String jobName = NodeUtil.asScalar(node);
        JobModel job = getJob(dc.getDocument(), jobName);
        if (job != null) {
            // Only check if the job exists. Otherwise the extra checks will show 'redundant' errors (e.g.
            // complaining that 'some-job' doesn't ineract with a resource (because the resource doesn't exist).
            YamlFileAST root = asts.getSafeAst(dc.getDocument());
            if (root != null) {
                Node stepNode = path.dropLast().traverseToNode(root);
                if (stepNode != null) {
                    StepModel step = newStep(stepNode);
                    String resourceName = step.getResourceName();
                    if (resourceName != null && getResource(dc.getDocument(), resourceName) != null) {
                        Set<String> interactions = job.getInteractedResources();
                        if (interactions != null && !interactions.contains(resourceName)) {
                            problems.accept(YamlSchemaProblems.schemaProblem("Job '" + jobName + "' does not interact with resource '" + resourceName + "'", node));
                        }
                    }
                }
            }
        }
    }
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node)

Aggregations

YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)12 YamlFileAST (org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST)4 SNode (org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode)4 SRootNode (org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode)4 Test (org.junit.Test)3 Node (org.yaml.snakeyaml.nodes.Node)3 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)2 StemcellModel (org.springframework.ide.vscode.bosh.models.StemcellModel)1 QuickfixData (org.springframework.ide.vscode.commons.languageserver.quickfix.Quickfix.QuickfixData)1 IntegerRange (org.springframework.ide.vscode.commons.util.IntegerRange)1 Renderable (org.springframework.ide.vscode.commons.util.Renderable)1 ValueParseException (org.springframework.ide.vscode.commons.util.ValueParseException)1 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)1 IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)1 NodeRef (org.springframework.ide.vscode.commons.yaml.ast.NodeRef)1 YamlAssistContext (org.springframework.ide.vscode.commons.yaml.completion.YamlAssistContext)1 SNodeDynamicSchemaContext (org.springframework.ide.vscode.commons.yaml.schema.SNodeDynamicSchemaContext)1 Constraint (org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint)1 YamlDocument (org.springframework.ide.vscode.commons.yaml.structure.YamlDocument)1 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)1