From fa3c7104a831ee18c2d349e3b80acf22f4a2dafb Mon Sep 17 00:00:00 2001 From: Jacob Wallraff Date: Tue, 21 Feb 2023 15:19:03 -0800 Subject: [PATCH] Refactor appendContext --- actions-languageservice/src/hover.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/actions-languageservice/src/hover.ts b/actions-languageservice/src/hover.ts index 7c80e23..9643c56 100644 --- a/actions-languageservice/src/hover.ts +++ b/actions-languageservice/src/hover.ts @@ -66,7 +66,7 @@ export async function hover(document: TextDocument, position: Position, config?: if (exprPos) { let hover = expressionHover(exprPos, context, namedContexts, functions); if (hover) { - hover.contents = appendContext(token, hover.contents as string); + hover.contents = appendContext(hover.contents as string, allowedContext); } return hover; } @@ -92,7 +92,7 @@ export async function hover(document: TextDocument, position: Position, config?: if (tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) { let description = getReusableWorkflowInputDescription(workflowContext, tokenResult); - description = appendContext(token, description); + description = appendContext(description, token.definitionInfo?.allowedContext); return { contents: description, range: mapRange(token.range) @@ -100,7 +100,7 @@ export async function hover(document: TextDocument, position: Position, config?: } let description = await getDescription(config, workflowContext, token, tokenResult.path); - description = appendContext(token, description); + description = appendContext(description, token.definitionInfo?.allowedContext); return { contents: description, @@ -108,8 +108,7 @@ export async function hover(document: TextDocument, position: Position, config?: } satisfies Hover; } -function appendContext(token: TemplateToken, description: string) { - const allowedContext = token.definitionInfo?.allowedContext; +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(", ")}`;