diff --git a/languageservice/src/hover.reusable-workflow.test.ts b/languageservice/src/hover.reusable-workflow.test.ts index 63443f6..a8d9459 100644 --- a/languageservice/src/hover.reusable-workflow.test.ts +++ b/languageservice/src/hover.reusable-workflow.test.ts @@ -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 () => { diff --git a/languageservice/src/hover.test.ts b/languageservice/src/hover.test.ts index 5250af6..eeeccce 100644 --- a/languageservice/src/hover.test.ts +++ b/languageservice/src/hover.test.ts @@ -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); }); diff --git a/languageservice/src/hover.ts b/languageservice/src/hover.ts index 11f3e77..35e8600 100644 --- a/languageservice/src/hover.ts +++ b/languageservice/src/hover.ts @@ -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(