Skip to content

Commit

Permalink
fix: update root node presentation (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch authored Oct 13, 2024
1 parent 4222c0d commit 9ede32e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,46 @@ class SnykToolWindowSnykScanListenerLS(
)
}

private fun displayResults(snykResults: Map<SnykFile, List<ScanIssue>>, enabledInSettings: Boolean, filterTree: Boolean, rootNode: DefaultMutableTreeNode) {
private fun displayResults(
snykResults: Map<SnykFile, List<ScanIssue>>,
enabledInSettings: Boolean,
filterTree: Boolean,
rootNode: DefaultMutableTreeNode,
issueType: String
) {
if (disposed) return
if (getSnykCachedResults(project)?.currentIacError != null) return

displayIssues(
enabledInSettings = enabledInSettings,
filterTree = filterTree,
snykResults = snykResults,
rootNode = rootNode,
iacResultsCount = snykResults.values.flatten().distinct().size,
fixableIssuesCount = snykResults.values.flatten().count { it.additionalData.isUpgradable }
)
val flattenedResults = snykResults.values.flatten()

when (issueType) {
ScanIssue.OPEN_SOURCE -> {
val ossResultsCount =
flattenedResults.filter { it.filterableIssueType == ScanIssue.OPEN_SOURCE }.distinct().size
displayIssues(
enabledInSettings = enabledInSettings,
filterTree = filterTree,
snykResults = snykResults,
rootNode = rootNode,
ossResultsCount = ossResultsCount,
fixableIssuesCount = flattenedResults.count { it.additionalData.isUpgradable }
)
}

ScanIssue.INFRASTRUCTURE_AS_CODE -> {
val iacResultsCount =
flattenedResults.filter { it.filterableIssueType == ScanIssue.INFRASTRUCTURE_AS_CODE }
.distinct().size
displayIssues(
enabledInSettings = enabledInSettings,
filterTree = filterTree,
snykResults = snykResults,
rootNode = rootNode,
iacResultsCount = iacResultsCount,
fixableIssuesCount = flattenedResults.count { it.additionalData.isUpgradable }
)
}
}
}

fun displayOssResults(snykResults: Map<SnykFile, List<ScanIssue>>) {
Expand All @@ -189,15 +217,27 @@ class SnykToolWindowSnykScanListenerLS(

val settings = pluginSettings()

displayResults(snykResults, settings.ossScanEnable, settings.treeFiltering.ossResults, this.rootOssIssuesTreeNode)
displayResults(
snykResults,
settings.ossScanEnable,
settings.treeFiltering.ossResults,
this.rootOssIssuesTreeNode,
ScanIssue.OPEN_SOURCE
)
}

fun displayIacResults(snykResults: Map<SnykFile, List<ScanIssue>>) {
if (disposed) return
if (getSnykCachedResults(project)?.currentIacError != null) return

val settings = pluginSettings()
displayResults(snykResults, settings.iacScanEnabled, settings.treeFiltering.iacResults, this.rootIacIssuesTreeNode)
displayResults(
snykResults,
settings.iacScanEnabled,
settings.treeFiltering.iacResults,
this.rootIacIssuesTreeNode,
ScanIssue.INFRASTRUCTURE_AS_CODE,
)
}

private fun displayIssues(
Expand Down Expand Up @@ -305,7 +345,7 @@ class SnykToolWindowSnykScanListenerLS(
} else {
"ies"
}
text = "$issuesCount vulnerabilit$plural found by Snyk"
text = "$issuesCount vulnerabilit$plural found by Snyk"
if (pluginSettings().isGlobalIgnoresFeatureEnabled) {
text += ", $ignoredIssuesCount ignored"
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,18 @@ class LanguageServerWrapper(
fun sendScanCommand(project: Project) {
if (notAuthenticated()) return
DumbService.getInstance(project).runWhenSmart {
refreshFeatureFlags()
getTrustedContentRoots(project).forEach {
sendFolderScanCommand(it.path, project)
}
}
}

fun refreshFeatureFlags() {
runInBackground("Snyk: refreshing feature flags...") {
runAsync {
// this check should be async, as refresh is called from initialization and notAuthenticated is triggering
// initialization. So, to make it wait patiently for its turn, it needs to be checked and executed in a
// different thread.
if (notAuthenticated()) return@runInBackground
if (notAuthenticated()) return@runAsync
pluginSettings().isGlobalIgnoresFeatureEnabled = getFeatureFlagStatus("snykCodeConsistentIgnores")
}
}
Expand Down

0 comments on commit 9ede32e

Please sign in to comment.