Files
languageservices/languageservice/src/description-providers/reusable-job-inputs.ts
T
eric scipleandGitHub d2ffb50a92 Add language service support for action.yml files (#275)
- Add validation, completion, hover, and document links for action.yml files
- Implement document type detection to route action.yml to action-specific handlers
- Add expression context for composite actions (inputs, steps, github, runner, etc.)
- Add schema validation for required fields, branding, and composite step requirements
- Support JavaScript (node20/node24), Docker, and composite action types
- Validate action references in composite action uses steps
- Add JSDoc comments to parser and template functions
- Refactor hover to use hoverToken consistently
- Fix lint errors and add return type annotations
2026-01-02 10:38:52 -06:00

50 lines
1.6 KiB
TypeScript

import {isMapping, isString} from "@actions/workflow-parser";
import {DESCRIPTION} from "@actions/workflow-parser/templates/template-constants";
import {WorkflowContext} from "../context/workflow-context.js";
import {TokenResult} from "../utils/find-token.js";
/**
* Checks if the token is an input value in a reusable workflow job's `with:` block.
*/
export function isReusableWorkflowJobInput(tokenResult: TokenResult): boolean {
return (
tokenResult.parent?.definition?.key === "workflow-job-with" &&
tokenResult.token !== null &&
isString(tokenResult.token)
);
}
/**
* Gets the description of an input from a called reusable workflow.
* When a workflow calls another workflow with `uses:`, this fetches the input's
* description from the called workflow's `workflow_call.inputs` definitions.
*/
export function getReusableWorkflowInputDescription(
workflowContext: WorkflowContext,
tokenResult: TokenResult
): string {
const reusableWorkflowJob = workflowContext.reusableWorkflowJob;
if (!reusableWorkflowJob) {
return "";
}
const inputName = tokenResult.token && isString(tokenResult.token) && tokenResult.token.value;
if (!inputName) {
return "";
}
// Find the input description in the template, if any
if (reusableWorkflowJob["input-definitions"]) {
const definition = reusableWorkflowJob["input-definitions"].find(inputName);
if (definition && isMapping(definition)) {
const description = definition.find(DESCRIPTION);
if (description && isString(description)) {
return description.value;
}
}
}
return "";
}