From a2d5300578b01ab2e2f259068500e9a8daa9b37e Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Thu, 9 Mar 2023 17:10:23 -0500 Subject: [PATCH 1/3] 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( From d9de07bfe3587e9d8266909cd7bd54e34d7cdeee Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Fri, 10 Mar 2023 10:39:59 -0500 Subject: [PATCH 2/3] Remove bolded context text --- languageservice/src/hover.test.ts | 6 +++--- languageservice/src/hover.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/languageservice/src/hover.test.ts b/languageservice/src/hover.test.ts index 1f73cd8..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" + - "**Available expression contexts:** `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 = - "**Available expression contexts:** `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" + - "**Available expression contexts:** `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 fae74d6..35e8600 100644 --- a/languageservice/src/hover.ts +++ b/languageservice/src/hover.ts @@ -113,7 +113,7 @@ function appendContext(description: string, allowedContext?: string[]) { return description; } - const contextDescription = `**Available expression contexts:** ${allowedContext.map(c => `\`${c}\``).join(", ")}`; + const contextDescription = `Available expression contexts: ${allowedContext.map(c => `\`${c}\``).join(", ")}`; if (description.length == 0) { return contextDescription; } From bc997ffdbc3285b68d4d27cc894e622c7b4413f6 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Fri, 10 Mar 2023 10:55:44 -0500 Subject: [PATCH 3/3] Fix context descriptions in hover tests --- languageservice/src/hover.reusable-workflow.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 () => {