From 9c13996ee9189517946b4078a1ba52b82ca08cc0 Mon Sep 17 00:00:00 2001 From: Arunprasad Rajkumar Date: Mon, 21 Dec 2020 13:05:18 +0530 Subject: [PATCH] fix: Clear diagnostics before generating new set of diagnostics (#177) --- src/server.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/server.ts b/src/server.ts index 70d7dde7..22d88c73 100644 --- a/src/server.ts +++ b/src/server.ts @@ -251,21 +251,19 @@ function slicePayload(payload, batchSize, ecosystem): any { const regexVersion = new RegExp(/^([a-zA-Z0-9]+\.)?([a-zA-Z0-9]+\.)?([a-zA-Z0-9]+\.)?([a-zA-Z0-9]+)$/); const sendDiagnostics = async (ecosystem: string, diagnosticFilePath: string, contents: string, collector: IDependencyCollector) => { + // clear all diagnostics + connection.sendDiagnostics({ uri: diagnosticFilePath, diagnostics: [] }); connection.sendNotification('caNotification', {data: caDefaultMsg, done: false, uri: diagnosticFilePath}); let deps = null; try { const start = new Date().getTime(); deps = await collector.collect(contents); const end = new Date().getTime(); - connection.console.log(`manifest parse took ${end - start} ms`); + connection.console.log(`manifest parse took ${end - start} ms, found ${deps.length} deps`); } catch (error) { - // Error can be raised during golang `go list ` command only. - if (ecosystem == "golang") { - connection.console.warn(`Command execution failed with error: ${error}`); - connection.sendNotification('caError', {data: error, uri: diagnosticFilePath}); - connection.sendDiagnostics({ uri: diagnosticFilePath, diagnostics: [] }); - return; - } + connection.console.warn(`Error: ${error}`); + connection.sendNotification('caError', {data: error, uri: diagnosticFilePath}); + return; } let validPackages = deps;