From 6be4e4c0144d15418b935d8800764ba3090fbaa7 Mon Sep 17 00:00:00 2001 From: Josh Ghiloni Date: Thu, 4 Mar 2021 13:38:43 -0700 Subject: [PATCH 1/2] Add display property to pipeline schema In Concourse 6.6, a feature was introduced to allow pipeline developers to set custom background images to their pipelines. This commit adds support for that field to the language server. --- .../vscode/concourse/PipelineYmlSchema.java | 17 ++++++++-- .../desc/Display/background_image.md | 1 + .../main/resources/desc/Pipeline/display.md | 8 +++++ .../vscode/concourse/ConcourseEditorTest.java | 34 ++++++++++++++++++- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 headless-services/concourse-language-server/src/main/resources/desc/Display/background_image.md create mode 100644 headless-services/concourse-language-server/src/main/resources/desc/Pipeline/display.md diff --git a/headless-services/concourse-language-server/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java b/headless-services/concourse-language-server/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java index 97260c117..2aec4c0d3 100644 --- a/headless-services/concourse-language-server/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java +++ b/headless-services/concourse-language-server/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java @@ -22,6 +22,7 @@ import org.springframework.ide.vscode.commons.util.MimeTypes; import org.springframework.ide.vscode.commons.util.PartialCollection; import org.springframework.ide.vscode.commons.util.Renderable; import org.springframework.ide.vscode.commons.util.Renderables; +import org.springframework.ide.vscode.commons.util.StringUtil; import org.springframework.ide.vscode.commons.util.ValueParseException; import org.springframework.ide.vscode.commons.util.ValueParser; import org.springframework.ide.vscode.commons.util.ValueParsers; @@ -36,6 +37,7 @@ import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaValuePars import org.springframework.ide.vscode.commons.yaml.reconcile.TypeBasedYamlHierarchicalSymbolHandler.HierarchicalDefType; import org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint; import org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext; +import org.springframework.ide.vscode.commons.yaml.schema.SchemaContextAware; import org.springframework.ide.vscode.commons.yaml.schema.YType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType; @@ -57,6 +59,7 @@ import org.springframework.ide.vscode.concourse.github.GithubValueParsers; import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.nodes.Node; +import com.fasterxml.jackson.databind.jsonschema.SchemaAware; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -456,6 +459,12 @@ public class PipelineYmlSchema implements YamlSchema { addProp(group, "resources", f.yseq(t_resource_name)); addProp(group, "jobs", f.yseq(t_job_name)); + YType t_background_image_def = f.yatomic("Background Image") + .parseWith(ValueParsers.NE_STRING); + + AbstractType t_display = f.ybean("Display"); + addProp(t_display, "background_image", t_background_image_def).isRequired(true); + YSeqType t_resources = f.yseq(t_resource); YSeqType t_jobs = f.yseq(job); YSeqType t_resourceTypes = f.yseq(resourceType); @@ -464,12 +473,14 @@ public class PipelineYmlSchema implements YamlSchema { addProp(TOPLEVEL_TYPE, "jobs", t_jobs); addProp(TOPLEVEL_TYPE, "resource_types", t_resourceTypes); addProp(TOPLEVEL_TYPE, "groups", t_groups); + addProp(TOPLEVEL_TYPE, "display", t_display); definitionTypes = ImmutableList.of( jobNameDef, resourceTypeNameDef, t_resource_name_def, - t_group_name_def + t_group_name_def, + t_background_image_def ); hierarchicDefinitions = ImmutableList.of( new HierarchicalDefType(t_resources, null, SymbolKind.File, "Resources"), @@ -482,7 +493,9 @@ public class PipelineYmlSchema implements YamlSchema { new HierarchicalDefType(resourceType, YamlPath.fromSimpleProperty("name"), SymbolKind.Interface, "Resource Type"), new HierarchicalDefType(t_groups, null, SymbolKind.Package, "Groups"), - new HierarchicalDefType(group, YamlPath.fromSimpleProperty("name"), SymbolKind.Package, "Groups") + new HierarchicalDefType(group, YamlPath.fromSimpleProperty("name"), SymbolKind.Package, "Groups"), + + new HierarchicalDefType(t_display, null, SymbolKind.Package, "Display Settings") ); initializeDefaultResourceTypes(); diff --git a/headless-services/concourse-language-server/src/main/resources/desc/Display/background_image.md b/headless-services/concourse-language-server/src/main/resources/desc/Display/background_image.md new file mode 100644 index 000000000..f622d474d --- /dev/null +++ b/headless-services/concourse-language-server/src/main/resources/desc/Display/background_image.md @@ -0,0 +1 @@ +Allow users to specify a custom background image which is put at 30% opacity, grayscaled and blended into existing background. Must be an http, https, or relative URL. \ No newline at end of file diff --git a/headless-services/concourse-language-server/src/main/resources/desc/Pipeline/display.md b/headless-services/concourse-language-server/src/main/resources/desc/Pipeline/display.md new file mode 100644 index 000000000..f7208cfbd --- /dev/null +++ b/headless-services/concourse-language-server/src/main/resources/desc/Pipeline/display.md @@ -0,0 +1,8 @@ +Visual configurations for personalizing your pipeline (Concourse 6.6+ only) + +You may use this optional section to set a background image on your pipeline. + +A simple example looks like this: + + display: + background_image: https://avatars1.githubusercontent.com/u/7809479?s=400&v=4 diff --git a/headless-services/concourse-language-server/src/test/java/org/springframework/ide/vscode/concourse/ConcourseEditorTest.java b/headless-services/concourse-language-server/src/test/java/org/springframework/ide/vscode/concourse/ConcourseEditorTest.java index 1199649f6..0d1e7fd1b 100644 --- a/headless-services/concourse-language-server/src/test/java/org/springframework/ide/vscode/concourse/ConcourseEditorTest.java +++ b/headless-services/concourse-language-server/src/test/java/org/springframework/ide/vscode/concourse/ConcourseEditorTest.java @@ -184,6 +184,18 @@ public class ConcourseEditorTest { ); } + @Test public void reconcileDisplayType() throws Exception { + Editor editor; + editor = harness.newEditor( + "display:\n" + + " background_image: # <- bad\n" + ); + + editor.assertProblems( + "^ # <- bad|String should not be empty" + ); + } + @Test public void testReconcileCatchesParseError() throws Exception { Editor editor = harness.newEditor( "somemap: val\n"+ @@ -493,6 +505,17 @@ public class ConcourseEditorTest { editor.assertHoverContains("ensure", "a second step to execute regardless of the result of the parent step"); } + @Test public void displayHovers() throws Exception { + Editor editor; + editor = harness.newEditor( + "display:\n" + + " background_image: http://google.com/myimage.png\n" + ); + + editor.assertHoverContains("background_image", "custom background image"); + } + + @Test public void groupHovers() throws Exception { Editor editor = harness.newEditor( @@ -819,6 +842,9 @@ public class ConcourseEditorTest { Editor editor; editor = harness.newEditor(CURSOR); editor.assertCompletions( + "display:\n"+ + " background_image: <*>" + , // --------------- "groups:\n" + "- name: <*>" , // -------------- @@ -890,6 +916,8 @@ public class ConcourseEditorTest { @Test public void topLevelHoverInfos() throws Exception { Editor editor = harness.newEditor( + "display:\n" + + " background_image: http://example.com/fakeimage.png\n" + "resource_types:\n" + "- name: s3-multi\n" + " type: docker-image\n" + @@ -924,6 +952,7 @@ public class ConcourseEditorTest { editor.assertHoverContains("resources", "A resource is any entity that can be checked for new versions"); editor.assertHoverContains("jobs", "At a high level, a job describes some actions to perform"); editor.assertHoverContains("groups", "A pipeline may optionally contain a section called `groups`"); + editor.assertHoverContains("display", "set a background image on your pipeline"); } @Test @@ -4003,11 +4032,12 @@ public class ConcourseEditorTest { //For the nested context: "→ uri", // For the top-level context: + "← display", "← groups", "← jobs", "← resource_types", "← - Resource Snippet", - // For the 'next job' context: + // For the 'next job' context "← - name" ); @@ -4255,6 +4285,7 @@ public class ConcourseEditorTest { "- try", "- aggregate", //Dedented completions + "← display", "← groups", "← resource_types", "← resources", @@ -4711,6 +4742,7 @@ public class ConcourseEditorTest { "<*>" ); editor.assertCompletionLabels( + "display", "groups", "jobs", "resource_types", From 6e51ca93c302ead81991ef5acd65cad96a6e1af4 Mon Sep 17 00:00:00 2001 From: Josh Ghiloni Date: Thu, 4 Mar 2021 13:48:52 -0700 Subject: [PATCH 2/2] Remove unused imports --- .../ide/vscode/concourse/PipelineYmlSchema.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/headless-services/concourse-language-server/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java b/headless-services/concourse-language-server/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java index 2aec4c0d3..a16be166e 100644 --- a/headless-services/concourse-language-server/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java +++ b/headless-services/concourse-language-server/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java @@ -22,7 +22,6 @@ import org.springframework.ide.vscode.commons.util.MimeTypes; import org.springframework.ide.vscode.commons.util.PartialCollection; import org.springframework.ide.vscode.commons.util.Renderable; import org.springframework.ide.vscode.commons.util.Renderables; -import org.springframework.ide.vscode.commons.util.StringUtil; import org.springframework.ide.vscode.commons.util.ValueParseException; import org.springframework.ide.vscode.commons.util.ValueParser; import org.springframework.ide.vscode.commons.util.ValueParsers; @@ -37,7 +36,6 @@ import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaValuePars import org.springframework.ide.vscode.commons.yaml.reconcile.TypeBasedYamlHierarchicalSymbolHandler.HierarchicalDefType; import org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint; import org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext; -import org.springframework.ide.vscode.commons.yaml.schema.SchemaContextAware; import org.springframework.ide.vscode.commons.yaml.schema.YType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType; @@ -59,9 +57,7 @@ import org.springframework.ide.vscode.concourse.github.GithubValueParsers; import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.nodes.Node; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; /** * @author Kris De Volder