Content assist and checking for 'location' values in time resource
This commit is contained in:
@@ -23,4 +23,8 @@ public interface ValueParser {
|
|||||||
* that the String is not the format this parser expects.
|
* that the String is not the format this parser expects.
|
||||||
*/
|
*/
|
||||||
Object parse(String str) throws Exception;
|
Object parse(String str) throws Exception;
|
||||||
|
|
||||||
|
static ValueParser of(ValueParser x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -185,8 +185,9 @@ public class YTypeFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHintProvider(Callable<Collection<YValueHint>> hintProvider) {
|
public AbstractType addHintProvider(Callable<Collection<YValueHint>> hintProvider) {
|
||||||
addHintProvider((DynamicSchemaContext dc) -> hintProvider);
|
addHintProvider((DynamicSchemaContext dc) -> hintProvider);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractType addHintProvider(SchemaContextAware<Callable<Collection<YValueHint>>> hintProvider) {
|
public AbstractType addHintProvider(SchemaContextAware<Callable<Collection<YValueHint>>> hintProvider) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.springframework.ide.vscode.concourse;
|
package org.springframework.ide.vscode.concourse;
|
||||||
|
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -17,11 +18,14 @@ import org.springframework.ide.vscode.commons.languageserver.LanguageIds;
|
|||||||
import org.springframework.ide.vscode.commons.util.MimeTypes;
|
import org.springframework.ide.vscode.commons.util.MimeTypes;
|
||||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||||
import org.springframework.ide.vscode.commons.util.Renderables;
|
import org.springframework.ide.vscode.commons.util.Renderables;
|
||||||
|
import org.springframework.ide.vscode.commons.util.ValueParseException;
|
||||||
|
import org.springframework.ide.vscode.commons.util.ValueParser;
|
||||||
import org.springframework.ide.vscode.commons.util.ValueParsers;
|
import org.springframework.ide.vscode.commons.util.ValueParsers;
|
||||||
import org.springframework.ide.vscode.commons.yaml.ast.NodeUtil;
|
import org.springframework.ide.vscode.commons.yaml.ast.NodeUtil;
|
||||||
import org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST;
|
import org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST;
|
||||||
import org.springframework.ide.vscode.commons.yaml.path.YamlPath;
|
import org.springframework.ide.vscode.commons.yaml.path.YamlPath;
|
||||||
import org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment;
|
import org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment;
|
||||||
|
import org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint;
|
||||||
import org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext;
|
import org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext;
|
||||||
import org.springframework.ide.vscode.commons.yaml.schema.YType;
|
import org.springframework.ide.vscode.commons.yaml.schema.YType;
|
||||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory;
|
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory;
|
||||||
@@ -106,6 +110,20 @@ public class PipelineYmlSchema implements YamlSchema {
|
|||||||
.parseWith(ConcourseValueParsers.DURATION);
|
.parseWith(ConcourseValueParsers.DURATION);
|
||||||
public final YType t_time_of_day = f.yatomic("TimeOfDay")
|
public final YType t_time_of_day = f.yatomic("TimeOfDay")
|
||||||
.parseWith(ConcourseValueParsers.TIME_OF_DAY);
|
.parseWith(ConcourseValueParsers.TIME_OF_DAY);
|
||||||
|
public final YType t_location = f.yatomic("Location")
|
||||||
|
//Note: we could have used f.yenum here too. But it saves memory if we don't keep the large set of ValueHints in memory.
|
||||||
|
// That's why we attach custom hint provider and parser here that do essentially the same thing.
|
||||||
|
.addHintProvider(() -> {
|
||||||
|
return ZoneId.getAvailableZoneIds().stream()
|
||||||
|
.map(BasicYValueHint::new)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
})
|
||||||
|
.parseWith(ValueParser.of((zoneId) -> {
|
||||||
|
if (!ZoneId.getAvailableZoneIds().contains(zoneId)) {
|
||||||
|
throw new ValueParseException("Unknown 'Location'. See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones");
|
||||||
|
}
|
||||||
|
return zoneId;
|
||||||
|
}));
|
||||||
|
|
||||||
public final AbstractType task;
|
public final AbstractType task;
|
||||||
|
|
||||||
@@ -542,7 +560,7 @@ public class PipelineYmlSchema implements YamlSchema {
|
|||||||
{
|
{
|
||||||
AbstractType source = f.ybean("TimeSource");
|
AbstractType source = f.ybean("TimeSource");
|
||||||
addProp(source, "interval", t_duration);
|
addProp(source, "interval", t_duration);
|
||||||
addProp(source, "location", t_ne_string);
|
addProp(source, "location", t_location);
|
||||||
addProp(source, "start", t_time_of_day);
|
addProp(source, "start", t_time_of_day);
|
||||||
addProp(source, "stop", t_time_of_day);
|
addProp(source, "stop", t_time_of_day);
|
||||||
addProp(source, "days", f.yseq(t_day));
|
addProp(source, "days", f.yseq(t_day));
|
||||||
|
|||||||
@@ -778,6 +778,17 @@ public class ConcourseEditorTest {
|
|||||||
"Tuesday<*>",
|
"Tuesday<*>",
|
||||||
"Wednesday<*>"
|
"Wednesday<*>"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assertContextualCompletions(
|
||||||
|
"resources:\n" +
|
||||||
|
"- name: every5minutes\n" +
|
||||||
|
" type: time\n" +
|
||||||
|
" location: <*>"
|
||||||
|
, // ======================
|
||||||
|
"Van<*>"
|
||||||
|
, // =>
|
||||||
|
"America/Vancouver"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void timeResourceSourceReconcile() throws Exception {
|
@Test public void timeResourceSourceReconcile() throws Exception {
|
||||||
@@ -788,7 +799,7 @@ public class ConcourseEditorTest {
|
|||||||
"- name: every5minutes\n" +
|
"- name: every5minutes\n" +
|
||||||
" type: time\n" +
|
" type: time\n" +
|
||||||
" source:\n" +
|
" source:\n" +
|
||||||
" location: PST\n" +
|
" location: PST8PDT\n" +
|
||||||
" start: 7AM\n" +
|
" start: 7AM\n" +
|
||||||
" stop: 8AM\n" +
|
" stop: 8AM\n" +
|
||||||
" interval: 5m\n" +
|
" interval: 5m\n" +
|
||||||
@@ -802,6 +813,7 @@ public class ConcourseEditorTest {
|
|||||||
"- name: every5minutes\n" +
|
"- name: every5minutes\n" +
|
||||||
" type: time\n" +
|
" type: time\n" +
|
||||||
" source:\n" +
|
" source:\n" +
|
||||||
|
" location: some-location\n" +
|
||||||
" start: the-start-time\n" +
|
" start: the-start-time\n" +
|
||||||
" stop: the-stop-time\n" +
|
" stop: the-stop-time\n" +
|
||||||
" interval: the-interval\n" +
|
" interval: the-interval\n" +
|
||||||
@@ -810,6 +822,7 @@ public class ConcourseEditorTest {
|
|||||||
" - Someday\n"
|
" - Someday\n"
|
||||||
);
|
);
|
||||||
editor.assertProblems(
|
editor.assertProblems(
|
||||||
|
"some-location|Unknown 'Location'",
|
||||||
"the-start-time|not a valid 'Time'",
|
"the-start-time|not a valid 'Time'",
|
||||||
"the-stop-time|not a valid 'Time'",
|
"the-stop-time|not a valid 'Time'",
|
||||||
"the-interval|not a valid 'Duration'",
|
"the-interval|not a valid 'Duration'",
|
||||||
|
|||||||
Reference in New Issue
Block a user