Skip to content

Commit a014417

Browse files
committed
Gracefully handle YTT in Yaml
1 parent 449f038 commit a014417

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/ast/YamlParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016-2023 Pivotal, Inc.
2+
* Copyright (c) 2016-2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -37,6 +37,7 @@ public YamlFileAST getAST(IDocument doc) throws Exception {
3737
CharSequenceReader reader = new CharSequenceReader();
3838
reader.setInput(atTokenTransformHack(doc.get()));
3939
LoaderOptions loaderOpts = new LoaderOptions();
40+
loaderOpts.setProcessComments(true);
4041
loaderOpts.setMaxAliasesForCollections(1000);
4142
Iterable<Node> nodes = new Yaml(new SafeConstructor(loaderOpts), new Representer(new DumperOptions()), new DumperOptions(), loaderOpts).composeAll(reader);
4243
return new YamlFileAST(doc, ImmutableList.copyOf(nodes));

headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/reconcile/SchemaBasedYamlASTReconciler.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016-2017 Pivotal, Inc.
2+
* Copyright (c) 2016-2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -240,11 +240,21 @@ private void parse(YamlFileAST ast, Node node, YType type, ValueParser parser) {
240240
parser.parse(value);
241241
}
242242
} catch (Exception e) {
243-
ProblemType problemType = getProblemType(e);
244-
DocumentRegion region = getRegion(e, ast.getDocument(), node);
245-
String msg = getMessage(e);
246-
valueParseError(type, region, msg, problemType, getValueReplacement(e));
243+
// check for YTT
244+
if (isYttUsed(node)) {
245+
ProblemType problemType = getProblemType(e);
246+
DocumentRegion region = getRegion(e, ast.getDocument(), node);
247+
String msg = getMessage(e);
248+
valueParseError(type, region, msg, problemType, getValueReplacement(e));
249+
}
250+
}
251+
}
252+
253+
private boolean isYttUsed(Node node) {
254+
if (node.getBlockComments() != null) {
255+
return node.getBlockComments().stream().anyMatch(cl -> cl.getValue().startsWith("@"));
247256
}
257+
return false;
248258
}
249259

250260
protected ReplacementQuickfix getValueReplacement(Exception _e) {

headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/reconcile/TypeBasedYamlHierarchicalSymbolHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public DocumentSymbol createSymbol(YamlFileAST currentAst, Node node, YType type
7676
IDocument doc = currentAst.getDocument();
7777
if (namePath!=null) {
7878
Node nameNode = namePath.traverseNode(node);
79-
if (nameNode!=null) {
79+
// VSCode throws for DocumentSymbols having null or empty name hence do not create the symbol
80+
if (nameNode!=null && !NodeUtil.asScalar(nameNode).isEmpty()) {
8081
DocumentRegion nodeRegion = NodeUtil.region(doc, node);
8182
DocumentRegion nameRegion = NodeUtil.region(doc, nameNode);
8283
if (!nodeRegion.contains(nameRegion)) {

0 commit comments

Comments
 (0)