Better handle 'driver' property in semver resource
This commit is contained in:
@@ -112,12 +112,12 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
|
||||
if (CollectionUtil.hasElements(allProperties)) {
|
||||
List<List<YTypedProperty>> tieredProperties = sortIntoTiers(allProperties);
|
||||
Set<String> definedProps = dynamicCtxt.getDefinedProperties();
|
||||
List<ICompletionProposal> proposals = new ArrayList<>();
|
||||
for (List<YTypedProperty> thisTier : tieredProperties) {
|
||||
List<YTypedProperty> undefinedProps = thisTier.stream()
|
||||
.filter(p -> !definedProps.contains(p.getName()))
|
||||
.collect(Collectors.toList());
|
||||
if (!undefinedProps.isEmpty()) {
|
||||
List<ICompletionProposal> proposals = new ArrayList<>();
|
||||
for (YTypedProperty p : undefinedProps) {
|
||||
String name = p.getName();
|
||||
double score = FuzzyMatcher.matchScore(query, name);
|
||||
@@ -137,9 +137,13 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
|
||||
);
|
||||
}
|
||||
}
|
||||
return proposals;
|
||||
}
|
||||
//We should only move on to the next tier if all required properties in this tier are defined.
|
||||
if (undefinedProps.stream().anyMatch(p -> p.isRequired())) {
|
||||
return proposals; //stop here, take no more from next tier!
|
||||
}
|
||||
}
|
||||
return proposals;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -147,7 +151,7 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
|
||||
/**
|
||||
* Divides a given list of properties into tiers of decreasing significance. Property tiering
|
||||
* is a mechanism to reduce 'noise' in content assist proposals. Only properties of the
|
||||
* first tier that some still undefined properties will be used to generate proposals.
|
||||
* first X tiers will be used, until those tiers no longer have undefined required properties.
|
||||
* <p>
|
||||
* This allows, for example, to only suggest a 'name' property when starting to define
|
||||
* a new named entity. This is what a sane user would probably want, even though
|
||||
|
||||
@@ -772,7 +772,7 @@ public class YTypeFactory {
|
||||
|
||||
@Override
|
||||
public boolean isRequired() {
|
||||
return isRequired || isPrimary;
|
||||
return isRequired;
|
||||
}
|
||||
|
||||
public void isDeprecated(boolean isDeprecated) {
|
||||
@@ -784,8 +784,16 @@ public class YTypeFactory {
|
||||
return this.isDeprecated;
|
||||
}
|
||||
|
||||
public YTypedPropertyImpl isPrimary(boolean b) {
|
||||
this.isPrimary = b;
|
||||
|
||||
public YTypedPropertyImpl isPrimary(boolean primary) {
|
||||
this.isPrimary = primary;
|
||||
this.isRequired = primary;
|
||||
return this;
|
||||
}
|
||||
|
||||
public YTypedPropertyImpl isPrimary(boolean primary, boolean required) {
|
||||
this.isPrimary = primary;
|
||||
this.isRequired = required;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface YTypedProperty {
|
||||
String getName();
|
||||
YType getType();
|
||||
Renderable getDescription();
|
||||
default boolean isRequired() { return isPrimary() || false; }
|
||||
default boolean isRequired() { return false; }
|
||||
default boolean isDeprecated() { return false; }
|
||||
default boolean isPrimary() { return false; }
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
}
|
||||
}).treatAsBean();
|
||||
addProp(source, "initial_version", t_semver);
|
||||
addProp(source, "driver", f.yenum("SemverDriver", "git", "s3", "swift"));
|
||||
addProp(source, "driver", f.yenum("SemverDriver", "git", "s3", "swift")).isPrimary(true, false);
|
||||
for (AbstractType s : driverSpecificSources) {
|
||||
for (YTypedProperty p : source.getProperties()) {
|
||||
s.addProperty(p);
|
||||
|
||||
@@ -2126,6 +2126,115 @@ public class ConcourseEditorTest {
|
||||
editor.assertHoverContains("git_user", "The git identity to use");
|
||||
}
|
||||
|
||||
@Test public void semverResourceSourcePrimaryContentAssist() throws Exception {
|
||||
|
||||
//S3 completions
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
"resources:\n" +
|
||||
"- name: fff\n" +
|
||||
" type: semver\n" +
|
||||
" source:\n" +
|
||||
" <*>"
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
"bucket: <*>",
|
||||
"driver: <*>"
|
||||
);
|
||||
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
"resources:\n" +
|
||||
"- name: fff\n" +
|
||||
" type: semver\n" +
|
||||
" source:\n" +
|
||||
" driver: s3\n" +
|
||||
" <*>"
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
"bucket: <*>"
|
||||
);
|
||||
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
"resources:\n" +
|
||||
"- name: fff\n" +
|
||||
" type: semver\n" +
|
||||
" source:\n" +
|
||||
" driver: s3\n" +
|
||||
" bucket: some-bucket\n" +
|
||||
" <*>"
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
"access_key_id: <*>",
|
||||
"key: <*>",
|
||||
"secret_access_key: <*>"
|
||||
);
|
||||
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
"resources:\n" +
|
||||
"- name: fff\n" +
|
||||
" type: semver\n" +
|
||||
" source:\n" +
|
||||
" bucket: some-bucket\n" +
|
||||
" <*>"
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
"access_key_id: <*>",
|
||||
"driver: <*>",
|
||||
"key: <*>",
|
||||
"secret_access_key: <*>"
|
||||
);
|
||||
|
||||
//git completions
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
"resources:\n" +
|
||||
"- name: fff\n" +
|
||||
" type: semver\n" +
|
||||
" source:\n" +
|
||||
" driver: git\n" +
|
||||
" <*>"
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
"uri: <*>"
|
||||
);
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
"resources:\n" +
|
||||
"- name: fff\n" +
|
||||
" type: semver\n" +
|
||||
" source:\n" +
|
||||
" driver: git\n" +
|
||||
" uri: blah\n" +
|
||||
" <*>"
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
"branch: <*>",
|
||||
"file: <*>"
|
||||
);
|
||||
assertContextualCompletions(PLAIN_COMPLETION,
|
||||
"resources:\n" +
|
||||
"- name: fff\n" +
|
||||
" type: semver\n" +
|
||||
" source:\n" +
|
||||
" driver: git\n" +
|
||||
" uri: blah\n" +
|
||||
" branch: master\n" +
|
||||
" file: version-file\n"+
|
||||
" <*>"
|
||||
, /////////////
|
||||
"<*>"
|
||||
, // ==>
|
||||
"git_user: <*>",
|
||||
"initial_version: <*>",
|
||||
"password: <*>",
|
||||
"private_key: <*>",
|
||||
"username: <*>"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void semverS3ResourceSourceReconcileAndHovers() throws Exception {
|
||||
Editor editor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user