From d8d4a3f46a2ee7d2e64e45123f2aa805ff9f33c0 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Mon, 23 Jan 2023 16:20:59 -0500 Subject: [PATCH] Ensure inherited context is shown on hover --- actions-languageservice/src/hover.test.ts | 26 ++++++++++++++++++++++- actions-languageservice/src/hover.ts | 7 +++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/actions-languageservice/src/hover.test.ts b/actions-languageservice/src/hover.test.ts index 8581a27..a1c172c 100644 --- a/actions-languageservice/src/hover.test.ts +++ b/actions-languageservice/src/hover.test.ts @@ -95,6 +95,27 @@ jobs: expect(result).not.toBeUndefined(); expect(result?.contents).toEqual("Runs your workflow when you push a commit or tag."); }); + + + it("shows context inherited from parent nodes", async () => { + const input = ` +on: push +jobs: + build: + runs-on: [self-hosted] + steps: + - uses: actions/checkout@v2 + with: + ref|: main +`; + + const result = await hover(...getPositionFromCursor(input)); + expect(result).not.toBeUndefined(); + + // The `ref` is a `string` definition and inherits the context from `step-with` + const expected = "**Context:** github, inputs, vars, needs, strategy, matrix, secrets, steps, job, runner, env, hashFiles(1,255)" + expect(result?.contents).toEqual(expected); + }); }); describe("hover with description provider", () => { @@ -112,7 +133,10 @@ jobs: const result = await hover(...getPositionFromCursor(input), testHoverConfig("ref", "string", "The branch, tag or SHA to checkout.")); expect(result).not.toBeUndefined(); - expect(result?.contents).toEqual("The branch, tag or SHA to checkout."); + + const expected = "The branch, tag or SHA to checkout.\n\n" + + "**Context:** github, inputs, vars, needs, strategy, matrix, secrets, steps, job, runner, env, hashFiles(1,255)" + expect(result?.contents).toEqual(expected); }); it("falls back to the token description", async () => { diff --git a/actions-languageservice/src/hover.ts b/actions-languageservice/src/hover.ts index 4d5ebdd..e7bac56 100644 --- a/actions-languageservice/src/hover.ts +++ b/actions-languageservice/src/hover.ts @@ -35,11 +35,10 @@ export async function hover(document: TextDocument, position: Position, config?: let description = await getDescription(document, config, result, token, path); - if (token.definition.evaluatorContext.length > 0) { + const allowedContext = token.definitionInfo?.allowedContext; + if (allowedContext && allowedContext?.length > 0) { // Only add padding if there is a description - description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${token.definition.evaluatorContext.join( - ", " - )}`; + description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${allowedContext.join(", ")}`; } return {