Merge pull request #11 from github/cschleiden/auto-complete-string-constants
Auto-completion for string definitions
This commit is contained in:
@@ -12,5 +12,6 @@ export default {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ["ts", "js"]
|
moduleFileExtensions: ["ts", "js"],
|
||||||
|
reporters: ["default", "github-actions"]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ describe("completion", () => {
|
|||||||
const input = `on: push
|
const input = `on: push
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: [self-hosted, u|]`;
|
runs-on: [self-hosted, u|]`;
|
||||||
const result = await complete(...getPositionFromCursor(input));
|
const result = await complete(...getPositionFromCursor(input));
|
||||||
|
|
||||||
expect(result).not.toBeUndefined();
|
expect(result).not.toBeUndefined();
|
||||||
@@ -57,6 +57,39 @@ jobs:
|
|||||||
expect(result.length).toEqual(20);
|
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 () => {
|
it("map keys filter out existing values", async () => {
|
||||||
const input = `on: push
|
const input = `on: push
|
||||||
jobs:
|
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 {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 {MappingDefinition} from "@github/actions-workflow-parser/templates/schema/mapping-definition";
|
||||||
import {OneOfDefinition} from "@github/actions-workflow-parser/templates/schema/one-of-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 {getWorkflowSchema} from "@github/actions-workflow-parser/workflows/workflow-schema";
|
||||||
import {Value, ValueProvider} from "./config";
|
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 {
|
function definitionValueProvider(key: string, definitions: {[key: string]: Definition}): ValueProvider | undefined {
|
||||||
const def = definitions[key];
|
const def = definitions[key];
|
||||||
|
|
||||||
if (def instanceof MappingDefinition) {
|
if (def instanceof MappingDefinition) {
|
||||||
return mappingValueProvider(def);
|
return mappingValueProvider(def);
|
||||||
} else if (def instanceof OneOfDefinition) {
|
}
|
||||||
|
|
||||||
|
if (def instanceof OneOfDefinition) {
|
||||||
return oneOfValueProvider(def, definitions);
|
return oneOfValueProvider(def, definitions);
|
||||||
} else if (def instanceof BooleanDefinition) {
|
}
|
||||||
|
|
||||||
|
if (def instanceof BooleanDefinition) {
|
||||||
return () => stringsToValues(["true", "false"]);
|
return () => stringsToValues(["true", "false"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (def instanceof StringDefinition && def.constant) {
|
||||||
|
return () => stringsToValues([def.constant]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mappingValueProvider(mappingDefinition: MappingDefinition): ValueProvider {
|
function mappingValueProvider(mappingDefinition: MappingDefinition): ValueProvider {
|
||||||
|
|||||||
Generated
+6
-6
@@ -665,9 +665,9 @@
|
|||||||
"link": true
|
"link": true
|
||||||
},
|
},
|
||||||
"node_modules/@github/actions-workflow-parser": {
|
"node_modules/@github/actions-workflow-parser": {
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.12/b7b753fe96c1be36cc6f7952be76301ee3a10f12",
|
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.13/ff0fdf35ecf25145c56cb7d6d6b93b5a6b0774de",
|
||||||
"integrity": "sha512-tPtIiRpCilAGUygpCCBv7yEamw9/Te0SF1lBN5BljxLE0atb34bLMGR3yyKjE+S3R3xUf3jmNNcTiGRLIqnAfw==",
|
"integrity": "sha512-kQGTQZUrBqK0qK2AlSrljyhzjPh/LPcX+cg6Tc3ZmQmoLlqgIm9bN30iC5JDKzsY7j3otedQQ2YfniFmCRBWRA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@github/actions-expressions": "*",
|
"@github/actions-expressions": "*",
|
||||||
@@ -10927,9 +10927,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@github/actions-workflow-parser": {
|
"@github/actions-workflow-parser": {
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.12/b7b753fe96c1be36cc6f7952be76301ee3a10f12",
|
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.13/ff0fdf35ecf25145c56cb7d6d6b93b5a6b0774de",
|
||||||
"integrity": "sha512-tPtIiRpCilAGUygpCCBv7yEamw9/Te0SF1lBN5BljxLE0atb34bLMGR3yyKjE+S3R3xUf3jmNNcTiGRLIqnAfw==",
|
"integrity": "sha512-kQGTQZUrBqK0qK2AlSrljyhzjPh/LPcX+cg6Tc3ZmQmoLlqgIm9bN30iC5JDKzsY7j3otedQQ2YfniFmCRBWRA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@github/actions-expressions": "*",
|
"@github/actions-expressions": "*",
|
||||||
"yaml": "^2.0.0-8"
|
"yaml": "^2.0.0-8"
|
||||||
|
|||||||
Reference in New Issue
Block a user