|
1 | 1 | export * as ConfigLSP from "./lsp" |
2 | 2 |
|
3 | | -import z from "zod" |
| 3 | +import { Schema } from "effect" |
| 4 | +import { zod } from "@/util/effect-zod" |
| 5 | +import { withStatics } from "@/util/schema" |
4 | 6 | import * as LSPServer from "../lsp/server" |
5 | 7 |
|
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) }))) |
9 | 11 |
|
10 | | -export const Entry = z.union([ |
| 12 | +export const Entry = Schema.Union([ |
11 | 13 | 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)), |
18 | 20 | }), |
19 | | -]) |
| 21 | +]).pipe(withStatics((s) => ({ zod: zod(s) }))) |
20 | 22 |
|
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)) |
25 | 29 |
|
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 | + })), |
35 | 41 | ) |
36 | 42 |
|
37 | | -export type Info = z.infer<typeof Info> |
| 43 | +export type Info = Schema.Schema.Type<typeof Info> |
0 commit comments