Add file provider to hover

This commit is contained in:
Jacob Wallraff
2023-02-15 14:50:26 -08:00
parent ed9199aa93
commit cc7ca2237d
6 changed files with 120 additions and 5 deletions
+4 -1
View File
@@ -134,7 +134,10 @@ export function initConnection(connection: Connection) {
return hover(documents.get(textDocument.uri)!, position, {
descriptionProvider: descriptionProvider(client, cache),
contextProviderConfig: repoContext && contextProviders(client, repoContext, cache)
contextProviderConfig: repoContext && contextProviders(client, repoContext, cache),
fileProvider: getFileProvider(client, cache, repoContext?.workspaceUri, async path => {
return await connection.sendRequest(Requests.ReadFile, {path});
})
});
});
@@ -1,10 +1,11 @@
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) => {
const getDescription: DescriptionProvider["getDescription"] = async (context, token, path, fileProvider) => {
if (!client) {
return undefined;
}
@@ -13,6 +14,10 @@ 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 && fileProvider && parent.definition?.key === "workflow-job-with") {
return await getReusableWorkflowInputDescription(client, cache, context.reusableWorkflowJob, token, fileProvider);
}
};
return {
@@ -0,0 +1,23 @@
import {parseActionReference} from "@github/actions-languageservice/action";
import {isString} from "@github/actions-workflow-parser";
import {isActionStep, isReusableWorkflowJob} from "@github/actions-workflow-parser/model/type-guards";
import {FileProvider} from "@github/actions-workflow-parser/workflows/file-provider";
import {ReusableWorkflowJob} 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 getReusableWorkflowInputDescription(
client: Octokit,
cache: TTLCache,
reusableWorkflowJob: ReusableWorkflowJob,
token: TemplateToken,
fileProvider: FileProvider
): Promise<string | undefined> {
if (!isReusableWorkflowJob(reusableWorkflowJob)) {
return undefined;
}
return "here's a description"
}