Refactor appendContext

This commit is contained in:
Jacob Wallraff
2023-02-21 15:19:03 -08:00
parent ba23758999
commit fa3c7104a8
+4 -5
View File
@@ -66,7 +66,7 @@ export async function hover(document: TextDocument, position: Position, config?:
if (exprPos) { if (exprPos) {
let hover = expressionHover(exprPos, context, namedContexts, functions); let hover = expressionHover(exprPos, context, namedContexts, functions);
if (hover) { if (hover) {
hover.contents = appendContext(token, hover.contents as string); hover.contents = appendContext(hover.contents as string, allowedContext);
} }
return hover; return hover;
} }
@@ -92,7 +92,7 @@ export async function hover(document: TextDocument, position: Position, config?:
if (tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) { if (tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) {
let description = getReusableWorkflowInputDescription(workflowContext, tokenResult); let description = getReusableWorkflowInputDescription(workflowContext, tokenResult);
description = appendContext(token, description); description = appendContext(description, token.definitionInfo?.allowedContext);
return { return {
contents: description, contents: description,
range: mapRange(token.range) 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); let description = await getDescription(config, workflowContext, token, tokenResult.path);
description = appendContext(token, description); description = appendContext(description, token.definitionInfo?.allowedContext);
return { return {
contents: description, contents: description,
@@ -108,8 +108,7 @@ export async function hover(document: TextDocument, position: Position, config?:
} satisfies Hover; } satisfies Hover;
} }
function appendContext(token: TemplateToken, description: string) { function appendContext(description: string, allowedContext?: string[]) {
const allowedContext = token.definitionInfo?.allowedContext;
if (allowedContext && allowedContext?.length > 0) { if (allowedContext && allowedContext?.length > 0) {
// Only add padding if there is a description // Only add padding if there is a description
description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${allowedContext.join(", ")}`; description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${allowedContext.join(", ")}`;