Enable snippet generator in concourse editor
This commit is contained in:
@@ -57,7 +57,7 @@ public class SchemaBasedSnippetGenerator implements TypeBasedSnippetProvider {
|
||||
if (typeUtil.isBean(type)) {
|
||||
SnippetBuilder builder = snippetBuilderFactory.get();
|
||||
List<YTypedProperty> requiredProps = typeUtil.getProperties(type).stream()
|
||||
.filter(p -> p.isPrimary() || p.isRequired())
|
||||
.filter(p -> p.isRequired())
|
||||
.collect(CollectorUtil.toImmutableList());
|
||||
if (!requiredProps.isEmpty()) {
|
||||
generateBeanSnippet(requiredProps, builder, indent, maxNesting);
|
||||
@@ -118,7 +118,7 @@ public class SchemaBasedSnippetGenerator implements TypeBasedSnippetProvider {
|
||||
}
|
||||
//Insert required keys
|
||||
List<YTypedProperty> requiredProps = typeUtil.getProperties(type).stream()
|
||||
.filter(p -> p.isPrimary() || p.isRequired())
|
||||
.filter(p -> p.isRequired())
|
||||
.collect(Collectors.toList());
|
||||
generateBeanSnippet(requiredProps, builder, indent, nestingLimit);
|
||||
} else if (typeUtil.isSequencable(type)) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaBasedReco
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YType;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema;
|
||||
import org.springframework.ide.vscode.commons.yaml.snippet.SchemaBasedSnippetGenerator;
|
||||
import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureProvider;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -81,10 +82,19 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
}
|
||||
}
|
||||
|
||||
public void enableSnippets(PipelineYmlSchema schema, boolean enable) {
|
||||
if (enable) {
|
||||
schema.f.setSnippetProvider(new SchemaBasedSnippetGenerator(schema.getTypeUtil(), this::createSnippetBuilder));
|
||||
} else {
|
||||
schema.f.setSnippetProvider(null);
|
||||
}
|
||||
}
|
||||
|
||||
public ConcourseLanguageServer(YamlCompletionEngineOptions completionOptions) {
|
||||
super("vscode-concourse");
|
||||
this.COMPLETION_OPTIONS = completionOptions;
|
||||
PipelineYmlSchema pipelineSchema = new PipelineYmlSchema(models);
|
||||
enableSnippets(pipelineSchema, true);
|
||||
this.yamlQuickfixes = new YamlQuickfixes(getQuickfixRegistry(), documents, structureProvider);
|
||||
|
||||
this.forPipelines = new SchemaSpecificPieces(pipelineSchema, pipelineSchema.getDefinitionTypes());
|
||||
|
||||
@@ -472,8 +472,10 @@ public class ConcourseEditorTest {
|
||||
Editor editor;
|
||||
editor = harness.newEditor("jo<*>");
|
||||
editor.assertCompletions(
|
||||
"jobs:\n"+
|
||||
"- name: <*>"
|
||||
"jobs:\n" +
|
||||
"- name: $1\n" +
|
||||
" plan:\n" +
|
||||
" - $2<*>"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -486,19 +488,24 @@ public class ConcourseEditorTest {
|
||||
"- name: <*>"
|
||||
, // --------------
|
||||
"jobs:\n" +
|
||||
"- name: <*>"
|
||||
"- name: $1\n" +
|
||||
" plan:\n" +
|
||||
" - $2<*>"
|
||||
, // ---------------
|
||||
"resource_types:\n" +
|
||||
"- name: <*>"
|
||||
"- name: $1\n" +
|
||||
" type: $2<*>"
|
||||
, // ---------------
|
||||
"resources:\n"+
|
||||
"- name: <*>"
|
||||
"- name: $1\n" +
|
||||
" type: $2<*>"
|
||||
);
|
||||
|
||||
editor = harness.newEditor("rety<*>");
|
||||
editor.assertCompletions(
|
||||
"resource_types:\n" +
|
||||
"- name: <*>"
|
||||
"- name: $1\n" +
|
||||
" type: $2<*>"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2095,6 +2102,10 @@ public class ConcourseEditorTest {
|
||||
, // ===========
|
||||
"<*>"
|
||||
, // ==>
|
||||
"uri: $1\n" +
|
||||
" branch: $2\n" +
|
||||
" file: $3<*>"
|
||||
, //---
|
||||
"uri: <*>"
|
||||
);
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
@@ -2186,6 +2197,12 @@ public class ConcourseEditorTest {
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
//snippet:
|
||||
"bucket: $1\n" +
|
||||
" key: $2\n" +
|
||||
" access_key_id: $3\n" +
|
||||
" secret_access_key: $4<*>",
|
||||
//non-snippet:
|
||||
"bucket: <*>",
|
||||
"driver: <*>"
|
||||
);
|
||||
@@ -2200,6 +2217,12 @@ public class ConcourseEditorTest {
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
//snippet:
|
||||
"bucket: $1\n" +
|
||||
" key: $2\n" +
|
||||
" access_key_id: $3\n" +
|
||||
" secret_access_key: $4<*>",
|
||||
//non-snippet:
|
||||
"bucket: <*>"
|
||||
);
|
||||
|
||||
@@ -2246,6 +2269,10 @@ public class ConcourseEditorTest {
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
"uri: $1\n" +
|
||||
" branch: $2\n" +
|
||||
" file: $3<*>"
|
||||
, //===
|
||||
"uri: <*>"
|
||||
);
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
@@ -2793,10 +2820,14 @@ public class ConcourseEditorTest {
|
||||
assertTaskCompletions(
|
||||
"<*>"
|
||||
, // ==>
|
||||
"platform: $1\n" +
|
||||
"run:\n" +
|
||||
" path: $2<*>"
|
||||
,
|
||||
"platform: <*>"
|
||||
,
|
||||
"run:\n" +
|
||||
" <*>"
|
||||
" path: <*>"
|
||||
);
|
||||
|
||||
assertContextualTaskCompletions(
|
||||
@@ -2807,7 +2838,7 @@ public class ConcourseEditorTest {
|
||||
"<*>"
|
||||
, // ==>
|
||||
"image_resource:\n" +
|
||||
" <*>"
|
||||
" type: <*>"
|
||||
,
|
||||
"inputs:\n" +
|
||||
"- name: <*>"
|
||||
@@ -3142,6 +3173,7 @@ public class ConcourseEditorTest {
|
||||
"← groups",
|
||||
"← jobs",
|
||||
"← resource_types",
|
||||
"← - Resource Snippet",
|
||||
// For the 'next job' context:
|
||||
"← - name"
|
||||
);
|
||||
@@ -3358,6 +3390,7 @@ public class ConcourseEditorTest {
|
||||
"← groups",
|
||||
"← resource_types",
|
||||
"← resources",
|
||||
"← - Job Snippet",
|
||||
"← - name"
|
||||
);
|
||||
}
|
||||
@@ -3758,6 +3791,7 @@ public class ConcourseEditorTest {
|
||||
"jobs",
|
||||
"resource_types",
|
||||
"→ type",
|
||||
"- Resource Snippet",
|
||||
"- name"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user