From 2d7a05c0491f3fda14edea5a66f063e0435b54a6 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Wed, 14 Dec 2022 11:18:38 -0500 Subject: [PATCH] Use the allowed context from the definition info --- actions-languageservice/src/complete.ts | 3 +-- .../src/utils/allowed-context.ts | 15 --------------- actions-languageservice/src/validate.ts | 5 +---- 3 files changed, 2 insertions(+), 21 deletions(-) delete mode 100644 actions-languageservice/src/utils/allowed-context.ts diff --git a/actions-languageservice/src/complete.ts b/actions-languageservice/src/complete.ts index 16b50dc..1617f70 100644 --- a/actions-languageservice/src/complete.ts +++ b/actions-languageservice/src/complete.ts @@ -14,7 +14,6 @@ import {ContextProviderConfig} from "./context-providers/config"; import {getContext, Mode} from "./context-providers/default"; import {getWorkflowContext, WorkflowContext} from "./context/workflow-context"; import {nullTrace} from "./nulltrace"; -import {getAllowedContext} from "./utils/allowed-context"; import {findToken} from "./utils/find-token"; import {mapRange} from "./utils/range"; import {transform} from "./utils/transform"; @@ -92,7 +91,7 @@ export async function complete( const expressionInput = (getExpressionInput(currentInput, relCharPos) || "").trim(); - const allowedContext = getAllowedContext(token, parent); + const allowedContext = token.definitionInfo?.allowedContext || []; const context = await getContext(allowedContext, contextProviderConfig, workflowContext, Mode.Completion); return completeExpression(expressionInput, context, []); diff --git a/actions-languageservice/src/utils/allowed-context.ts b/actions-languageservice/src/utils/allowed-context.ts deleted file mode 100644 index 36a5d91..0000000 --- a/actions-languageservice/src/utils/allowed-context.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/template-token"; - -export function getAllowedContext(token: TemplateToken, parent: TemplateToken | null | undefined): string[] { - // Workaround for https://github.com/github/c2c-actions-experience/issues/6876 - // Context is inherited from the parent - const allowedContext = new Set(); - for (const t of [token, parent]) { - if (t?.definition?.readerContext) { - for (const context of t.definition.readerContext) { - allowedContext.add(context); - } - } - } - return Array.from(allowedContext); -} diff --git a/actions-languageservice/src/validate.ts b/actions-languageservice/src/validate.ts index 8d2a0b4..d5e9884 100644 --- a/actions-languageservice/src/validate.ts +++ b/actions-languageservice/src/validate.ts @@ -24,7 +24,6 @@ import {getWorkflowContext, WorkflowContext} from "./context/workflow-context"; import {AccessError, wrapDictionary} from "./expression-validation/error-dictionary"; import {error} from "./log"; import {nullTrace} from "./nulltrace"; -import {getAllowedContext} from "./utils/allowed-context"; import {findToken} from "./utils/find-token"; import {mapRange} from "./utils/range"; import {validateAction} from "./validate-action"; @@ -94,14 +93,12 @@ async function additionalValidations( const validationToken = key || parent || token; const validationDefinition = validationToken.definition; - const allowedContext = getAllowedContext(validationToken, parent); - // If this is an expression, validate it if (isBasicExpression(token)) { await validateExpression( diagnostics, token, - allowedContext, + validationToken.definitionInfo?.allowedContext || [], config?.contextProviderConfig, getProviderContext(documentUri, template, root, token) );