Merge pull request #159 from github/thyeggman/reusable-workflow-outputs

Implement hover support for reusable workflow outputs
This commit is contained in:
Jacob Wallraff
2023-02-22 09:43:15 -08:00
committed by GitHub
3 changed files with 24 additions and 6 deletions
@@ -1,4 +1,4 @@
import {isMapping, isString, ParseWorkflowResult} from "@github/actions-workflow-parser"; import {isMapping, isString} from "@github/actions-workflow-parser";
import {DESCRIPTION} from "@github/actions-workflow-parser/templates/template-constants"; import {DESCRIPTION} from "@github/actions-workflow-parser/templates/template-constants";
import {WorkflowContext} from "../context/workflow-context"; import {WorkflowContext} from "../context/workflow-context";
import {TokenResult} from "../utils/find-token"; import {TokenResult} from "../utils/find-token";
@@ -2,7 +2,7 @@ import {hover} from "./hover";
import {testHoverConfig} from "./hover.test"; import {testHoverConfig} from "./hover.test";
import {getPositionFromCursor} from "./test-utils/cursor-position"; import {getPositionFromCursor} from "./test-utils/cursor-position";
describe("hover on reusable workflows", () => { describe("hover.reusable-workflow", () => {
it("hover on job input with description", async () => { it("hover on job input with description", async () => {
const input = ` const input = `
on: push on: push
@@ -34,4 +34,23 @@ jobs:
expect(result).not.toBeUndefined(); expect(result).not.toBeUndefined();
expect(result?.contents).toEqual("**Context:** github, inputs, vars, needs, strategy, matrix"); expect(result?.contents).toEqual("**Context:** github, inputs, vars, needs, strategy, matrix");
}); });
it("hover on job output with description", async () => {
const input = `
on: push
jobs:
build:
uses: ./reusable-workflow-with-outputs.yaml
echo_outputs:
runs-on: ubuntu-latest
needs: build
steps:
- run: echo \${{ needs.build.outputs.bu|ild_id }}
`;
const result = await hover(...getPositionFromCursor(input), testHoverConfig("", "string-steps-context"));
expect(result).not.toBeUndefined();
expect(result?.contents).toEqual("The resulting build ID");
});
}); });
+3 -4
View File
@@ -91,7 +91,7 @@ export async function hover(document: TextDocument, position: Position, config?:
if (tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) { if (tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) {
let description = getReusableWorkflowInputDescription(workflowContext, tokenResult); let description = getReusableWorkflowInputDescription(workflowContext, tokenResult);
description = appendContext(token, description); description = appendContext(description, token.definitionInfo?.allowedContext);
return { return {
contents: description, contents: description,
range: mapRange(token.range) range: mapRange(token.range)
@@ -99,7 +99,7 @@ export async function hover(document: TextDocument, position: Position, config?:
} }
let description = await getDescription(config, workflowContext, token, tokenResult.path); let description = await getDescription(config, workflowContext, token, tokenResult.path);
description = appendContext(token, description); description = appendContext(description, token.definitionInfo?.allowedContext);
return { return {
contents: description, contents: description,
@@ -107,8 +107,7 @@ export async function hover(document: TextDocument, position: Position, config?:
} satisfies Hover; } satisfies Hover;
} }
function appendContext(token: TemplateToken, description: string) { function appendContext(description: string, allowedContext?: string[]) {
const allowedContext = token.definitionInfo?.allowedContext;
if (allowedContext && allowedContext?.length > 0) { if (allowedContext && allowedContext?.length > 0) {
// Only add padding if there is a description // Only add padding if there is a description
description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${allowedContext.join(", ")}`; description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${allowedContext.join(", ")}`;