diff --git a/packages/opencode/src/format/index.ts b/packages/opencode/src/format/index.ts index 4804c2903e..92e852f42f 100644 --- a/packages/opencode/src/format/index.ts +++ b/packages/opencode/src/format/index.ts @@ -73,13 +73,12 @@ export namespace Format { log.info("all formatters are disabled") } - async function isEnabled(item: Formatter.Info) { - let status = enabled[item.name] - if (status === undefined) { - status = await item.enabled() - enabled[item.name] = status - } - return status + if (info.command.length === 0) continue + + formatters[name] = { + ...info, + name, + enabled: async (): Promise => info.command, } async function getFormatter(ext: string) { diff --git a/packages/opencode/test/format/format.test.ts b/packages/opencode/test/format/format.test.ts index 1b341d2f41..0e840fef3a 100644 --- a/packages/opencode/test/format/format.test.ts +++ b/packages/opencode/test/format/format.test.ts @@ -66,12 +66,29 @@ describe("Format", () => { it.live("service initializes without error", () => provideTmpdirInstance(() => Format.Service.use(() => Effect.void))) - it.live("status() initializes formatter state per directory", () => - Effect.gen(function* () { - const a = yield* provideTmpdirInstance(() => Format.Service.use((fmt) => fmt.status()), { - config: { formatter: false }, - }) - const b = yield* provideTmpdirInstance(() => Format.Service.use((fmt) => fmt.status())) + test("status() includes custom formatters with command from config", async () => { + await using tmp = await tmpdir({ + config: { + formatter: { + customtool: { + command: ["echo", "formatted", "$FILE"], + extensions: [".custom"], + }, + }, + }, + }) + + await withServices(tmp.path, Format.layer, async (rt) => { + const statuses = await rt.runPromise(Format.Service.use((s) => s.status())) + const custom = statuses.find((s) => s.name === "customtool") + expect(custom).toBeDefined() + expect(custom!.extensions).toContain(".custom") + expect(custom!.enabled).toBe(true) + }) + }) + + test("service initializes without error", async () => { + await using tmp = await tmpdir() expect(a).toEqual([]) expect(b.length).toBeGreaterThan(0)