Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit ef78fd8

Browse files
authored
fix: debounce LSP diagnostics to get complete results (anomalyco#5600)
1 parent 72ebaeb commit ef78fd8

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

packages/opencode/src/lsp/client.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { withTimeout } from "../util/timeout"
1313
import { Instance } from "../project/instance"
1414
import { Filesystem } from "../util/filesystem"
1515

16+
const DIAGNOSTICS_DEBOUNCE_MS = 150
17+
1618
export namespace LSPClient {
1719
const log = Log.create({ service: "lsp.client" })
1820

@@ -188,20 +190,26 @@ export namespace LSPClient {
188190
)
189191
log.info("waiting for diagnostics", { path: normalizedPath })
190192
let unsub: () => void
193+
let debounceTimer: ReturnType<typeof setTimeout> | undefined
191194
return await withTimeout(
192195
new Promise<void>((resolve) => {
193196
unsub = Bus.subscribe(Event.Diagnostics, (event) => {
194197
if (event.properties.path === normalizedPath && event.properties.serverID === result.serverID) {
195-
log.info("got diagnostics", { path: normalizedPath })
196-
unsub?.()
197-
resolve()
198+
// Debounce to allow LSP to send follow-up diagnostics (e.g., semantic after syntax)
199+
if (debounceTimer) clearTimeout(debounceTimer)
200+
debounceTimer = setTimeout(() => {
201+
log.info("got diagnostics", { path: normalizedPath })
202+
unsub?.()
203+
resolve()
204+
}, DIAGNOSTICS_DEBOUNCE_MS)
198205
}
199206
})
200207
}),
201208
3000,
202209
)
203210
.catch(() => {})
204211
.finally(() => {
212+
if (debounceTimer) clearTimeout(debounceTimer)
205213
unsub?.()
206214
})
207215
},

0 commit comments

Comments
 (0)