Browse Source

Wait for diagnostics to update before continuing

Saoud Rizwan 1 year ago
parent
commit
71c57a31f7
2 changed files with 10 additions and 3 deletions
  1. 3 1
      src/ClaudeDev.ts
  2. 7 2
      src/integrations/DiagnosticsMonitor.ts

+ 3 - 1
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) =>

+ 7 - 2
src/integrations/DiagnosticsMonitor.ts

@@ -47,8 +47,8 @@ class DiagnosticsMonitor {
 
 	public async getCurrentDiagnostics(shouldWaitForChanges: boolean): Promise<FileDiagnostics> {
 		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)
 			})