Ensure inherited context is shown on hover

This commit is contained in:
Josh Gross
2023-01-23 16:20:59 -05:00
parent 48c728771e
commit d8d4a3f46a
2 changed files with 28 additions and 5 deletions
+25 -1
View File
@@ -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 () => {
+3 -4
View File
@@ -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 {