Skip to content

Commit

Permalink
fix: isSnykCodeRunning, cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Feb 22, 2024
1 parent aad33a8 commit 40d544f
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)"
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/snyk/common/SnykCachedResults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -126,18 +125,16 @@ class SnykCachedResults(val project: Project) {
object : SnykCodeScanListenerLS {
val logger = logger<SnykCachedResults>()
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<SnykCodeFile, List<ScanIssue>>) {
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",
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/snyk/common/lsp/ScanState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Boolean> = Collections.synchronizedMap(mutableMapOf())
}
2 changes: 2 additions & 0 deletions src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,6 +89,7 @@ class SnykLanguageClient : LanguageClient {

@JsonNotification(value = "$/snyk.scan")
fun snykScan(snykScan: SnykScanParams) {

Check warning

Code scanning / detekt

Excessive nesting leads to hidden complexity. Prefer extracting code to make it easier to understand. Warning

Function snykScan is nested too deeply.
if (snykScan.product != ScanState.SNYK_CODE || !isSnykCodeLSEnabled()) return
try {
getScanPublishersFor(snykScan).forEach { (project, scanPublisher) ->
when (snykScan.status) {
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/snyk/common/lsp/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ data class MarkerPosition(
result = 31 * result + file.hashCode()
return result
}

}

data class DataFlow(
Expand Down

0 comments on commit 40d544f

Please sign in to comment.