Procházet zdrojové kódy

fix(format): handle custom formatter command property with enabled() interface

The formatter Info interface uses enabled(): Promise<string[] | false> but
user configs provide a command property. Added explicit return type to the
arrow function that transforms command into the enabled() return value.

Also added test to verify custom formatters with command property work.
Dax Raad před 1 měsícem
rodič
revize
7a28d0520a

+ 1 - 1
packages/opencode/src/format/index.ts

@@ -62,7 +62,7 @@ export namespace Format {
           formatters[name] = {
             ...info,
             name,
-            enabled: async () => info.command,
+            enabled: async (): Promise<string[] | false> => info.command,
           }
         }
       } else {

+ 21 - 0
packages/opencode/test/format/format.test.ts

@@ -55,6 +55,27 @@ describe("Format", () => {
     })
   })
 
+  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()