diff --git a/actions-languageserver/src/connection.ts b/actions-languageserver/src/connection.ts index cb35490..d061b4e 100644 --- a/actions-languageserver/src/connection.ts +++ b/actions-languageserver/src/connection.ts @@ -108,7 +108,9 @@ export function initConnection(connection: Connection) { return undefined; }, - fileProvider: getFileProvider(client, cache) + fileProvider: getFileProvider(client, cache, repoContext?.workspaceUri, async path => { + return await connection.sendRequest("actions/readFile", {path}); + }) }; const result = await validate(textDocument, config); diff --git a/actions-languageserver/src/file-provider.ts b/actions-languageserver/src/file-provider.ts index 7c01cd1..398dd3c 100644 --- a/actions-languageserver/src/file-provider.ts +++ b/actions-languageserver/src/file-provider.ts @@ -2,22 +2,43 @@ import {File} from "@github/actions-workflow-parser/workflows/file"; import {FileProvider} from "@github/actions-workflow-parser/workflows/file-provider"; import {fileIdentifier} from "@github/actions-workflow-parser/workflows/file-reference"; import {Octokit} from "@octokit/rest"; +import path from "path"; import {TTLCache} from "./utils/cache"; -export function getFileProvider(client: Octokit | undefined, cache: TTLCache): FileProvider | undefined { - if (!client) { +export function getFileProvider( + client: Octokit | undefined, + cache: TTLCache, + workspace: string | undefined, + readFile: (path: string) => Promise +): FileProvider | undefined { + if (!client && !workspace) { return undefined; } return { getFileContent: async (ref): Promise => { - if (!("repository" in ref)) { - throw new Error("Only remote file references are supported right now"); + if ("repository" in ref) { + if (!client) { + throw new Error("Remote file references are not supported with this configuration"); + } + + return await cache.get(`file-content-${fileIdentifier(ref)}`, undefined, () => + fetchWorkflowFile(client, ref.owner, ref.repository, ref.path, ref.version) + ); } - return await cache.get(`file-content-${fileIdentifier(ref)}`, undefined, () => - fetchWorkflowFile(client, ref.owner, ref.repository, ref.path, ref.version) - ); + if (!workspace) { + throw new Error("Local file references are not supported with this configuration"); + } + + const file = await readFile(path.join(workspace, ref.path)); + if (!file) { + throw new Error(`File not found: ${ref.path}`); + } + return { + name: ref.path, + content: file + }; } }; }