@@ -129,12 +129,29 @@ class SnykLanguageClient(private val project: Project, val progressManager: Prog
129129 val firstDiagnostic = diagnosticsParams.diagnostics.firstOrNull()
130130 val product = firstDiagnostic?.source
131131
132- // If the diagnostics for the file is empty, clear the cache.
132+ // If the diagnostics for the file is empty, we only want to clear the cache for the product
133+ // that sent it.
134+ // However, if we don't know the product, we have to clear everything.
133135 if (firstDiagnostic == null ) {
134- scanPublisher.onPublishDiagnostics(LsProduct .Code , snykFile, emptySet())
135- scanPublisher.onPublishDiagnostics(LsProduct .OpenSource , snykFile, emptySet())
136- scanPublisher.onPublishDiagnostics(LsProduct .InfrastructureAsCode , snykFile, emptySet())
137- scanPublisher.onPublishDiagnostics(LsProduct .Secrets , snykFile, emptySet())
136+ // The language server sends empty diagnostics per product when it has finished a scan and
137+ // did not find anything.If the product is contained in the version of the file, use it to
138+ // clean only the product cache
139+ when (diagnosticsParams.version) {
140+ LsProduct .OpenSource .ordinal ->
141+ scanPublisher.onPublishDiagnostics(LsProduct .OpenSource , snykFile, emptySet())
142+ LsProduct .Code .ordinal ->
143+ scanPublisher.onPublishDiagnostics(LsProduct .Code , snykFile, emptySet())
144+ LsProduct .InfrastructureAsCode .ordinal ->
145+ scanPublisher.onPublishDiagnostics(LsProduct .InfrastructureAsCode , snykFile, emptySet())
146+ LsProduct .Secrets .ordinal ->
147+ scanPublisher.onPublishDiagnostics(LsProduct .Secrets , snykFile, emptySet())
148+ else -> {
149+ scanPublisher.onPublishDiagnostics(LsProduct .Code , snykFile, emptySet())
150+ scanPublisher.onPublishDiagnostics(LsProduct .OpenSource , snykFile, emptySet())
151+ scanPublisher.onPublishDiagnostics(LsProduct .InfrastructureAsCode , snykFile, emptySet())
152+ scanPublisher.onPublishDiagnostics(LsProduct .Secrets , snykFile, emptySet())
153+ }
154+ }
138155 return
139156 }
140157
0 commit comments