diff options
| author | Dax Raad <[email protected]> | 2025-05-20 22:27:30 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-26 12:40:17 -0400 |
| commit | f0f55bc75ff2bbc6690ae61c771a46de7c2bb17d (patch) | |
| tree | 4a6bd67984b9cf4f3129f2d707f650d020016b49 /js | |
| parent | 2860a2bb1a1f227c26b02f1325454ab79d6f6451 (diff) | |
| download | opencode-f0f55bc75ff2bbc6690ae61c771a46de7c2bb17d.tar.gz opencode-f0f55bc75ff2bbc6690ae61c771a46de7c2bb17d.zip | |
sync
Diffstat (limited to 'js')
| -rw-r--r-- | js/src/lsp/client.ts | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/js/src/lsp/client.ts b/js/src/lsp/client.ts index e6cfdb2eb..f5b0f6bee 100644 --- a/js/src/lsp/client.ts +++ b/js/src/lsp/client.ts @@ -9,12 +9,23 @@ import { import { App } from "../app"; import { Log } from "../util/log"; import { LANGUAGE_EXTENSIONS } from "./language"; +import { Bus } from "../bus"; +import z from "zod/v4"; export namespace LSPClient { const log = Log.create({ service: "lsp.client" }); export type Info = Awaited<ReturnType<typeof create>>; + export const Event = { + Diagnostics: Bus.event( + "lsp.client.diagnostics", + z.object({ + path: z.string(), + }), + ), + }; + export async function create(input: { cmd: string[] }) { log.info("starting client", input); let version = 0; @@ -33,10 +44,12 @@ export namespace LSPClient { const diagnostics = new Map<string, any>(); connection.onNotification("textDocument/publishDiagnostics", (params) => { + const path = new URL(params.uri).pathname; log.info("textDocument/publishDiagnostics", { - path: new URL(params.uri).pathname, + path, }); - diagnostics.set(new URL(params.uri).pathname, params.diagnostics); + diagnostics.set(path, params.diagnostics); + Bus.publish(Event.Diagnostics, { path }); }); connection.listen(); @@ -144,31 +157,26 @@ export namespace LSPClient { }, async refreshDiagnostics(input: { path: string }) { log.info("refreshing diagnostics", input); - let notif: Disposable | undefined; + let unsub: () => void; + let timeout: NodeJS.Timeout; return await Promise.race([ new Promise<void>(async (resolve) => { - notif = connection.onNotification( - "textDocument/publishDiagnostics", - (params) => { + unsub = Bus.subscribe(Event.Diagnostics, (event) => { + if (event.properties.path === input.path) { log.info("refreshed diagnostics", input); - if (new URL(params.uri).pathname === input.path) { - diagnostics.set( - new URL(params.uri).pathname, - params.diagnostics, - ); - resolve(); - notif?.dispose(); - } - }, - ); + clearTimeout(timeout); + unsub?.(); + resolve(); + } + }); await result.notify.change(input); }), - new Promise<void>((resolve) => - setTimeout(() => { - notif?.dispose(); + new Promise<void>((resolve) => { + timeout = setTimeout(() => { + unsub?.(); resolve(); - }, 5000), - ), + }, 5000); + }), ]); }, }; |
