Completions for 'resourceName' in put and get task

This commit is contained in:
Kris De Volder
2016-12-20 21:01:17 -08:00
parent ae9e3591de
commit 3837c8a9e4
5 changed files with 54 additions and 9 deletions

View File

@@ -143,7 +143,7 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
}
private List<ICompletionProposal> getValueCompletions(YamlDocument doc, int offset, String query) {
YValueHint[] values = typeUtil.getHintValues(type);
YValueHint[] values = typeUtil.getHintValues(type, getSchemaContext());
if (values!=null) {
ArrayList<ICompletionProposal> completions = new ArrayList<>();
for (YValueHint value : values) {

View File

@@ -97,8 +97,8 @@ public class YTypeFactory {
}
@Override
public YValueHint[] getHintValues(YType type) {
return ((AbstractType)type).getHintValues();
public YValueHint[] getHintValues(YType type, DynamicSchemaContext dc) {
return ((AbstractType)type).getHintValues(dc);
}
@Override
@@ -143,7 +143,7 @@ public class YTypeFactory {
private List<YTypedProperty> propertyList = new ArrayList<>();
private final List<YValueHint> hints = new ArrayList<>();
private Map<String, YTypedProperty> cachedPropertyMap;
private Provider<Collection<YValueHint>> hintProvider;
private SchemaContextAware<Collection<YValueHint>> hintProvider;
public boolean isSequenceable() {
return false;
@@ -166,11 +166,15 @@ public class YTypeFactory {
}
public void addHintProvider(Provider<Collection<YValueHint>> hintProvider) {
addHintProvider((DynamicSchemaContext dc) -> hintProvider.get());
}
public void addHintProvider(SchemaContextAware<Collection<YValueHint>> hintProvider) {
this.hintProvider = hintProvider;
}
public YValueHint[] getHintValues() {
Collection<YValueHint> providerHints = hintProvider != null ? hintProvider.get() : null;
public YValueHint[] getHintValues(DynamicSchemaContext dc) {
Collection<YValueHint> providerHints = hintProvider != null ? hintProvider.withContext(dc) : null;
if (providerHints == null || providerHints.isEmpty()) {
return hints.toArray(new YValueHint[hints.size()]);
@@ -585,8 +589,8 @@ public class YTypeFactory {
public YAtomicType yenum(String name, BiFunction<String, Collection<String>, String> errorMessageFormatter, SchemaContextAware<Collection<String>> values) {
YAtomicType t = yatomic(name);
t.addHintProvider(() -> {
Collection<String> strings = values.withContext(DynamicSchemaContext.NULL); //TODO: make this really context aware!
t.addHintProvider((dc) -> {
Collection<String> strings = values.withContext(dc);
return strings==null
? null
: strings.stream()

View File

@@ -29,7 +29,7 @@ public interface YTypeUtil {
boolean isSequencable(YType type);
boolean isBean(YType type);
YType getDomainType(YType type);
YValueHint[] getHintValues(YType yType);
YValueHint[] getHintValues(YType yType, DynamicSchemaContext dc);
String niceTypeName(YType type);
YType getKeyType(YType type);
ValueParser getValueParser(YType type, DynamicSchemaContext dc);

View File

@@ -406,6 +406,39 @@ public class PipelineYamlEditorTest {
"bogus-get|[sts4]",
"bogus-put|[sts4]"
);
}
@Test
public void completionsResourceReferences() throws Exception {
assertContextualCompletions(
"resources:\n" +
"- name: sts4\n" +
"- name: repo-a\n" +
"- name: repo-b\n" +
"jobs:\n" +
"- name: job1\n" +
" plan:\n" +
" - get: <*>\n"
, ////////////////////
"<*>"
, // =>
"repo-a<*>", "repo-b<*>", "sts4<*>"
);
assertContextualCompletions(
"resources:\n" +
"- name: sts4\n" +
"- name: repo-a\n" +
"- name: repo-b\n" +
"jobs:\n" +
"- name: job1\n" +
" plan:\n" +
" - put: <*>\n"
, ////////////////////
"r<*>"
, // =>
"repo-a<*>", "repo-b<*>"
);
}

View File

@@ -3,6 +3,14 @@ resources:
type: git
source:
repository: https://github.com/kdvolder/somestuff
- name: other-repo
type: git
source:
repository: https://github.com/kdvolder/somestuff
- name: more-stuff
type: git
source:
repository: https://github.com/kdvolder/somestuff
jobs:
- name: job1
plan: