Show action input descriptions on hover
This commit is contained in:
@@ -23,6 +23,7 @@ import {TTLCache} from "./utils/cache";
|
||||
import {valueProviders} from "./value-providers";
|
||||
import {getActionInputs} from "./value-providers/action-inputs";
|
||||
import {Commands} from "./commands";
|
||||
import {descriptionProvider} from "./description-provider";
|
||||
|
||||
export function initConnection(connection: Connection) {
|
||||
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
||||
@@ -120,7 +121,9 @@ export function initConnection(connection: Connection) {
|
||||
});
|
||||
|
||||
connection.onHover(async ({position, textDocument}: HoverParams): Promise<Hover | null> => {
|
||||
return hover(documents.get(textDocument.uri)!, position);
|
||||
return hover(documents.get(textDocument.uri)!, position, {
|
||||
descriptionProvider: descriptionProvider(sessionToken, cache)
|
||||
});
|
||||
});
|
||||
|
||||
connection.onRequest("workspace/executeCommand", (params: ExecuteCommandParams) => {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import {DescriptionProvider} from "@github/actions-languageservice/hover";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {TTLCache} from "./utils/cache";
|
||||
import {getActionInputDescription} from "./description-providers/action-input";
|
||||
|
||||
export function descriptionProvider(sessionToken: string | undefined, cache: TTLCache): DescriptionProvider {
|
||||
const octokit =
|
||||
sessionToken &&
|
||||
new Octokit({
|
||||
auth: sessionToken
|
||||
});
|
||||
|
||||
const getDescription: DescriptionProvider["getDescription"] = async (context, token, path) => {
|
||||
if (!octokit) {
|
||||
return undefined;
|
||||
}
|
||||
const parent = path[path.length - 1];
|
||||
if (context.step && parent.definition?.key === "step-with") {
|
||||
return await getActionInputDescription(octokit, cache, context.step, token);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
getDescription
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {parseActionReference} from "@github/actions-languageservice/action";
|
||||
import {isString} from "@github/actions-workflow-parser";
|
||||
import {isActionStep} from "@github/actions-workflow-parser/model/type-guards";
|
||||
import {Step} from "@github/actions-workflow-parser/model/workflow-template";
|
||||
import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/template-token";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {fetchActionMetadata} from "../utils/action-metadata";
|
||||
import {TTLCache} from "../utils/cache";
|
||||
|
||||
export async function getActionInputDescription(
|
||||
client: Octokit,
|
||||
cache: TTLCache,
|
||||
step: Step,
|
||||
token: TemplateToken
|
||||
): Promise<string | undefined> {
|
||||
if (!isActionStep(step)) {
|
||||
return undefined;
|
||||
}
|
||||
const action = parseActionReference(step.uses.value);
|
||||
if (!action) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const inputName = isString(token) && token.value;
|
||||
if (!inputName) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const metadata = await fetchActionMetadata(client, cache, action);
|
||||
if (!metadata?.inputs) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return metadata.inputs[inputName]?.description;
|
||||
}
|
||||
Reference in New Issue
Block a user