|
@@ -13,6 +13,8 @@ import { withTimeout } from "../util/timeout"
|
|
|
import { Instance } from "../project/instance"
|
|
import { Instance } from "../project/instance"
|
|
|
import { Filesystem } from "../util/filesystem"
|
|
import { Filesystem } from "../util/filesystem"
|
|
|
|
|
|
|
|
|
|
+const DIAGNOSTICS_DEBOUNCE_MS = 150
|
|
|
|
|
+
|
|
|
export namespace LSPClient {
|
|
export namespace LSPClient {
|
|
|
const log = Log.create({ service: "lsp.client" })
|
|
const log = Log.create({ service: "lsp.client" })
|
|
|
|
|
|
|
@@ -188,13 +190,18 @@ export namespace LSPClient {
|
|
|
)
|
|
)
|
|
|
log.info("waiting for diagnostics", { path: normalizedPath })
|
|
log.info("waiting for diagnostics", { path: normalizedPath })
|
|
|
let unsub: () => void
|
|
let unsub: () => void
|
|
|
|
|
+ let debounceTimer: ReturnType<typeof setTimeout> | undefined
|
|
|
return await withTimeout(
|
|
return await withTimeout(
|
|
|
new Promise<void>((resolve) => {
|
|
new Promise<void>((resolve) => {
|
|
|
unsub = Bus.subscribe(Event.Diagnostics, (event) => {
|
|
unsub = Bus.subscribe(Event.Diagnostics, (event) => {
|
|
|
if (event.properties.path === normalizedPath && event.properties.serverID === result.serverID) {
|
|
if (event.properties.path === normalizedPath && event.properties.serverID === result.serverID) {
|
|
|
- log.info("got diagnostics", { path: normalizedPath })
|
|
|
|
|
- unsub?.()
|
|
|
|
|
- resolve()
|
|
|
|
|
|
|
+ // Debounce to allow LSP to send follow-up diagnostics (e.g., semantic after syntax)
|
|
|
|
|
+ if (debounceTimer) clearTimeout(debounceTimer)
|
|
|
|
|
+ debounceTimer = setTimeout(() => {
|
|
|
|
|
+ log.info("got diagnostics", { path: normalizedPath })
|
|
|
|
|
+ unsub?.()
|
|
|
|
|
+ resolve()
|
|
|
|
|
+ }, DIAGNOSTICS_DEBOUNCE_MS)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}),
|
|
}),
|
|
@@ -202,6 +209,7 @@ export namespace LSPClient {
|
|
|
)
|
|
)
|
|
|
.catch(() => {})
|
|
.catch(() => {})
|
|
|
.finally(() => {
|
|
.finally(() => {
|
|
|
|
|
+ if (debounceTimer) clearTimeout(debounceTimer)
|
|
|
unsub?.()
|
|
unsub?.()
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|