Move description fetching to language service
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import {DescriptionProvider} from "@github/actions-languageservice/hover";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {getActionInputDescription} from "./description-providers/action-input";
|
||||
import {getReusableWorkflowInputDescription} from "./description-providers/reusable-workflow-input";
|
||||
import {TTLCache} from "./utils/cache";
|
||||
|
||||
export function descriptionProvider(client: Octokit | undefined, cache: TTLCache): DescriptionProvider {
|
||||
const getDescription: DescriptionProvider["getDescription"] = async (context, token, path, template) => {
|
||||
const getDescription: DescriptionProvider["getDescription"] = async (context, token, path) => {
|
||||
if (!client) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -14,10 +13,6 @@ export function descriptionProvider(client: Octokit | undefined, cache: TTLCache
|
||||
if (context.step && parent.definition?.key === "step-with") {
|
||||
return await getActionInputDescription(client, cache, context.step, token);
|
||||
}
|
||||
|
||||
if (context.reusableWorkflowJob && template && parent.definition?.key === "workflow-job-with") {
|
||||
return await getReusableWorkflowInputDescription(context.reusableWorkflowJob, token, template);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import {WorkflowTemplate, isMapping} from "@github/actions-workflow-parser";
|
||||
import {isReusableWorkflowJob} from "@github/actions-workflow-parser/model/type-guards";
|
||||
import {isString} from "@github/actions-workflow-parser";
|
||||
import {ReusableWorkflowJob} from "@github/actions-workflow-parser/model/workflow-template";
|
||||
import {DESCRIPTION} from "@github/actions-workflow-parser/templates/template-constants";
|
||||
import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/template-token";
|
||||
|
||||
export async function getReusableWorkflowInputDescription(
|
||||
reusableWorkflowJob: ReusableWorkflowJob,
|
||||
token: TemplateToken,
|
||||
template: WorkflowTemplate
|
||||
): Promise<string | undefined> {
|
||||
if (!isReusableWorkflowJob(reusableWorkflowJob)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const inputName = isString(token) && token.value;
|
||||
if (!inputName) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Filter out just reusable jobs
|
||||
const templateReusableJobs = template.jobs.filter(isReusableWorkflowJob);
|
||||
|
||||
// Find the reusable job in the template that matches the current reusable job
|
||||
const templateReusableJob = templateReusableJobs.find(job => job.id.value === reusableWorkflowJob.id.value);
|
||||
|
||||
// Find the input description in the template, if any
|
||||
if (templateReusableJob && reusableWorkflowJob["input-definitions"] && templateReusableJob["input-definitions"]) {
|
||||
const definition = templateReusableJob["input-definitions"].find(token.value)
|
||||
if (definition && isMapping(definition)) {
|
||||
const description = definition.find(DESCRIPTION)
|
||||
if (description && isString(description)) {
|
||||
return description.value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user