This repository was archived by the owner on Apr 1, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
packages/opencode/src/lsp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import { withTimeout } from "../util/timeout"
1313import { Instance } from "../project/instance"
1414import { Filesystem } from "../util/filesystem"
1515
16+ const DIAGNOSTICS_DEBOUNCE_MS = 150
17+
1618export 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 } ,
You can’t perform that action at this time.
0 commit comments