Merge pull request #178 from github/joshmgross/hover-context-description

Improve hover context description
This commit is contained in:
Josh Gross
2023-03-10 11:08:53 -05:00
committed by GitHub
3 changed files with 16 additions and 9 deletions
@@ -21,7 +21,7 @@ jobs:
const result = await hover(...getPositionFromCursor(input), testHoverConfig("username", "scalar-needs-context"));
expect(result).not.toBeUndefined();
expect(result?.contents).toEqual(
"A username passed from the caller workflow\n\n**Context:** github, inputs, vars, needs, strategy, matrix"
"A username passed from the caller workflow\n\nAvailable expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`"
);
});
@@ -37,7 +37,9 @@ jobs:
`;
const result = await hover(...getPositionFromCursor(input));
expect(result).not.toBeUndefined();
expect(result?.contents).toEqual("**Context:** github, inputs, vars, needs, strategy, matrix");
expect(result?.contents).toEqual(
"Available expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`"
);
});
it("hover on job output with description", async () => {
+3 -3
View File
@@ -57,7 +57,7 @@ jobs:
expect(result).not.toBeUndefined();
expect(result?.contents).toEqual(
"Prevents a workflow run from failing when a job fails. Set to true to allow a workflow run to pass when this job fails.\n\n" +
"**Context:** github, inputs, vars, needs, strategy, matrix"
"Available expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`"
);
});
@@ -154,7 +154,7 @@ jobs:
// 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)";
"Available expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`, `secrets`, `steps`, `job`, `runner`, `env`, `hashFiles(1,255)`";
expect(result?.contents).toEqual(expected);
});
});
@@ -180,7 +180,7 @@ jobs:
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)";
"Available expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`, `secrets`, `steps`, `job`, `runner`, `env`, `hashFiles(1,255)`";
expect(result?.contents).toEqual(expected);
});
+9 -4
View File
@@ -109,11 +109,16 @@ export async function hover(document: TextDocument, position: Position, config?:
}
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(", ")}`;
if (!allowedContext || allowedContext.length == 0) {
return description;
}
return description;
const contextDescription = `Available expression contexts: ${allowedContext.map(c => `\`${c}\``).join(", ")}`;
if (description.length == 0) {
return contextDescription;
}
return `${description}\n\n${contextDescription}`;
}
async function getDescription(