From 212dacff69f361ab01dcf1270042f0972b2a8999 Mon Sep 17 00:00:00 2001 From: aboyko Date: Wed, 15 May 2024 15:22:14 -0400 Subject: [PATCH] Fix YAML structure for escaped keys --- .../yaml/structure/YamlStructureParser.java | 2 +- .../structure/YamlStructureParserTest.java | 33 +++++++++++++++++++ .../boot/test/ApplicationYamlEditorTest.java | 23 +++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/structure/YamlStructureParser.java b/headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/structure/YamlStructureParser.java index 14930d2e4..1f17453db 100644 --- a/headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/structure/YamlStructureParser.java +++ b/headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/structure/YamlStructureParser.java @@ -76,7 +76,7 @@ public class YamlStructureParser { * Pattern that matches a line starting with a 'simple key' */ public static final Pattern SIMPLE_KEY_LINE = Pattern.compile( - "^((\\w(\\.|\\w|-)*)|(\\'(\\.|\\w|-|\\[|\\])*\\')):( .*|$)"); + "^((\\w(\\.|\\w|-)*)|(\\'(\\.|\\w|-|\\[|\\]|\\*|/)*\\')):( .*|$)"); //TODO: the parrern above is too selective (e.g. in real yaml one can have //spaces in simple keys and lots of other characters that this pattern does not //allow. For now it is good enough because we are only interested in spring property diff --git a/headless-services/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlStructureParserTest.java b/headless-services/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlStructureParserTest.java index 3bb8a2790..f31c0c146 100644 --- a/headless-services/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlStructureParserTest.java +++ b/headless-services/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlStructureParserTest.java @@ -65,6 +65,39 @@ public class YamlStructureParserTest { } + @Test public void escapedStringKey_2() throws Exception { + MockYamlEditor editor; + + editor = new MockYamlEditor( + "my:\n" + + " map:\n"+ + " foobar:\n" + + " name: jeff" + ); + assertParseOneDoc(editor, + "DOC(0): ", + " KEY(0): my:", + " KEY(2): map:", + " KEY(4): foobar:", + " KEY(6): name: jeff" + ); + + editor = new MockYamlEditor( + "my:\n" + + " map:\n"+ + " '[**/]':\n" + + " name: jeff" + ); + assertParseOneDoc(editor, + "DOC(0): ", + " KEY(0): my:", + " KEY(2): map:", + " KEY(4): '[**/]':", + " KEY(6): name: jeff" + ); + + } + @Test public void ignoreLeadingYamlCruftBeforeLeadingDocumentSeparator() throws Exception { String[] stuffToIgnore = { "#comment", diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java index 1f2d62016..d4196d883 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java @@ -2582,6 +2582,29 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest { "monday : String", "tuesday : String", "wednesday : String", "thursday : String", "friday : String", "saturday : String", "sunday : String" ); } + + @Test + void testValueCompletionsOnEscapedKey() throws Exception { + useProject(createPredefinedMavenProject("enums-boot-1.3.2-app")); + + data("foo.demo", "java.util.Map", null, "Map of any string to colors"); + + assertCompletions( + "foo:\n" + + " demo:\n" + + " '[./**/]': <*>", + //=> + "foo:\n" + + " demo:\n" + + " '[./**/]': blue<*>", + "foo:\n" + + " demo:\n" + + " '[./**/]': green<*>", + "foo:\n" + + " demo:\n" + + " '[./**/]': red<*>" + ); + } @Test void testEnumMapKeyCompletion() throws Exception {