Minimal support for editing cloud-config
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.bosh;
|
||||
|
||||
import org.springframework.ide.vscode.bosh.models.BoshModels;
|
||||
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.YBeanType;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema;
|
||||
|
||||
public class BoshCloudConfigSchema extends SchemaSupport implements YamlSchema {
|
||||
|
||||
private YBeanType toplevelType;
|
||||
private YType t_any;
|
||||
|
||||
public BoshCloudConfigSchema(YTypeFactory f, BoshModels models) {
|
||||
super(f);
|
||||
this.toplevelType = f.ybean("CloudConfig");
|
||||
t_any = f.yany("Object");
|
||||
|
||||
addProp(toplevelType, "azs", t_any);
|
||||
addProp(toplevelType, "networks", t_any);
|
||||
addProp(toplevelType, "vm_types", t_any);
|
||||
addProp(toplevelType, "vm_extensions", t_any);
|
||||
addProp(toplevelType, "disk_types", t_any);
|
||||
addProp(toplevelType, "compilation", t_any);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YType getTopLevelType() {
|
||||
return toplevelType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YTypeUtil getTypeUtil() {
|
||||
return f.TYPE_UTIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResourcePathPrefix() {
|
||||
return "cloud-config";
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class BoshDefintionFinder extends SimpleDefinitionFinder<BoshLanguageServ
|
||||
|
||||
private final YamlAstCache asts;
|
||||
private final ASTTypeCache astTypes;
|
||||
private final BoshDeploymentManifestSchema schema;
|
||||
private final BoshSchemas schema;
|
||||
|
||||
private Map<YType, Handler> handlers = new HashMap<>();
|
||||
|
||||
@@ -47,7 +47,7 @@ public class BoshDefintionFinder extends SimpleDefinitionFinder<BoshLanguageServ
|
||||
Flux<Location> handle(Node refNode, TextDocument doc, YamlFileAST ast);
|
||||
}
|
||||
|
||||
public BoshDefintionFinder(BoshLanguageServer server, BoshDeploymentManifestSchema schema, YamlAstCache asts, ASTTypeCache astTypes) {
|
||||
public BoshDefintionFinder(BoshLanguageServer server, BoshSchemas schema, YamlAstCache asts, ASTTypeCache astTypes) {
|
||||
super(server);
|
||||
this.schema = schema;
|
||||
this.asts = asts;
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.ide.vscode.bosh.models.BoshModels;
|
||||
import org.springframework.ide.vscode.bosh.models.CachingModelProvider;
|
||||
import org.springframework.ide.vscode.bosh.models.CloudConfigModel;
|
||||
import org.springframework.ide.vscode.bosh.models.DynamicModelProvider;
|
||||
@@ -58,7 +59,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
/**
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
public class BoshDeploymentManifestSchema extends SchemaSupport implements YamlSchema {
|
||||
|
||||
private final YBeanType V2_TOPLEVEL_TYPE;
|
||||
private final YBeanType V1_TOPLEVEL_TYPE;
|
||||
@@ -70,26 +71,19 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
private ImmutableList<YType> definitionTypes = null;
|
||||
//Note: 'director_uuid' is also deprecated. But its treated separately since it is deprecated and ignored by V2 client no matter what (i.e. deprecated in both schemas)
|
||||
|
||||
public final YTypeFactory f = new YTypeFactory()
|
||||
.enableTieredProposals(false)
|
||||
.suggestDeprecatedProperties(false);
|
||||
public final YType t_string = f.yatomic("String");
|
||||
public final YType t_ne_string = f.yatomic("String")
|
||||
.parseWith(ValueParsers.NE_STRING);
|
||||
public final YType t_string;
|
||||
public final YType t_ne_string;
|
||||
|
||||
public final YType t_strings = f.yseq(t_string);
|
||||
public final YType t_strings;
|
||||
|
||||
public final YAtomicType t_boolean = f.yenum("boolean", "true", "false");
|
||||
public final YType t_any = f.yany("Object");
|
||||
public final YType t_params = f.ymap(t_string, t_any);
|
||||
public final YType t_string_params = f.ymap(t_string, t_string);
|
||||
public final YType t_pos_integer = f.yatomic("Positive Integer")
|
||||
.parseWith(ValueParsers.POS_INTEGER);
|
||||
public final YType t_strictly_pos_integer = f.yatomic("Strictly Positive Integer")
|
||||
.parseWith(ValueParsers.integerAtLeast(1));
|
||||
public final YType t_uuid = f.yatomic("UUID").parseWith(UUID::fromString);
|
||||
public final YType t_integer_or_range = f.yatomic("Integer or Range")
|
||||
.parseWith(BoshValueParsers.INTEGER_OR_RANGE);
|
||||
public final YAtomicType t_boolean;
|
||||
public final YType t_any;
|
||||
public final YType t_params;
|
||||
public final YType t_string_params;
|
||||
public final YType t_pos_integer;
|
||||
public final YType t_strictly_pos_integer;
|
||||
public final YType t_uuid;
|
||||
public final YType t_integer_or_range;
|
||||
private YType t_stemcell_alias_def;
|
||||
private YType t_stemcell_alias_ref;
|
||||
private YType t_release_name_def;
|
||||
@@ -103,19 +97,31 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
private DynamicModelProvider<ReleasesModel> releasesProvider;
|
||||
private List<Pair<YType, YType>> defAndRefTypes;
|
||||
|
||||
public BoshDeploymentManifestSchema(
|
||||
YamlAstCache asts, ASTTypeCache astTypes,
|
||||
DynamicModelProvider<CloudConfigModel> cloudConfigProvider,
|
||||
DynamicModelProvider<StemcellsModel> stemcellsProvider,
|
||||
DynamicModelProvider<ReleasesModel> releasesProvider
|
||||
) {
|
||||
this.asts = asts;
|
||||
this.astTypes = astTypes;
|
||||
this.cloudConfigProvider = new CachingModelProvider<>(cloudConfigProvider, CloudConfigModel.class);
|
||||
this.stemcellsProvider = new CachingModelProvider<>(stemcellsProvider, StemcellsModel.class);
|
||||
this.releasesProvider = new CachingModelProvider<>(releasesProvider, ReleasesModel.class);
|
||||
public BoshDeploymentManifestSchema(YTypeFactory f, BoshModels models) {
|
||||
super(f);
|
||||
this.asts = models.asts;
|
||||
this.astTypes = models.astTypes;
|
||||
this.cloudConfigProvider = new CachingModelProvider<>(models.cloudConfigProvider, CloudConfigModel.class);
|
||||
this.stemcellsProvider = new CachingModelProvider<>(models.stemcellsProvider, StemcellsModel.class);
|
||||
this.releasesProvider = new CachingModelProvider<>(models.releasesProvider, ReleasesModel.class);
|
||||
TYPE_UTIL = f.TYPE_UTIL;
|
||||
|
||||
t_string = f.yatomic("String");
|
||||
t_boolean = f.yenum("boolean", "true", "false");
|
||||
t_ne_string = f.yatomic("String")
|
||||
.parseWith(ValueParsers.NE_STRING);
|
||||
t_strings = f.yseq(t_string);
|
||||
t_any = f.yany("Object");
|
||||
t_params = f.ymap(t_string, t_any);
|
||||
t_string_params = f.ymap(t_string, t_string);
|
||||
t_pos_integer = f.yatomic("Positive Integer")
|
||||
.parseWith(ValueParsers.POS_INTEGER);
|
||||
t_strictly_pos_integer = f.yatomic("Strictly Positive Integer")
|
||||
.parseWith(ValueParsers.integerAtLeast(1));
|
||||
t_uuid = f.yatomic("UUID").parseWith(UUID::fromString);
|
||||
t_integer_or_range = f.yatomic("Integer or Range")
|
||||
.parseWith(BoshValueParsers.INTEGER_OR_RANGE);
|
||||
|
||||
V2_TOPLEVEL_TYPE = createV2Schema();
|
||||
V1_TOPLEVEL_TYPE = createV1Schema(V2_TOPLEVEL_TYPE);
|
||||
|
||||
@@ -345,25 +351,9 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
return TYPE_UTIL;
|
||||
}
|
||||
|
||||
private YTypedPropertyImpl prop(AbstractType beanType, String name, YType type) {
|
||||
YTypedPropertyImpl prop = f.yprop(name, type);
|
||||
prop.setDescriptionProvider(descriptionFor(beanType, name));
|
||||
return prop;
|
||||
}
|
||||
|
||||
public static Renderable descriptionFor(YType owner, String propName) {
|
||||
String typeName = owner.toString();
|
||||
return Renderables.fromClasspath(BoshDeploymentManifestSchema.class, "/desc/"+typeName+"/"+propName);
|
||||
}
|
||||
|
||||
private YTypedPropertyImpl addProp(AbstractType bean, String name, YType type) {
|
||||
return addProp(bean, bean, name, type);
|
||||
}
|
||||
|
||||
private YTypedPropertyImpl addProp(AbstractType superType, AbstractType bean, String name, YType type) {
|
||||
YTypedPropertyImpl p = prop(superType, name, type);
|
||||
bean.addProperty(p);
|
||||
return p;
|
||||
@Override
|
||||
protected String getResourcePathPrefix() {
|
||||
return "/deployment-manifest/";
|
||||
}
|
||||
|
||||
public Collection<YType> getDefinitionTypes() {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.bosh;
|
||||
|
||||
import org.springframework.ide.vscode.bosh.models.BoshModels;
|
||||
import org.springframework.ide.vscode.bosh.models.CloudConfigModel;
|
||||
import org.springframework.ide.vscode.bosh.models.DynamicModelProvider;
|
||||
import org.springframework.ide.vscode.bosh.models.ReleasesModel;
|
||||
@@ -41,7 +42,7 @@ import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureProvid
|
||||
public class BoshLanguageServer extends SimpleLanguageServer {
|
||||
|
||||
private final VscodeCompletionEngineAdapter completionEngine;
|
||||
private BoshDeploymentManifestSchema schema;
|
||||
private BoshSchemas schema;
|
||||
|
||||
public BoshLanguageServer(BoshCliConfig cliConfig,
|
||||
DynamicModelProvider<CloudConfigModel> cloudConfigProvider,
|
||||
@@ -49,11 +50,12 @@ public class BoshLanguageServer extends SimpleLanguageServer {
|
||||
DynamicModelProvider<ReleasesModel> releasesProvider
|
||||
) {
|
||||
super("vscode-bosh");
|
||||
YamlAstCache asts = new YamlAstCache();
|
||||
BoshModels models = new BoshModels(cloudConfigProvider, stemcellsProvider, releasesProvider);
|
||||
SimpleTextDocumentService documents = getTextDocumentService();
|
||||
|
||||
ASTTypeCache astTypeCache = new ASTTypeCache();
|
||||
schema = new BoshDeploymentManifestSchema(asts, astTypeCache, cloudConfigProvider, stemcellsProvider, releasesProvider);
|
||||
schema = new BoshSchemas(models);
|
||||
YamlAstCache asts = models.asts;
|
||||
ASTTypeCache astTypeCache = models.astTypes;
|
||||
|
||||
YamlStructureProvider structureProvider = YamlStructureProvider.DEFAULT;
|
||||
YamlAssistContextProvider contextProvider = new SchemaBasedYamlAssistContextProvider(schema);
|
||||
@@ -82,11 +84,7 @@ public class BoshLanguageServer extends SimpleLanguageServer {
|
||||
}
|
||||
|
||||
private void validateOnDocumentChange(IReconcileEngine engine, TextDocument doc) {
|
||||
if (LanguageId.BOSH_DEPLOYMENT.equals(doc.getLanguageId())) {
|
||||
validateWith(doc.getId(), engine);
|
||||
} else {
|
||||
validateWith(doc.getId(), IReconcileEngine.NULL);
|
||||
}
|
||||
validateWith(doc.getId(), engine);
|
||||
}
|
||||
|
||||
public void enableSnippets(boolean enable) {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.bosh;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.ide.vscode.bosh.models.BoshModels;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
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.YTypeUtil;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema;
|
||||
|
||||
public class BoshSchemas implements YamlSchema {
|
||||
|
||||
public final YTypeFactory f = new YTypeFactory()
|
||||
.enableTieredProposals(false)
|
||||
.suggestDeprecatedProperties(false);
|
||||
public BoshDeploymentManifestSchema getDeploymentSchema() {
|
||||
return deploymentSchema;
|
||||
}
|
||||
|
||||
private final BoshDeploymentManifestSchema deploymentSchema;
|
||||
private YTypeUtil typeUtil;
|
||||
|
||||
private final YType toplevelType;
|
||||
private BoshCloudConfigSchema cloudConfigSchema;
|
||||
|
||||
public BoshSchemas(BoshModels models) {
|
||||
this.typeUtil = f.TYPE_UTIL;
|
||||
this.deploymentSchema = new BoshDeploymentManifestSchema(f, models);
|
||||
this.cloudConfigSchema = new BoshCloudConfigSchema(f, models);
|
||||
toplevelType = f.contextAware("BoshSchemas", dc -> {
|
||||
return LanguageId.BOSH_CLOUD_CONFIG.equals(dc.getDocument().getLanguageId())
|
||||
? cloudConfigSchema.getTopLevelType()
|
||||
: deploymentSchema.getTopLevelType();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public YType getTopLevelType() {
|
||||
return toplevelType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YTypeUtil getTypeUtil() {
|
||||
return f.TYPE_UTIL;
|
||||
}
|
||||
|
||||
public Collection<Pair<YType,YType>> getDefAndRefTypes() {
|
||||
return deploymentSchema.getDefAndRefTypes();
|
||||
}
|
||||
|
||||
public Collection<YType> getDefinitionTypes() {
|
||||
return deploymentSchema.getDefinitionTypes();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.bosh;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.Renderables;
|
||||
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;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YTypedPropertyImpl;
|
||||
|
||||
/**
|
||||
* Some common utility methods useful in implementing Schemas.
|
||||
*
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class SchemaSupport {
|
||||
|
||||
protected final YTypeFactory f;
|
||||
|
||||
protected SchemaSupport(YTypeFactory f) {
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
protected String getResourcePathPrefix() {
|
||||
return "desc";
|
||||
}
|
||||
|
||||
protected YTypedPropertyImpl prop(AbstractType beanType, String name, YType type) {
|
||||
YTypedPropertyImpl prop = f.yprop(name, type);
|
||||
prop.setDescriptionProvider(descriptionFor(beanType, name));
|
||||
return prop;
|
||||
}
|
||||
|
||||
protected Renderable descriptionFor(YType owner, String propName) {
|
||||
String typeName = owner.toString();
|
||||
return Renderables.fromClasspath(BoshDeploymentManifestSchema.class, getResourcePathPrefix()+typeName+"/"+propName);
|
||||
}
|
||||
|
||||
protected YTypedPropertyImpl addProp(AbstractType bean, String name, YType type) {
|
||||
return addProp(bean, bean, name, type);
|
||||
}
|
||||
|
||||
protected YTypedPropertyImpl addProp(AbstractType superType, AbstractType bean, String name, YType type) {
|
||||
YTypedPropertyImpl p = prop(superType, name, type);
|
||||
bean.addProperty(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.bosh.models;
|
||||
|
||||
import org.springframework.ide.vscode.commons.yaml.ast.YamlAstCache;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache;
|
||||
|
||||
public class BoshModels {
|
||||
public final YamlAstCache asts = new YamlAstCache();
|
||||
public final ASTTypeCache astTypes = new ASTTypeCache();
|
||||
public final DynamicModelProvider<CloudConfigModel> cloudConfigProvider;
|
||||
public final DynamicModelProvider<StemcellsModel> stemcellsProvider;
|
||||
public final DynamicModelProvider<ReleasesModel> releasesProvider;
|
||||
|
||||
public BoshModels(DynamicModelProvider<CloudConfigModel> cloudConfigProvider,
|
||||
DynamicModelProvider<StemcellsModel> stemcellsProvider,
|
||||
DynamicModelProvider<ReleasesModel> releasesProvider) {
|
||||
this.cloudConfigProvider = cloudConfigProvider;
|
||||
this.stemcellsProvider = stemcellsProvider;
|
||||
this.releasesProvider = releasesProvider;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
@@ -39,6 +40,7 @@ public class CachingModelProvider<T> implements DynamicModelProvider<T> {
|
||||
private Class<T> modelInterface;
|
||||
|
||||
public CachingModelProvider(DynamicModelProvider<T> delegate, Class<T> modelInterface) {
|
||||
Assert.isNotNull(delegate);
|
||||
this.delegate = delegate;
|
||||
this.modelInterface = modelInterface;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user