Flesh out schema for stemcells block
This commit is contained in:
@@ -32,7 +32,8 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
private final AbstractType TOPLEVEL_TYPE;
|
||||
private final YTypeUtil TYPE_UTIL;
|
||||
|
||||
public final YTypeFactory f = new YTypeFactory();
|
||||
public final YTypeFactory f = new YTypeFactory()
|
||||
.enableTieredProposals(false);
|
||||
public final YType t_string = f.yatomic("String");
|
||||
public final YType t_ne_string = f.yatomic("String")
|
||||
.parseWith(ValueParsers.NE_STRING);
|
||||
@@ -66,7 +67,12 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
addProp(t_release, "version", t_version).isRequired(true);
|
||||
addProp(TOPLEVEL_TYPE, "releases", f.yseq(t_release)).isRequired(true);
|
||||
|
||||
YType t_stemcell = t_params; //TODO: https://www.pivotaltracker.com/story/show/148627093
|
||||
YBeanType t_stemcell = f.ybean("Stemcell");
|
||||
addProp(t_stemcell, "alias", t_ne_string).isRequired(true);
|
||||
addProp(t_stemcell, "version", t_ne_string).isRequired(true);
|
||||
addProp(t_stemcell, "name", t_ne_string);
|
||||
addProp(t_stemcell, "os", t_ne_string);
|
||||
t_stemcell.requireOneOf("name", "os");
|
||||
addProp(TOPLEVEL_TYPE, "stemcells", f.yseq(t_stemcell)).isRequired(true);
|
||||
|
||||
YType t_update = t_params; //TODO: https://www.pivotaltracker.com/story/show/148627121
|
||||
|
||||
@@ -121,7 +121,35 @@ public class BoshEditorTest {
|
||||
"name: <*>",
|
||||
"releases:\n- <*>",
|
||||
"stemcells:\n- <*>",
|
||||
"update:\n <*>"
|
||||
"tags:\n <*>",
|
||||
"update:\n <*>",
|
||||
"variables:\n- <*>",
|
||||
"properties:\n <*>"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void stemcellCompletions() throws Exception {
|
||||
Editor editor = harness.newEditor(
|
||||
"stemcells:\n" +
|
||||
"- <*>"
|
||||
);
|
||||
editor.assertCompletions(
|
||||
"stemcells:\n" +
|
||||
"- alias: <*>"
|
||||
, // ==========
|
||||
"stemcells:\n" +
|
||||
"- name: <*>"
|
||||
, // ==========
|
||||
"stemcells:\n" +
|
||||
"- os: <*>"
|
||||
, // ==========
|
||||
"stemcells:\n" +
|
||||
"- version: <*>"
|
||||
);
|
||||
|
||||
editor = harness.newEditor(
|
||||
"stemcells:\n" +
|
||||
"- alias<*>"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -162,23 +162,27 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
|
||||
* in theory they would be free to define the properties in any order they want.
|
||||
*/
|
||||
protected List<List<YTypedProperty>> sortIntoTiers(List<YTypedProperty> properties) {
|
||||
if (properties.isEmpty()) {
|
||||
//Nothing to sort
|
||||
return ImmutableList.of();
|
||||
} else {
|
||||
ImmutableList.Builder<YTypedProperty> primary = ImmutableList.builder();
|
||||
ImmutableList.Builder<YTypedProperty> required = ImmutableList.builder();
|
||||
ImmutableList.Builder<YTypedProperty> other = ImmutableList.builder();
|
||||
for (YTypedProperty p : properties) {
|
||||
if (p.isPrimary()) {
|
||||
primary.add(p);
|
||||
} else if (p.isRequired()) {
|
||||
required.add(p);
|
||||
} else {
|
||||
other.add(p);
|
||||
if (typeUtil.isEnabledTieredProposals()) {
|
||||
if (properties.isEmpty()) {
|
||||
//Nothing to sort
|
||||
return ImmutableList.of();
|
||||
} else {
|
||||
ImmutableList.Builder<YTypedProperty> primary = ImmutableList.builder();
|
||||
ImmutableList.Builder<YTypedProperty> required = ImmutableList.builder();
|
||||
ImmutableList.Builder<YTypedProperty> other = ImmutableList.builder();
|
||||
for (YTypedProperty p : properties) {
|
||||
if (p.isPrimary()) {
|
||||
primary.add(p);
|
||||
} else if (p.isRequired()) {
|
||||
required.add(p);
|
||||
} else {
|
||||
other.add(p);
|
||||
}
|
||||
}
|
||||
return ImmutableList.of(primary.build(), required.build(), other.build());
|
||||
}
|
||||
return ImmutableList.of(primary.build(), required.build(), other.build());
|
||||
} else {
|
||||
return ImmutableList.of(properties);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,11 @@ import reactor.core.publisher.Flux;
|
||||
*/
|
||||
public class YTypeFactory {
|
||||
|
||||
/**
|
||||
* Configuration option for the type-based completion engine.
|
||||
*/
|
||||
private boolean enableTieredProposals = true;
|
||||
|
||||
private static class Deprecation {
|
||||
final String errorMsg;
|
||||
final String replacement;
|
||||
@@ -154,6 +159,11 @@ public class YTypeFactory {
|
||||
*/
|
||||
public final YTypeUtil TYPE_UTIL = new YTypeUtil() {
|
||||
|
||||
@Override
|
||||
public boolean isEnabledTieredProposals() {
|
||||
return enableTieredProposals;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSequencable(YType type) {
|
||||
return ((AbstractType)type).isSequenceable();
|
||||
@@ -901,5 +911,9 @@ public class YTypeFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
public YTypeFactory enableTieredProposals(boolean enable) {
|
||||
this.enableTieredProposals = enable;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,4 +49,11 @@ public interface YTypeUtil {
|
||||
List<Constraint> getConstraints(YType type);
|
||||
|
||||
ISubCompletionEngine getCustomContentAssistant(YType type);
|
||||
|
||||
/**
|
||||
* Config option for type-based completion engine. This enables the
|
||||
* 'tiered' proposals feature (so that optional properties are not
|
||||
* suggested until required ones are all defined)
|
||||
*/
|
||||
boolean isEnabledTieredProposals();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user