Goto Definition for resource_types
This commit is contained in:
@@ -19,7 +19,6 @@ import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||
import org.springframework.ide.vscode.commons.languageserver.definition.SimpleDefinitionFinder;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
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;
|
||||
@@ -38,7 +37,7 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<ConcourseL
|
||||
|
||||
private final ConcourseModel models;
|
||||
private ASTTypeCache astTypes;
|
||||
private Map<YType, Handler> findersByType = new HashMap<>();
|
||||
private Map<YType, Handler> handlers = new HashMap<>();
|
||||
|
||||
public ConcourseDefinitionFinder(ConcourseLanguageServer server, ConcourseModel models, PipelineYmlSchema schema) {
|
||||
super(server);
|
||||
@@ -46,6 +45,7 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<ConcourseL
|
||||
this.astTypes = models.getAstTypeCache();
|
||||
findByPath(schema.t_resource_name, ConcourseModel.RESOURCE_NAMES_PATH);
|
||||
findByPath(schema.t_job_name, ConcourseModel.JOB_NAMES_PATH);
|
||||
findByPath(schema.t_resource_type_name, ConcourseModel.RESOURCE_TYPE_NAMES_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<ConcourseL
|
||||
}
|
||||
return Flux.empty();
|
||||
};
|
||||
findersByType.put(refType, handler);
|
||||
handlers.put(refType, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +82,7 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<ConcourseL
|
||||
if (refNode!=null) {
|
||||
YType type = astTypes.getType(ast, refNode);
|
||||
if (type!=null) {
|
||||
Handler handler = findersByType.get(type);
|
||||
Handler handler = handlers.get(type);
|
||||
if (handler!=null) {
|
||||
return handler.handle(refNode, doc, ast);
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class ConcourseDefinitionFinder extends SimpleDefinitionFinder<ConcourseL
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Flux.error(e);
|
||||
Log.log(e);
|
||||
}
|
||||
return Flux.empty();
|
||||
}
|
||||
|
||||
@@ -10,20 +10,14 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.concourse;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.EnumValueParser;
|
||||
import org.springframework.ide.vscode.commons.util.RegexpParser;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParser;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.SchemaContextAware;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
/**
|
||||
* Methods and constants to create/get parsers for some atomic types
|
||||
|
||||
@@ -93,10 +93,10 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
|
||||
public final YAtomicType t_resource_name;
|
||||
public final YAtomicType t_job_name;
|
||||
public final YAtomicType t_resource_type_name;
|
||||
|
||||
private final ResourceTypeRegistry resourceTypes = new ResourceTypeRegistry();
|
||||
|
||||
|
||||
public PipelineYmlSchema(ConcourseModel models) {
|
||||
TYPE_UTIL = f.TYPE_UTIL;
|
||||
|
||||
@@ -112,7 +112,7 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
YAtomicType t_image_type = f.yatomic("ImageType");
|
||||
t_image_type.addHints("docker_image");
|
||||
|
||||
YAtomicType t_resource_type_name = f.yenumFromHints("ResourceType Name",
|
||||
t_resource_type_name = f.yenumFromHints("ResourceType Name",
|
||||
(parseString, validValues) -> {
|
||||
return "The '"+parseString+"' Resource Type does not exist. Existing types: "+validValues;
|
||||
},
|
||||
|
||||
@@ -1338,6 +1338,21 @@ public class PipelineYamlEditorTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gotoResourceTypeDefinition() throws Exception {
|
||||
Editor editor = harness.newEditor(
|
||||
"resource_types:\n" +
|
||||
"- name: slack-notification\n" +
|
||||
" type: docker_image\n" +
|
||||
"resources:\n" +
|
||||
"- name: zazazee\n" +
|
||||
" type: slack-notification\n"
|
||||
);
|
||||
editor.assertGotoDefinition(editor.positionOf("type: slack-notification", "slack-notification"),
|
||||
editor.rangeOf("- name: slack-notification", "slack-notification")
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void reconcileResourceTypeNames() throws Exception {
|
||||
String userDefinedResourceTypesSnippet =
|
||||
"resource_types:\n" +
|
||||
|
||||
Reference in New Issue
Block a user