Auto-completion for string definitions
This commit is contained in:
@@ -25,7 +25,7 @@ describe("completion", () => {
|
||||
const input = `on: push
|
||||
jobs:
|
||||
build:
|
||||
runs-on: [self-hosted, u|]`;
|
||||
runs-on: [self-hosted, u|]`;
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result).not.toBeUndefined();
|
||||
@@ -57,6 +57,39 @@ jobs:
|
||||
expect(result.length).toEqual(20);
|
||||
});
|
||||
|
||||
it("string definition completion in sequence", async () => {
|
||||
const input = `on:
|
||||
release:
|
||||
types:
|
||||
- |`;
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
expect(result.map(x => x.label)).toEqual([
|
||||
"created",
|
||||
"deleted",
|
||||
"edited",
|
||||
"prereleased",
|
||||
"published",
|
||||
"released",
|
||||
"unpublished"
|
||||
]);
|
||||
});
|
||||
|
||||
it("string definition completion", async () => {
|
||||
const input = `on:
|
||||
release:
|
||||
types: |`;
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
expect(result.map(x => x.label)).toEqual([
|
||||
"created",
|
||||
"deleted",
|
||||
"edited",
|
||||
"prereleased",
|
||||
"published",
|
||||
"released",
|
||||
"unpublished"
|
||||
]);
|
||||
});
|
||||
|
||||
it("map keys filter out existing values", async () => {
|
||||
const input = `on: push
|
||||
jobs:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import {Definition} from "@github/actions-workflow-parser/templates/schema/definition";
|
||||
import {BooleanDefinition} from "@github/actions-workflow-parser/templates/schema/boolean-definition";
|
||||
import {Definition} from "@github/actions-workflow-parser/templates/schema/definition";
|
||||
import {MappingDefinition} from "@github/actions-workflow-parser/templates/schema/mapping-definition";
|
||||
import {OneOfDefinition} from "@github/actions-workflow-parser/templates/schema/one-of-definition";
|
||||
import {StringDefinition} from "@github/actions-workflow-parser/templates/schema/string-definition";
|
||||
import {getWorkflowSchema} from "@github/actions-workflow-parser/workflows/workflow-schema";
|
||||
import {Value, ValueProvider} from "./config";
|
||||
|
||||
@@ -37,13 +38,22 @@ export function defaultValueProviders(): {[key: string]: ValueProvider} {
|
||||
|
||||
function definitionValueProvider(key: string, definitions: {[key: string]: Definition}): ValueProvider | undefined {
|
||||
const def = definitions[key];
|
||||
|
||||
if (def instanceof MappingDefinition) {
|
||||
return mappingValueProvider(def);
|
||||
} else if (def instanceof OneOfDefinition) {
|
||||
}
|
||||
|
||||
if (def instanceof OneOfDefinition) {
|
||||
return oneOfValueProvider(def, definitions);
|
||||
} else if (def instanceof BooleanDefinition) {
|
||||
}
|
||||
|
||||
if (def instanceof BooleanDefinition) {
|
||||
return () => stringsToValues(["true", "false"]);
|
||||
}
|
||||
|
||||
if (def instanceof StringDefinition && def.constant) {
|
||||
return () => stringsToValues([def.constant]);
|
||||
}
|
||||
}
|
||||
|
||||
function mappingValueProvider(mappingDefinition: MappingDefinition): ValueProvider {
|
||||
|
||||
Reference in New Issue
Block a user