refactor(core): move database schema ownership (#29068)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
Dax 2026-05-30 21:08:38 -04:00 committed by GitHub
commit 7f571d36ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
390 changed files with 11106 additions and 9143 deletions

View file

@ -1,5 +1,3 @@
import { BusEvent } from "@/bus/bus-event"
import { Bus } from "@/bus"
import path from "path"
import { pathToFileURL, fileURLToPath } from "url"
import { createMessageConnection, StreamMessageReader, StreamMessageWriter } from "vscode-jsonrpc/node"
@ -11,8 +9,6 @@ import { Effect, Schema } from "effect"
import type * as LSPServer from "./server"
import { withTimeout } from "../util/timeout"
import { Filesystem } from "@/util/filesystem"
import { InstanceRef } from "@/effect/instance-ref"
import { makeRuntime } from "@/effect/run-service"
import type { InstanceContext } from "@/project/instance-context"
const DIAGNOSTICS_DEBOUNCE_MS = 150
@ -28,8 +24,6 @@ const FILE_CHANGE_CHANGED = 2
const TEXT_DOCUMENT_SYNC_INCREMENTAL = 2
const log = Log.create({ service: "lsp.client" })
const busRuntime = makeRuntime(Bus.Service, Bus.layer)
export type Info = NonNullable<Awaited<ReturnType<typeof create>>>
export type Diagnostic = VSCodeDiagnostic
@ -39,16 +33,6 @@ export class InitializeError extends Schema.TaggedErrorClass<InitializeError>()(
cause: Schema.optional(Schema.Defect),
}) {}
export const Event = {
Diagnostics: BusEvent.define(
"lsp.client.diagnostics",
Schema.Struct({
serverID: Schema.String,
path: Schema.String,
}),
),
}
type DocumentDiagnosticReport = {
items?: Diagnostic[]
relatedDocuments?: Record<string, DocumentDiagnosticReport>
@ -169,15 +153,12 @@ export async function create(input: {
const published = new Map<string, { at: number; version?: number }>()
const diagnosticRegistrations = new Map<string, CapabilityRegistration>()
const registrationListeners = new Set<() => void>()
const diagnosticListeners = new Set<(input: { path: string; serverID: string }) => void>()
const mergedDiagnostics = (filePath: string) =>
dedupeDiagnostics([...(pushDiagnostics.get(filePath) ?? []), ...(pullDiagnostics.get(filePath) ?? [])])
const updatePushDiagnostics = (filePath: string, next: Diagnostic[]) => {
pushDiagnostics.set(filePath, next)
void busRuntime.runPromise((svc) =>
svc
.publish(Event.Diagnostics, { path: filePath, serverID: input.serverID })
.pipe(Effect.provideService(InstanceRef, instance)),
)
for (const listener of diagnosticListeners) listener({ path: filePath, serverID: input.serverID })
}
const updatePullDiagnostics = (filePath: string, next: Diagnostic[]) => {
pullDiagnostics.set(filePath, next)
@ -525,14 +506,12 @@ export async function create(input: {
}
timeoutTimer = setTimeout(() => finish(false), request.timeout)
unsub = busRuntime.runSync((svc) =>
svc
.subscribeCallback(Event.Diagnostics, (event) => {
if (event.properties.path !== request.path || event.properties.serverID !== input.serverID) return
schedule()
})
.pipe(Effect.provideService(InstanceRef, instance)),
)
const listener = (event: { path: string; serverID: string }) => {
if (event.path !== request.path || event.serverID !== input.serverID) return
schedule()
}
diagnosticListeners.add(listener)
unsub = () => diagnosticListeners.delete(listener)
schedule()
})
}