migrate LSP data schemas to Effect Schema (#23745)
Some checks are pending
deploy / deploy (push) Waiting to run

This commit is contained in:
Kit Langton 2026-04-21 17:26:50 -04:00 committed by GitHub
parent caaddf0964
commit 7933657135
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 54 deletions

View file

@ -10,9 +10,11 @@ import { Config } from "../config"
import { Flag } from "@/flag/flag" import { Flag } from "@/flag/flag"
import { Process } from "../util" import { Process } from "../util"
import { spawn as lspspawn } from "./launch" import { spawn as lspspawn } from "./launch"
import { Effect, Layer, Context } from "effect" import { Effect, Layer, Context, Schema } from "effect"
import { InstanceState } from "@/effect" import { InstanceState } from "@/effect"
import { AppFileSystem } from "@opencode-ai/shared/filesystem" import { AppFileSystem } from "@opencode-ai/shared/filesystem"
import { withStatics } from "@/util/schema"
import { zod, ZodOverride } from "@/util/effect-zod"
const log = Log.create({ service: "lsp" }) const log = Log.create({ service: "lsp" })
@ -20,60 +22,53 @@ export const Event = {
Updated: BusEvent.define("lsp.updated", z.object({})), Updated: BusEvent.define("lsp.updated", z.object({})),
} }
export const Range = z const Position = Schema.Struct({
.object({ line: Schema.Number,
start: z.object({ character: Schema.Number,
line: z.number(), })
character: z.number(),
}),
end: z.object({
line: z.number(),
character: z.number(),
}),
})
.meta({
ref: "Range",
})
export type Range = z.infer<typeof Range>
export const Symbol = z export const Range = Schema.Struct({
.object({ start: Position,
name: z.string(), end: Position,
kind: z.number(), })
location: z.object({ .annotate({ identifier: "Range" })
uri: z.string(), .pipe(withStatics((s) => ({ zod: zod(s) })))
export type Range = typeof Range.Type
export const Symbol = Schema.Struct({
name: Schema.String,
kind: Schema.Number,
location: Schema.Struct({
uri: Schema.String,
range: Range, range: Range,
}), }),
}) })
.meta({ .annotate({ identifier: "Symbol" })
ref: "Symbol", .pipe(withStatics((s) => ({ zod: zod(s) })))
}) export type Symbol = typeof Symbol.Type
export type Symbol = z.infer<typeof Symbol>
export const DocumentSymbol = z export const DocumentSymbol = Schema.Struct({
.object({ name: Schema.String,
name: z.string(), detail: Schema.optional(Schema.String),
detail: z.string().optional(), kind: Schema.Number,
kind: z.number(),
range: Range, range: Range,
selectionRange: Range, selectionRange: Range,
}) })
.meta({ .annotate({ identifier: "DocumentSymbol" })
ref: "DocumentSymbol", .pipe(withStatics((s) => ({ zod: zod(s) })))
}) export type DocumentSymbol = typeof DocumentSymbol.Type
export type DocumentSymbol = z.infer<typeof DocumentSymbol>
export const Status = z export const Status = Schema.Struct({
.object({ id: Schema.String,
id: z.string(), name: Schema.String,
name: z.string(), root: Schema.String,
root: z.string(), status: Schema.Literals(["connected", "error"]).annotate({
status: z.union([z.literal("connected"), z.literal("error")]), [ZodOverride]: z.union([z.literal("connected"), z.literal("error")]),
}) }),
.meta({ })
ref: "LSPStatus", .annotate({ identifier: "LSPStatus" })
}) .pipe(withStatics((s) => ({ zod: zod(s) })))
export type Status = z.infer<typeof Status> export type Status = typeof Status.Type
enum SymbolKind { enum SymbolKind {
File = 1, File = 1,

View file

@ -90,7 +90,7 @@ export const FileRoutes = lazy(() =>
description: "Symbols", description: "Symbols",
content: { content: {
"application/json": { "application/json": {
schema: resolver(LSP.Symbol.array()), schema: resolver(LSP.Symbol.zod.array()),
}, },
}, },
}, },

View file

@ -260,7 +260,7 @@ export const InstanceRoutes = (upgrade: UpgradeWebSocket): Hono => {
description: "LSP server status", description: "LSP server status",
content: { content: {
"application/json": { "application/json": {
schema: resolver(LSP.Status.array()), schema: resolver(LSP.Status.zod.array()),
}, },
}, },
}, },

View file

@ -159,7 +159,7 @@ export const FileSource = FilePartSourceBase.extend({
export const SymbolSource = FilePartSourceBase.extend({ export const SymbolSource = FilePartSourceBase.extend({
type: z.literal("symbol"), type: z.literal("symbol"),
path: z.string(), path: z.string(),
range: LSP.Range, range: LSP.Range.zod,
name: z.string(), name: z.string(),
kind: z.number().int(), kind: z.number().int(),
}).meta({ }).meta({