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;
}
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);
}
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;
}
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";
}
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));
}
}
}
}
}
}
}
Aggregations