diff --git a/actions-languageserver/src/description-providers/reusable-workflow-input.ts b/actions-languageserver/src/description-providers/reusable-workflow-input.ts index 1e4c805..e725b6e 100644 --- a/actions-languageserver/src/description-providers/reusable-workflow-input.ts +++ b/actions-languageserver/src/description-providers/reusable-workflow-input.ts @@ -1,6 +1,8 @@ -import {WorkflowTemplate} from "@github/actions-workflow-parser"; +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( @@ -12,22 +14,27 @@ export async function getReusableWorkflowInputDescription( 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); - // Set the description on the reusable job to the one from the template, if any + // Find the input description in the template, if any if (templateReusableJob && reusableWorkflowJob["input-definitions"] && templateReusableJob["input-definitions"]) { - // For each input in the reusable job, see if there's one that matches in the template - for (const input of reusableWorkflowJob["input-definitions"]) { - return "asd" + 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 "Didn't find a matching job description!" + return "" } diff --git a/actions-languageservice/src/hover.ts b/actions-languageservice/src/hover.ts index 4adb57d..e16a91b 100644 --- a/actions-languageservice/src/hover.ts +++ b/actions-languageservice/src/hover.ts @@ -119,7 +119,8 @@ async function getDescription( } const template = await convertWorkflowTemplate(result.context, result.value, config?.fileProvider, { - errorPolicy: ErrorPolicy.TryConversion + errorPolicy: ErrorPolicy.TryConversion, + fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0, }); const workflowContext = getWorkflowContext(document.uri, template, path); const description = await config.descriptionProvider.getDescription(workflowContext, token, path, template);