Skip to content

Commit 650a13a

Browse files
authored
refactor(config): migrate lsp schemas to Effect Schema (#23167)
1 parent 5443532 commit 650a13a

2 files changed

Lines changed: 33 additions & 27 deletions

File tree

packages/opencode/src/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const Info = z
189189
.optional()
190190
.describe("MCP (Model Context Protocol) server configurations"),
191191
formatter: ConfigFormatter.Info.optional(),
192-
lsp: ConfigLSP.Info.optional(),
192+
lsp: ConfigLSP.Info.zod.optional(),
193193
instructions: z.array(z.string()).optional().describe("Additional instruction files or patterns to include"),
194194
layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
195195
permission: ConfigPermission.Info.optional(),
Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
export * as ConfigLSP from "./lsp"
22

3-
import z from "zod"
3+
import { Schema } from "effect"
4+
import { zod } from "@/util/effect-zod"
5+
import { withStatics } from "@/util/schema"
46
import * as LSPServer from "../lsp/server"
57

6-
export const Disabled = z.object({
7-
disabled: z.literal(true),
8-
})
8+
export const Disabled = Schema.Struct({
9+
disabled: Schema.Literal(true),
10+
}).pipe(withStatics((s) => ({ zod: zod(s) })))
911

10-
export const Entry = z.union([
12+
export const Entry = Schema.Union([
1113
Disabled,
12-
z.object({
13-
command: z.array(z.string()),
14-
extensions: z.array(z.string()).optional(),
15-
disabled: z.boolean().optional(),
16-
env: z.record(z.string(), z.string()).optional(),
17-
initialization: z.record(z.string(), z.any()).optional(),
14+
Schema.Struct({
15+
command: Schema.mutable(Schema.Array(Schema.String)),
16+
extensions: Schema.optional(Schema.mutable(Schema.Array(Schema.String))),
17+
disabled: Schema.optional(Schema.Boolean),
18+
env: Schema.optional(Schema.Record(Schema.String, Schema.String)),
19+
initialization: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
1820
}),
19-
])
21+
]).pipe(withStatics((s) => ({ zod: zod(s) })))
2022

21-
export const Info = z.union([z.boolean(), z.record(z.string(), Entry)]).refine(
22-
(data) => {
23-
if (typeof data === "boolean") return true
24-
const serverIds = new Set(Object.values(LSPServer).map((server) => server.id))
23+
export const Info = Schema.Union([Schema.Boolean, Schema.Record(Schema.String, Entry)]).pipe(
24+
withStatics((s) => ({
25+
zod: zod(s).refine(
26+
(data) => {
27+
if (typeof data === "boolean") return true
28+
const serverIds = new Set(Object.values(LSPServer).map((server) => server.id))
2529

26-
return Object.entries(data).every(([id, config]) => {
27-
if (config.disabled) return true
28-
if (serverIds.has(id)) return true
29-
return Boolean(config.extensions)
30-
})
31-
},
32-
{
33-
error: "For custom LSP servers, 'extensions' array is required.",
34-
},
30+
return Object.entries(data).every(([id, config]) => {
31+
if (config.disabled) return true
32+
if (serverIds.has(id)) return true
33+
return Boolean(config.extensions)
34+
})
35+
},
36+
{
37+
error: "For custom LSP servers, 'extensions' array is required.",
38+
},
39+
),
40+
})),
3541
)
3642

37-
export type Info = z.infer<typeof Info>
43+
export type Info = Schema.Schema.Type<typeof Info>

0 commit comments

Comments
 (0)