From 798090808610df1862a682ed7e103473293f2c67 Mon Sep 17 00:00:00 2001 From: nsingh Date: Mon, 24 Jul 2017 14:53:57 -0700 Subject: [PATCH] 145545705 - Add symbol navigation to app name --- .../yaml/ManifestYamlLanguageServer.java | 11 +++++++--- .../manifest/yaml/ManifestYmlSchema.java | 20 +++++++++++++++++-- .../manifest/yaml/ManifestYamlEditorTest.java | 17 ++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java b/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java index b71f8596c..8bf3de536 100644 --- a/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java +++ b/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java @@ -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()); diff --git a/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java b/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java index 3d6fa9bc6..7c85119fa 100644 --- a/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java +++ b/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java @@ -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 definitionTypes = null; private static final Set 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 getDefinitionTypes() { + // These are the types of "interest" for symbol navigation. + if (definitionTypes==null) { + definitionTypes = ImmutableList.of(t_application_name); + } + return definitionTypes; + } } diff --git a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java index 383825933..1a8cea040 100644 --- a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java +++ b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java @@ -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;