Add descriptions to completion item detail
This commit is contained in:
@@ -286,6 +286,11 @@ jobs:
|
|||||||
"with",
|
"with",
|
||||||
"working-directory"
|
"working-directory"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Includes detail when available. Using continue-on-error as a sample here.
|
||||||
|
expect(result.map(x => x.detail)).toContain(
|
||||||
|
"Prevents a job from failing when a step fails. Set to true to allow a job to pass when this step fails."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("loose mapping keys have no completion suggestions", async () => {
|
it("loose mapping keys have no completion suggestions", async () => {
|
||||||
@@ -301,4 +306,27 @@ on:
|
|||||||
const result = await complete(...getPositionFromCursor(input));
|
const result = await complete(...getPositionFromCursor(input));
|
||||||
expect(result).toHaveLength(0);
|
expect(result).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("well known mapping keys have descriptions", async () => {
|
||||||
|
const input = `
|
||||||
|
o|
|
||||||
|
`;
|
||||||
|
const result = await complete(...getPositionFromCursor(input));
|
||||||
|
const onResult = result.find(x => x.label === "on");
|
||||||
|
expect(onResult).not.toBeUndefined();
|
||||||
|
expect(onResult?.detail).toEqual(
|
||||||
|
"The name of the GitHub event that triggers the workflow. You can provide a single event string, array of events, array of event types, or an event configuration map that schedules a workflow or restricts the execution of a workflow to specific files, tags, or branch changes. For a list of available events, see https://help.github.com/en/github/automating-your-workflow-with-github-actions/events-that-trigger-workflows."
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("event list includes descriptions when available ", async () => {
|
||||||
|
const input = `
|
||||||
|
on: [check_run, |]`;
|
||||||
|
const result = await complete(...getPositionFromCursor(input));
|
||||||
|
const dispatchResult = result.find(x => x.label === "workflow_dispatch");
|
||||||
|
expect(dispatchResult).not.toBeUndefined();
|
||||||
|
expect(dispatchResult?.detail).toEqual(
|
||||||
|
"You can now create workflows that are manually triggered with the new workflow_dispatch event. You will then see a 'Run workflow' button on the Actions tab, enabling you to easily trigger a run."
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -91,7 +91,11 @@ export async function complete(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const values = await getValues(token, keyToken, parent, valueProviderConfig, workflowContext);
|
const values = await getValues(token, keyToken, parent, valueProviderConfig, workflowContext);
|
||||||
return values.map(value => CompletionItem.create(value.label));
|
return values.map(value => {
|
||||||
|
const item = CompletionItem.create(value.label);
|
||||||
|
item.detail = value.description;
|
||||||
|
return item;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getValues(
|
async function getValues(
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export function definitionValues(def: Definition): Value[] {
|
|||||||
const schema = getWorkflowSchema();
|
const schema = getWorkflowSchema();
|
||||||
|
|
||||||
if (def instanceof MappingDefinition) {
|
if (def instanceof MappingDefinition) {
|
||||||
return mappingValues(def);
|
return mappingValues(def, schema.definitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def instanceof OneOfDefinition) {
|
if (def instanceof OneOfDefinition) {
|
||||||
@@ -24,7 +24,12 @@ export function definitionValues(def: Definition): Value[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (def instanceof StringDefinition && def.constant) {
|
if (def instanceof StringDefinition && def.constant) {
|
||||||
return stringsToValues([def.constant]);
|
return [
|
||||||
|
{
|
||||||
|
label: def.constant,
|
||||||
|
description: def.description
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def instanceof SequenceDefinition) {
|
if (def instanceof SequenceDefinition) {
|
||||||
@@ -37,10 +42,15 @@ export function definitionValues(def: Definition): Value[] {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function mappingValues(mappingDefinition: MappingDefinition): Value[] {
|
function mappingValues(mappingDefinition: MappingDefinition, definitions: {[key: string]: Definition}): Value[] {
|
||||||
const properties: Value[] = [];
|
const properties: Value[] = [];
|
||||||
for (const [key, value] of Object.entries(mappingDefinition.properties)) {
|
for (const [key, value] of Object.entries(mappingDefinition.properties)) {
|
||||||
properties.push({label: key, description: value.description});
|
let description: string | undefined;
|
||||||
|
if (value.type) {
|
||||||
|
const typeDef = definitions[value.type];
|
||||||
|
description = typeDef?.description;
|
||||||
|
}
|
||||||
|
properties.push({label: key, description: description});
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+3
@@ -9,6 +9,9 @@
|
|||||||
"actions-languageservice",
|
"actions-languageservice",
|
||||||
"actions-languageserver"
|
"actions-languageserver"
|
||||||
],
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@github/actions-workflow-parser": "^0.0.25"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"lerna": "^6.0.3"
|
"lerna": "^6.0.3"
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -7,5 +7,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"lerna": "^6.0.3"
|
"lerna": "^6.0.3"
|
||||||
},
|
},
|
||||||
"name": "actions-languageservices"
|
"name": "actions-languageservices",
|
||||||
|
"dependencies": {
|
||||||
|
"@github/actions-workflow-parser": "^0.0.25"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user