refactor(config): migrate lsp schemas to Effect Schema (#23167)
This commit is contained in:
@@ -189,7 +189,7 @@ export const Info = z
|
|||||||
.optional()
|
.optional()
|
||||||
.describe("MCP (Model Context Protocol) server configurations"),
|
.describe("MCP (Model Context Protocol) server configurations"),
|
||||||
formatter: ConfigFormatter.Info.optional(),
|
formatter: ConfigFormatter.Info.optional(),
|
||||||
lsp: ConfigLSP.Info.optional(),
|
lsp: ConfigLSP.Info.zod.optional(),
|
||||||
instructions: z.array(z.string()).optional().describe("Additional instruction files or patterns to include"),
|
instructions: z.array(z.string()).optional().describe("Additional instruction files or patterns to include"),
|
||||||
layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
|
layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
|
||||||
permission: ConfigPermission.Info.optional(),
|
permission: ConfigPermission.Info.optional(),
|
||||||
|
|||||||
@@ -1,37 +1,43 @@
|
|||||||
export * as ConfigLSP from "./lsp"
|
export * as ConfigLSP from "./lsp"
|
||||||
|
|
||||||
import z from "zod"
|
import { Schema } from "effect"
|
||||||
|
import { zod } from "@/util/effect-zod"
|
||||||
|
import { withStatics } from "@/util/schema"
|
||||||
import * as LSPServer from "../lsp/server"
|
import * as LSPServer from "../lsp/server"
|
||||||
|
|
||||||
export const Disabled = z.object({
|
export const Disabled = Schema.Struct({
|
||||||
disabled: z.literal(true),
|
disabled: Schema.Literal(true),
|
||||||
})
|
}).pipe(withStatics((s) => ({ zod: zod(s) })))
|
||||||
|
|
||||||
export const Entry = z.union([
|
export const Entry = Schema.Union([
|
||||||
Disabled,
|
Disabled,
|
||||||
z.object({
|
Schema.Struct({
|
||||||
command: z.array(z.string()),
|
command: Schema.mutable(Schema.Array(Schema.String)),
|
||||||
extensions: z.array(z.string()).optional(),
|
extensions: Schema.optional(Schema.mutable(Schema.Array(Schema.String))),
|
||||||
disabled: z.boolean().optional(),
|
disabled: Schema.optional(Schema.Boolean),
|
||||||
env: z.record(z.string(), z.string()).optional(),
|
env: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
||||||
initialization: z.record(z.string(), z.any()).optional(),
|
initialization: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
||||||
}),
|
}),
|
||||||
])
|
]).pipe(withStatics((s) => ({ zod: zod(s) })))
|
||||||
|
|
||||||
export const Info = z.union([z.boolean(), z.record(z.string(), Entry)]).refine(
|
export const Info = Schema.Union([Schema.Boolean, Schema.Record(Schema.String, Entry)]).pipe(
|
||||||
(data) => {
|
withStatics((s) => ({
|
||||||
if (typeof data === "boolean") return true
|
zod: zod(s).refine(
|
||||||
const serverIds = new Set(Object.values(LSPServer).map((server) => server.id))
|
(data) => {
|
||||||
|
if (typeof data === "boolean") return true
|
||||||
|
const serverIds = new Set(Object.values(LSPServer).map((server) => server.id))
|
||||||
|
|
||||||
return Object.entries(data).every(([id, config]) => {
|
return Object.entries(data).every(([id, config]) => {
|
||||||
if (config.disabled) return true
|
if (config.disabled) return true
|
||||||
if (serverIds.has(id)) return true
|
if (serverIds.has(id)) return true
|
||||||
return Boolean(config.extensions)
|
return Boolean(config.extensions)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: "For custom LSP servers, 'extensions' array is required.",
|
error: "For custom LSP servers, 'extensions' array is required.",
|
||||||
},
|
},
|
||||||
|
),
|
||||||
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
export type Info = z.infer<typeof Info>
|
export type Info = Schema.Schema.Type<typeof Info>
|
||||||
|
|||||||
Reference in New Issue
Block a user