Diagnostics fixes

This commit is contained in:
Saoud Rizwan
2024-09-14 14:11:51 -04:00
parent d29f4a174c
commit b58d3dd622
2 changed files with 34 additions and 24 deletions

View File

@@ -46,7 +46,7 @@ class DiagnosticsMonitor {
}
public async getCurrentDiagnostics(shouldWaitForChanges: boolean): Promise<FileDiagnostics> {
const currentDiagnostics = vscode.languages.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)
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) {
return currentDiagnostics
@@ -61,18 +61,18 @@ class DiagnosticsMonitor {
return this.waitForUpdatedDiagnostics()
}
private async waitForUpdatedDiagnostics(timeout: number = 1_000): Promise<FileDiagnostics> {
private async waitForUpdatedDiagnostics(timeout: number = 500): Promise<FileDiagnostics> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
cleanup()
const finalDiagnostics = vscode.languages.getDiagnostics()
const finalDiagnostics = this.getDiagnostics()
this.lastDiagnostics = finalDiagnostics
resolve(finalDiagnostics)
}, timeout)
const disposable = this.diagnosticsChangeEmitter.event(() => {
cleanup()
const updatedDiagnostics = vscode.languages.getDiagnostics()
const updatedDiagnostics = this.getDiagnostics()
this.lastDiagnostics = updatedDiagnostics
resolve(updatedDiagnostics)
})
@@ -84,6 +84,12 @@ class DiagnosticsMonitor {
})
}
private getDiagnostics(): FileDiagnostics {
const allDiagnostics = vscode.languages.getDiagnostics()
// for our deep comparison concept to work, we can't be comparing when new open files with 0 diagnostics to report are added to the list
return allDiagnostics.filter(([_, diagnostics]) => diagnostics.length > 0)
}
public dispose() {
this.disposables.forEach((d) => d.dispose())
this.disposables = []