From c0fd3b829ac0a69dda22e9eb937464aacb8af491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20S=C3=B8rensen?= Date: Sat, 18 Nov 2017 22:54:16 +0100 Subject: [PATCH] Remove diagnostics for deleted files --- src/diagnostics.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 66e9548c4..fb4ae30cb 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -3,6 +3,7 @@ * vscode inspector via the DiagnosticsCollection. */ import * as vscode from 'vscode' +import { existsSync } from 'fs' // import { DiagnosticCollection, Uri, Diagnostic, Range, DiagnosticSeverity } from 'vscode' import { TestFileAssertionStatus } from 'jest-editor-support' import { TestReconciliationState } from './TestReconciliationState' @@ -45,7 +46,6 @@ export function updateDiagnostics(testResults: TestFileAssertionStatus[], diagno testResults.forEach(result => { const uri = vscode.Uri.file(result.file) - switch (result.status) { case TestReconciliationState.KnownFail: if (result.assertions.length <= 0) { @@ -59,6 +59,17 @@ export function updateDiagnostics(testResults: TestFileAssertionStatus[], diagno break } }) + + // Remove diagnostics for files no longer in existence + const toBeDeleted = [] + diagnostics.forEach(uri => { + if (!existsSync(uri.fsPath)) { + toBeDeleted.push(uri) + } + }) + toBeDeleted.forEach(uri => { + diagnostics.delete(uri) + }) } export function resetDiagnostics(diagnostics: vscode.DiagnosticCollection) {