Merge remote-tracking branch 'origin/pr-18308' into pr-18308

pr-18308
Dax Raad 2026-04-01 11:59:56 -04:00
commit e2621148d1
2 changed files with 29 additions and 13 deletions

View File

@ -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<string[] | false> => info.command,
}
async function getFormatter(ext: string) {

View File

@ -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)