From 71c57a31f721b46b694ad294fd11f63a44b165a6 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:27:58 -0400 Subject: [PATCH] Wait for diagnostics to update before continuing --- src/ClaudeDev.ts | 4 +++- src/integrations/DiagnosticsMonitor.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ClaudeDev.ts b/src/ClaudeDev.ts index 2f7e8cf..58424f0 100644 --- a/src/ClaudeDev.ts +++ b/src/ClaudeDev.ts @@ -1855,9 +1855,11 @@ ${this.customInstructions.trim()} await delay(300) // delay after saving file to let terminals/diagnostics catch up } + let terminalWasBusy = false if (allTerminals.length > 0) { // wait for terminals to cool down // note this does not mean they're actively running just that they recently output something + terminalWasBusy = allTerminals.some((t) => this.terminalManager.isProcessHot(t.id)) await pWaitFor(() => allTerminals.every((t) => !this.terminalManager.isProcessHot(t.id)), { interval: 100, timeout: 15_000, @@ -1866,7 +1868,7 @@ ${this.customInstructions.trim()} // we want to get diagnostics AFTER terminal cools down for a few reasons: terminal could be scaffolding a project, dev servers (compilers like webpack) will first re-compile and then send diagnostics, etc let diagnosticsDetails = "" - const diagnostics = await this.diagnosticsMonitor.getCurrentDiagnostics(this.didEditFile) // if claude edited the workspace then wait a bit for updated diagnostics + const diagnostics = await this.diagnosticsMonitor.getCurrentDiagnostics(this.didEditFile || terminalWasBusy) // if claude ran a command (ie npm install) or edited the workspace then wait a bit for updated diagnostics for (const [uri, fileDiagnostics] of diagnostics) { const problems = fileDiagnostics.filter( (d) => diff --git a/src/integrations/DiagnosticsMonitor.ts b/src/integrations/DiagnosticsMonitor.ts index 7c1ff34..c0b3b35 100644 --- a/src/integrations/DiagnosticsMonitor.ts +++ b/src/integrations/DiagnosticsMonitor.ts @@ -47,8 +47,8 @@ class DiagnosticsMonitor { public async getCurrentDiagnostics(shouldWaitForChanges: boolean): Promise { const currentDiagnostics = this.getDiagnostics() // get all diagnostics for files open in workspace (not just errors/warnings so our did update check is more likely to detect updated diagnostics) - if (!shouldWaitForChanges) { + this.lastDiagnostics = currentDiagnostics return currentDiagnostics } @@ -68,6 +68,7 @@ class DiagnosticsMonitor { ) ) if (hasErrorsOrWarnings) { + console.log("Existing errors or warnings detected, extending timeout", currentDiagnostics) timeout = 5_000 } @@ -84,8 +85,12 @@ class DiagnosticsMonitor { }, timeout) const disposable = this.diagnosticsChangeEmitter.event(() => { + const updatedDiagnostics = this.getDiagnostics() // I thought this would only trigger when diagnostics changed, but that's not the case. + if (deepEqual(this.lastDiagnostics, updatedDiagnostics)) { + // diagnostics have not changed, ignoring... + return + } cleanup() - const updatedDiagnostics = this.getDiagnostics() this.lastDiagnostics = updatedDiagnostics resolve(updatedDiagnostics) })