diff --git a/actions-languageservice/src/complete.ts b/actions-languageservice/src/complete.ts index ca9d58c..db85d6c 100644 --- a/actions-languageservice/src/complete.ts +++ b/actions-languageservice/src/complete.ts @@ -84,7 +84,7 @@ export async function complete( const expressionInput = (getExpressionInput(currentInput, relCharPos) || "").trim(); - const allowedContext = getAllowedContext(token, parent!); + const allowedContext = getAllowedContext(token, parent); const context = await getContext(allowedContext, contextProviderConfig, workflowContext); return completeExpression(expressionInput, context, []); diff --git a/actions-languageservice/src/utils/allowed-context.ts b/actions-languageservice/src/utils/allowed-context.ts index 0eb8704..36a5d91 100644 --- a/actions-languageservice/src/utils/allowed-context.ts +++ b/actions-languageservice/src/utils/allowed-context.ts @@ -1,11 +1,11 @@ import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/template-token"; -export function getAllowedContext(token: TemplateToken, parent: TemplateToken): string[] { +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) { + if (t?.definition?.readerContext) { for (const context of t.definition.readerContext) { allowedContext.add(context); } diff --git a/actions-languageservice/src/validate.ts b/actions-languageservice/src/validate.ts index d0ca448..7592795 100644 --- a/actions-languageservice/src/validate.ts +++ b/actions-languageservice/src/validate.ts @@ -23,6 +23,7 @@ import {getContext} from "./context-providers/default"; import {getWorkflowContext, WorkflowContext} from "./context/workflow-context"; import {AccessError, wrapDictionary} from "./expression-validation/error-dictionary"; import {nullTrace} from "./nulltrace"; +import {getAllowedContext} from "./utils/allowed-context"; import {findToken} from "./utils/find-token"; import {mapRange} from "./utils/range"; import {ValueProviderConfig, ValueProviderKind} from "./value-providers/config"; @@ -75,6 +76,7 @@ export async function validate( } } catch (e) { // TODO: Handle error here + console.error(e); } return diagnostics; @@ -94,12 +96,14 @@ 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, - validationDefinition, + allowedContext, contextProviderConfig, getProviderContext(documentUri, template, root, token) ); @@ -170,14 +174,13 @@ function getProviderContext( async function validateExpression( diagnostics: Diagnostic[], token: BasicExpressionToken, - definition: Definition | undefined, + allowedContext: string[], contextProviderConfig: ContextProviderConfig | undefined, workflowContext: WorkflowContext ) { // Validate the expression for (const expression of token.originalExpressions || [token]) { - const allowedContexts = definition?.readerContext || []; - const {namedContexts, functions} = splitAllowedContext(allowedContexts); + const {namedContexts, functions} = splitAllowedContext(allowedContext); let expr: Expr | undefined;