145545705 - Add symbol navigation to app name

This commit is contained in:
nsingh
2017-07-24 14:53:57 -07:00
parent b3feca3b5b
commit 7980908086
3 changed files with 43 additions and 5 deletions

View File

@@ -48,9 +48,10 @@ 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.TypeBasedYamlSymbolHandler;
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaBasedReconcileEngine;
import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;
import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema;
import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureProvider;
import org.yaml.snakeyaml.Yaml;
@@ -60,7 +61,7 @@ import com.google.common.collect.ImmutableSet;
public class ManifestYamlLanguageServer extends SimpleLanguageServer {
private Yaml yaml = new Yaml();
private YamlSchema schema;
private ManifestYmlSchema schema;
private CFTargetCache cfTargetCache;
private final CloudFoundryClientFactory cfClientFactory;
private final CfClientConfig cfClientConfig;
@@ -91,7 +92,11 @@ public class ManifestYamlLanguageServer 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);
YamlSchemaBasedReconcileEngine engine = new YamlSchemaBasedReconcileEngine(parser, schema, quickfixes);
ASTTypeCache astTypeCache = new ASTTypeCache();
engine.setTypeCollector(astTypeCache);
documents.onDocumentSymbol(new TypeBasedYamlSymbolHandler(documents, astTypeCache, schema.getDefinitionTypes()));
documents.onDidChangeContent(params -> {
validateOnDocumentChange(engine, params.getDocument());

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Pivotal, Inc.
* Copyright (c) 2016, 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
@@ -36,6 +36,7 @@ import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;
import org.springframework.ide.vscode.commons.yaml.schema.YamlSchema;
import org.yaml.snakeyaml.nodes.Node;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
/**
@@ -50,6 +51,9 @@ public final class ManifestYmlSchema implements YamlSchema {
private final YTypeUtil TYPE_UTIL;
public final AbstractType t_route_string;
private final YAtomicType t_application_name;
private ImmutableList<YType> definitionTypes = null;
private static final Set<String> TOPLEVEL_EXCLUDED = ImmutableSet.of(
"name", "host", "hosts", "routes"
@@ -144,6 +148,10 @@ public final class ManifestYmlSchema implements YamlSchema {
YAtomicType t_boolean = f.yenum("boolean", "true", "false");
YAtomicType t_ne_string = f.yatomic("String");
t_ne_string.parseWith(ValueParsers.NE_STRING);
t_application_name = f.yatomic("ApplicationName");
t_application_name.parseWith(ValueParsers.NE_STRING);
YType t_string = f.yatomic("String");
t_route_string = f.yatomic("RouteUri")
@@ -187,7 +195,7 @@ public final class ManifestYmlSchema implements YamlSchema {
f.yprop("hosts", f.yseq(t_host)),
f.yprop("instances", t_strictly_pos_integer),
f.yprop("memory", t_memory),
f.yprop("name", t_ne_string).isRequired(true),
f.yprop("name", t_application_name).isRequired(true),
f.yprop("no-hostname", t_boolean),
f.yprop("no-route", t_boolean),
f.yprop("path", t_path),
@@ -227,4 +235,12 @@ public final class ManifestYmlSchema implements YamlSchema {
public YTypeUtil getTypeUtil() {
return TYPE_UTIL;
}
public Collection<YType> getDefinitionTypes() {
// These are the types of "interest" for symbol navigation.
if (definitionTypes==null) {
definitionTypes = ImmutableList.of(t_application_name);
}
return definitionTypes;
}
}

View File

@@ -1464,6 +1464,23 @@ public class ManifestYamlEditorTest {
);
}
@Test public void gotoSymbolInPipeline() throws Exception {
Editor editor = harness.newEditor(
"applications:\n" +
"- name: my-app\n" +
" routes:\n" +
" - route: myapp.org\n" +
"- name: app2\n" +
" routes:\n" +
" - route: my-route.org"
);
editor.assertDocumentSymbols(
"my-app|Application",
"app2|Application"
);
}
@Test public void contentAssistInsideRouteDomain() throws Exception {
Editor editor;