Files
languageservices/languageserver/src/description-provider.ts
T

27 lines
929 B
TypeScript
Raw Normal View History

2023-02-24 08:53:51 -08:00
import {DescriptionProvider} from "@actions/languageservice/hover";
2023-01-23 16:02:13 -05:00
import {Octokit} from "@octokit/rest";
2023-02-24 08:53:51 -08:00
import {getActionDescription} from "./description-providers/action-description";
2023-01-23 16:02:13 -05:00
import {getActionInputDescription} from "./description-providers/action-input";
2023-01-30 17:05:32 -08:00
import {TTLCache} from "./utils/cache";
2023-01-23 16:02:13 -05:00
2023-01-30 17:05:32 -08:00
export function descriptionProvider(client: Octokit | undefined, cache: TTLCache): DescriptionProvider {
2023-01-23 16:02:13 -05:00
const getDescription: DescriptionProvider["getDescription"] = async (context, token, path) => {
2023-03-06 14:44:18 -05:00
if (!client || !context.step) {
2023-01-23 16:02:13 -05:00
return undefined;
}
2023-01-30 17:05:32 -08:00
2023-03-06 15:06:38 -05:00
const parent = path[path.length - 1];
if (parent.definition?.key === "step-with") {
2023-01-30 17:05:32 -08:00
return await getActionInputDescription(client, cache, context.step, token);
2023-01-23 16:02:13 -05:00
}
2023-03-06 14:44:18 -05:00
2023-03-06 15:06:38 -05:00
if (parent.definition?.key === "step-uses") {
2023-03-06 14:44:18 -05:00
return await getActionDescription(client, cache, context.step);
}
2023-01-23 16:02:13 -05:00
};
return {
getDescription
};
}