Goto symbol for instance_groups
This commit is contained in:
@@ -10,12 +10,14 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.bosh;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.Renderables;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParser;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParsers;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YType;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory;
|
||||
@@ -29,6 +31,8 @@ import org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraints;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
@@ -43,6 +47,7 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
|
||||
private static final ImmutableSet<String> DEPRECATED_V1_PROPS = ImmutableSet.of("resource_pools", "networks", "compilation", "jobs", "disk_pools", "cloud_provider");
|
||||
private static final ImmutableSet<String> SHARED_V1_V2_PROPS = ImmutableSet.of("name", "director_uuid", "releases", "update", "properties");
|
||||
private Collection<YType> DEFINITION_TYPES = 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()
|
||||
@@ -65,6 +70,7 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
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);
|
||||
private YAtomicType t_instance_group_name_def;
|
||||
|
||||
public BoshDeploymentManifestSchema() {
|
||||
TYPE_UTIL = f.TYPE_UTIL;
|
||||
@@ -110,6 +116,9 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
YAtomicType t_network_name = f.yatomic("NetworkName"); //TODO: resolve from 'cloud config' https://www.pivotaltracker.com/story/show/148712155
|
||||
t_network_name.parseWith(ValueParsers.NE_STRING);
|
||||
|
||||
t_instance_group_name_def = f.yatomic("InstanceGroupName");
|
||||
t_instance_group_name_def.parseWith(ValueParsers.NE_STRING);
|
||||
|
||||
YAtomicType t_disk_type = f.yatomic("DiskType"); //TODO: resolve from 'cloud config' https://www.pivotaltracker.com/story/show/148704001
|
||||
t_disk_type.parseWith(ValueParsers.NE_STRING);
|
||||
|
||||
@@ -174,7 +183,7 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
addProp(t_job, "properties", t_params);
|
||||
|
||||
YBeanType t_instance_group = f.ybean("InstanceGroup");
|
||||
addProp(t_instance_group, "name", t_ne_string).isPrimary(true);
|
||||
addProp(t_instance_group, "name", t_instance_group_name_def).isPrimary(true);
|
||||
addProp(t_instance_group, "azs", f.yseq(t_az)).isRequired(true);
|
||||
addProp(t_instance_group, "instances", t_pos_integer).isRequired(true); //Strictly positive? Or zero is okay?
|
||||
addProp(t_instance_group, "jobs", f.yseq(t_job)).isRequired(true);
|
||||
@@ -245,4 +254,13 @@ public class BoshDeploymentManifestSchema implements YamlSchema {
|
||||
return p;
|
||||
}
|
||||
|
||||
public Collection<YType> getDefinitionTypes() {
|
||||
if (DEFINITION_TYPES==null) {
|
||||
DEFINITION_TYPES = ImmutableList.of(
|
||||
t_instance_group_name_def
|
||||
);
|
||||
}
|
||||
return DEFINITION_TYPES;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ import org.springframework.ide.vscode.commons.yaml.completion.YamlCompletionEngi
|
||||
import org.springframework.ide.vscode.commons.yaml.completion.YamlCompletionEngineOptions;
|
||||
import org.springframework.ide.vscode.commons.yaml.hover.YamlHoverInfoProvider;
|
||||
import org.springframework.ide.vscode.commons.yaml.quickfix.YamlQuickfixes;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.ITypeCollector;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.TypeBasedYamlSymbolHandler;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaBasedReconcileEngine;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema;
|
||||
import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureProvider;
|
||||
@@ -43,7 +46,7 @@ public class BoshLanguageServer extends SimpleLanguageServer {
|
||||
super("vscode-bosh");
|
||||
YamlASTProvider parser = new YamlParser(yaml);
|
||||
SimpleTextDocumentService documents = getTextDocumentService();
|
||||
YamlSchema schema = new BoshDeploymentManifestSchema();
|
||||
BoshDeploymentManifestSchema schema = new BoshDeploymentManifestSchema();
|
||||
|
||||
YamlStructureProvider structureProvider = YamlStructureProvider.DEFAULT;
|
||||
YamlAssistContextProvider contextProvider = new SchemaBasedYamlAssistContextProvider(schema);
|
||||
@@ -53,7 +56,10 @@ public class BoshLanguageServer extends SimpleLanguageServer {
|
||||
HoverInfoProvider infoProvider = new YamlHoverInfoProvider(parser, structureProvider, contextProvider);
|
||||
VscodeHoverEngine hoverEngine = new VscodeHoverEngineAdapter(this, infoProvider);
|
||||
YamlQuickfixes quickfixes = new YamlQuickfixes(getQuickfixRegistry(), getTextDocumentService(), structureProvider);
|
||||
IReconcileEngine engine = new YamlSchemaBasedReconcileEngine(parser, schema, quickfixes);
|
||||
ASTTypeCache astTypeCache = new ASTTypeCache();
|
||||
YamlSchemaBasedReconcileEngine engine = new YamlSchemaBasedReconcileEngine(parser, schema, quickfixes);
|
||||
engine.setTypeCollector(astTypeCache);
|
||||
documents.onDocumentSymbol(new TypeBasedYamlSymbolHandler(documents, astTypeCache, schema.getDefinitionTypes()));
|
||||
|
||||
documents.onDidChangeContent(params -> {
|
||||
validateOnDocumentChange(engine, params.getDocument());
|
||||
|
||||
@@ -643,4 +643,25 @@ public class BoshEditorTest {
|
||||
"networks|Deprecated: 'networks' is a V1 schema property"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void documentSymbols() throws Exception {
|
||||
Editor editor = harness.newEditor(
|
||||
"name: foo\n" +
|
||||
"instance_groups:\n" +
|
||||
"- name: foo-group\n" +
|
||||
" networks:\n" +
|
||||
" - name: the-network\n" +
|
||||
" static_ips: []\n" +
|
||||
" default: []\n" +
|
||||
"- name: bar-group\n" +
|
||||
" networks:\n" +
|
||||
" - name: the-network\n" +
|
||||
" static_ips: []\n" +
|
||||
" default: []\n"
|
||||
);
|
||||
editor.assertDocumentSymbols(
|
||||
"foo-group|InstanceGroup",
|
||||
"bar-group|InstanceGroup"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.concourse;
|
||||
package org.springframework.ide.vscode.commons.yaml.reconcile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -19,7 +19,6 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.ITypeCollector;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YType;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.concourse;
|
||||
package org.springframework.ide.vscode.commons.yaml.reconcile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -35,19 +35,20 @@ import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Finds symbols in a concourse document. This relies on type information cached
|
||||
* during reconcile and stored in the {@link ConcourseModel}. Therefore,
|
||||
* this handler only works if invoked after a reconcile.
|
||||
* Finds symbols in a yaml document based on type information cached
|
||||
* during reconcile and stored in the {@link ASTTypeCache}. Because
|
||||
* it relies on information computed during reconcile, this handler only
|
||||
* works if it is invoked after a reconcile.
|
||||
*
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class ConcourseDocumentSymbolHandler implements DocumentSymbolHandler {
|
||||
public class TypeBasedYamlSymbolHandler implements DocumentSymbolHandler {
|
||||
|
||||
private ASTTypeCache astTypeCache;
|
||||
private Set<YType> definitionTypes;
|
||||
private SimpleTextDocumentService documents;
|
||||
|
||||
public ConcourseDocumentSymbolHandler(SimpleTextDocumentService documents, ASTTypeCache astTypeCache, Collection<YType> definitionTypes) {
|
||||
public TypeBasedYamlSymbolHandler(SimpleTextDocumentService documents, ASTTypeCache astTypeCache, Collection<YType> definitionTypes) {
|
||||
Assert.isTrue(!definitionTypes.isEmpty()); // If there's no interesting types then you are better of using DocumentSymbolHandler.NO_SYMBOLS
|
||||
this.documents = documents;
|
||||
this.astTypeCache = astTypeCache;
|
||||
@@ -10,6 +10,8 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.yaml.schema;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.IntegerRange;
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
import org.springframework.ide.vscode.commons.yaml.ast.NodeUtil;
|
||||
import org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST;
|
||||
import org.springframework.ide.vscode.commons.yaml.path.YamlPath;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YType;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.ide.vscode.commons.yaml.completion.YamlCompletionEngi
|
||||
import org.springframework.ide.vscode.commons.yaml.completion.YamlCompletionEngineOptions;
|
||||
import org.springframework.ide.vscode.commons.yaml.hover.YamlHoverInfoProvider;
|
||||
import org.springframework.ide.vscode.commons.yaml.quickfix.YamlQuickfixes;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.TypeBasedYamlSymbolHandler;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaBasedReconcileEngine;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YType;
|
||||
@@ -74,7 +75,7 @@ public class ConcourseLanguageServer extends SimpleLanguageServer {
|
||||
reconcileEngine.setTypeCollector(models.getAstTypeCache());
|
||||
|
||||
this.symbolHandler = CollectionUtil.hasElements(definitionTypes)
|
||||
? new ConcourseDocumentSymbolHandler(documents, models.getAstTypeCache(), definitionTypes)
|
||||
? new TypeBasedYamlSymbolHandler(documents, models.getAstTypeCache(), definitionTypes)
|
||||
: DocumentSymbolHandler.NO_SYMBOLS;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,9 @@ import org.springframework.ide.vscode.commons.yaml.path.NodeCursor;
|
||||
import org.springframework.ide.vscode.commons.yaml.path.YamlPath;
|
||||
import org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment;
|
||||
import org.springframework.ide.vscode.commons.yaml.path.YamlTraversal;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems;
|
||||
import org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache.NodeTypes;
|
||||
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.YType;
|
||||
@@ -51,7 +53,6 @@ import org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;
|
||||
import org.springframework.ide.vscode.commons.yaml.util.Streams;
|
||||
import org.springframework.ide.vscode.concourse.ASTTypeCache.NodeTypes;
|
||||
import org.springframework.ide.vscode.concourse.util.StaleFallbackCache;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
Reference in New Issue
Block a user