From 40d544f7a5250d277f934036b2c101f860253424 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Thu, 22 Feb 2024 15:23:41 +0100 Subject: [PATCH] fix: isSnykCodeRunning, cache --- .../ui/toolwindow/SnykToolWindowSnykCodeScanListenerLS.kt | 2 -- src/main/kotlin/snyk/common/SnykCachedResults.kt | 5 +---- src/main/kotlin/snyk/common/lsp/ScanState.kt | 2 +- src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt | 2 ++ src/main/kotlin/snyk/common/lsp/Types.kt | 1 - 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykCodeScanListenerLS.kt b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykCodeScanListenerLS.kt index 39648879f..e2fd8d1e4 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykCodeScanListenerLS.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykCodeScanListenerLS.kt @@ -19,7 +19,6 @@ import io.snyk.plugin.ui.toolwindow.nodes.root.RootSecurityIssuesTreeNode import io.snyk.plugin.ui.toolwindow.nodes.secondlevel.SnykCodeFileTreeNodeFromLS import snyk.common.ProductType import snyk.common.lsp.ScanIssue -import snyk.common.lsp.ScanState import snyk.common.lsp.SnykScanParams import javax.swing.JTree import javax.swing.tree.DefaultMutableTreeNode @@ -34,7 +33,6 @@ class SnykToolWindowSnykCodeScanListenerLS( override fun scanningStarted(snykScan: SnykScanParams) { ApplicationManager.getApplication().invokeLater { - if (snykScan.product != ScanState.SNYK_CODE) return@invokeLater rootSecurityIssuesTreeNode.userObject = "$CODE_SECURITY_ROOT_TEXT (scanning...)" rootQualityIssuesTreeNode.userObject = "$CODE_QUALITY_ROOT_TEXT (scanning...)" } diff --git a/src/main/kotlin/snyk/common/SnykCachedResults.kt b/src/main/kotlin/snyk/common/SnykCachedResults.kt index 8701a1854..4c7fd2367 100644 --- a/src/main/kotlin/snyk/common/SnykCachedResults.kt +++ b/src/main/kotlin/snyk/common/SnykCachedResults.kt @@ -12,7 +12,6 @@ import io.snyk.plugin.snykcode.core.SnykCodeFile import io.snyk.plugin.ui.SnykBalloonNotificationHelper import io.snyk.plugin.ui.toolwindow.SnykToolWindowPanel import snyk.common.lsp.ScanIssue -import snyk.common.lsp.ScanState import snyk.common.lsp.SnykScanParams import snyk.container.ContainerResult import snyk.container.ContainerService @@ -126,18 +125,16 @@ class SnykCachedResults(val project: Project) { object : SnykCodeScanListenerLS { val logger = logger() override fun scanningStarted(snykScan: SnykScanParams) { - if (snykScan.product != ScanState.SNYK_CODE) return logger.info("scanningStarted for project ${project.name}, emptying cache.") } override fun scanningSnykCodeFinished(snykCodeResults: Map>) { + currentSnykCodeResultsLS.clear() currentSnykCodeResultsLS.putAll(snykCodeResults) logger.info("scanning finished for project ${project.name}, assigning cache.") } override fun scanningSnykCodeError(snykScan: SnykScanParams) { - if (snykScan.product != ScanState.SNYK_CODE) return - SnykBalloonNotificationHelper .showError( "scanning error for project ${project.name}, emptying cache.Data: $snykScan", diff --git a/src/main/kotlin/snyk/common/lsp/ScanState.kt b/src/main/kotlin/snyk/common/lsp/ScanState.kt index c7d5314dc..2336c0a0a 100644 --- a/src/main/kotlin/snyk/common/lsp/ScanState.kt +++ b/src/main/kotlin/snyk/common/lsp/ScanState.kt @@ -3,6 +3,6 @@ package snyk.common.lsp import java.util.Collections object ScanState { - const val SNYK_CODE = "Snyk Code" + const val SNYK_CODE = "code" val scanInProgress: MutableMap = Collections.synchronizedMap(mutableMapOf()) } diff --git a/src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt b/src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt index c7c5b6ba9..e932b5455 100644 --- a/src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt +++ b/src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt @@ -17,6 +17,7 @@ import com.intellij.openapi.util.io.toNioPathOrNull import io.snyk.plugin.events.SnykCodeScanListenerLS import io.snyk.plugin.getContentRootVirtualFiles import io.snyk.plugin.getSyncPublisher +import io.snyk.plugin.isSnykCodeLSEnabled import io.snyk.plugin.pluginSettings import io.snyk.plugin.snykcode.core.SnykCodeFile import io.snyk.plugin.toVirtualFile @@ -88,6 +89,7 @@ class SnykLanguageClient : LanguageClient { @JsonNotification(value = "$/snyk.scan") fun snykScan(snykScan: SnykScanParams) { + if (snykScan.product != ScanState.SNYK_CODE || !isSnykCodeLSEnabled()) return try { getScanPublishersFor(snykScan).forEach { (project, scanPublisher) -> when (snykScan.status) { diff --git a/src/main/kotlin/snyk/common/lsp/Types.kt b/src/main/kotlin/snyk/common/lsp/Types.kt index d175e0d93..b3b886005 100644 --- a/src/main/kotlin/snyk/common/lsp/Types.kt +++ b/src/main/kotlin/snyk/common/lsp/Types.kt @@ -160,7 +160,6 @@ data class MarkerPosition( result = 31 * result + file.hashCode() return result } - } data class DataFlow(