use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class BoshDeploymentManifestSchema method getCurrentStemcell.
private StemcellModel getCurrentStemcell(DynamicSchemaContext dc) throws Exception {
YamlPath path = dc.getPath();
YamlFileAST ast = asts.getAst(dc.getDocument(), true);
return new StemcellModel(path.dropLast().traverseToNode(ast));
}
use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class BoshCommandBasedModelProvider method parseYaml.
protected YamlFileAST parseYaml(String block) throws Exception {
TextDocument doc = new TextDocument(null, LanguageId.BOSH_CLOUD_CONFIG);
doc.setText(block);
YamlFileAST ast = yamlParser.getAST(doc);
return ast;
}
use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class YamlAstTest method assertPath.
protected void assertPath(MockYamlEditor input, String nodeText, String expected) throws Exception {
YamlFileAST ast = input.parse();
String path = pathString(ast.findPath(input.middleOf(nodeText)));
assertEquals(expected, path);
}
use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class ValuePropertyReferencesProvider method findReferencesInYMLFile.
private List<Location> findReferencesInYMLFile(String filePath, String propertyKey) {
List<Location> foundLocations = new ArrayList<>();
try {
String fileContent = FileUtils.readFileToString(new File(filePath));
Yaml yaml = new Yaml();
YamlASTProvider parser = new YamlParser(yaml);
URI docURI = Paths.get(filePath).toUri();
TextDocument doc = new TextDocument(docURI.toString(), null);
doc.setText(fileContent);
YamlFileAST ast = parser.getAST(doc);
List<Node> nodes = ast.getNodes();
if (nodes != null && !nodes.isEmpty()) {
for (Node node : nodes) {
Node foundNode = findNode(node, "", propertyKey);
if (foundNode != null) {
Position start = new Position();
start.setLine(foundNode.getStartMark().getLine());
start.setCharacter(foundNode.getStartMark().getColumn());
Position end = new Position();
end.setLine(foundNode.getEndMark().getLine());
end.setCharacter(foundNode.getEndMark().getColumn());
Range range = new Range();
range.setStart(start);
range.setEnd(end);
Location location = new Location(docURI.toString(), range);
foundLocations.add(location);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return foundLocations;
}
use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST 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;
}
Aggregations