Merge pull request #159 from github/thyeggman/reusable-workflow-outputs
Implement hover support for reusable workflow outputs
This commit is contained in:
@@ -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 {WorkflowContext} from "../context/workflow-context";
|
||||
import {TokenResult} from "../utils/find-token";
|
||||
|
||||
@@ -2,7 +2,7 @@ import {hover} from "./hover";
|
||||
import {testHoverConfig} from "./hover.test";
|
||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||
|
||||
describe("hover on reusable workflows", () => {
|
||||
describe("hover.reusable-workflow", () => {
|
||||
it("hover on job input with description", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
@@ -34,4 +34,23 @@ jobs:
|
||||
expect(result).not.toBeUndefined();
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export async function hover(document: TextDocument, position: Position, config?:
|
||||
|
||||
if (tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) {
|
||||
let description = getReusableWorkflowInputDescription(workflowContext, tokenResult);
|
||||
description = appendContext(token, description);
|
||||
description = appendContext(description, token.definitionInfo?.allowedContext);
|
||||
return {
|
||||
contents: description,
|
||||
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);
|
||||
description = appendContext(token, description);
|
||||
description = appendContext(description, token.definitionInfo?.allowedContext);
|
||||
|
||||
return {
|
||||
contents: description,
|
||||
@@ -107,8 +107,7 @@ export async function hover(document: TextDocument, position: Position, config?:
|
||||
} satisfies Hover;
|
||||
}
|
||||
|
||||
function appendContext(token: TemplateToken, description: string) {
|
||||
const allowedContext = token.definitionInfo?.allowedContext;
|
||||
function appendContext(description: string, allowedContext?: string[]) {
|
||||
if (allowedContext && allowedContext?.length > 0) {
|
||||
// Only add padding if there is a description
|
||||
description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${allowedContext.join(", ")}`;
|
||||
|
||||
Reference in New Issue
Block a user