From a2d5300578b01ab2e2f259068500e9a8daa9b37e Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Thu, 9 Mar 2023 17:10:23 -0500 Subject: [PATCH] Improve hover context description --- languageservice/src/hover.test.ts | 6 +++--- languageservice/src/hover.ts | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/languageservice/src/hover.test.ts b/languageservice/src/hover.test.ts index 5250af6..1f73cd8 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..fae74d6 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(