Skip to content

Commit 605814b

Browse files
committed
fix: race condition for showing error in the tree view, remove notification when Snyk Code isn't enabled for folder
1 parent 9544232 commit 605814b

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ ij_kotlin_packages_to_use_import_on_demand = ^
2121
ij_kotlin_name_count_to_use_star_import = 999
2222
ij_kotlin_name_count_to_use_star_import_for_members = 999
2323
ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^
24+
ktlint_standard = disabled
25+
ktlint_official = disabled
26+
ktlint_experimental = disabled
2427

2528
[*.java]
2629
ij_java_names_count_to_use_import_on_demand = 999

src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowPanel.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,14 @@ class SnykToolWindowPanel(
561561
securityIssuesCount: Int?,
562562
addHMLPostfix: String
563563
) = when {
564-
getSnykCachedResults(project)?.currentSnykCodeError != null -> "$CODE_SECURITY_ROOT_TEXT (error)"
564+
getSnykCachedResults(project)?.currentSnykCodeError != null -> {
565+
val errorMessage = getSnykCachedResults(project)?.currentSnykCodeError?.message
566+
val errorSuffix = when {
567+
errorMessage?.contains("not enabled", ignoreCase = true) == true -> "(disabled at Snyk)"
568+
else -> "(error)"
569+
}
570+
"$CODE_SECURITY_ROOT_TEXT $errorSuffix"
571+
}
565572
isSnykCodeRunning(project) &&
566573
settings.snykCodeSecurityIssuesScanEnable -> "$CODE_SECURITY_ROOT_TEXT (scanning...)"
567574

@@ -762,6 +769,9 @@ class SnykToolWindowPanel(
762769
@TestOnly
763770
fun getRootOssIssuesTreeNode() = rootOssTreeNode
764771

772+
@TestOnly
773+
fun getRootSecurityIssuesTreeNode() = rootSecurityIssuesTreeNode
774+
765775
fun getTree() = vulnerabilitiesTree
766776

767777
@TestOnly

src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowScanListener.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ class SnykToolWindowSnykScanListener(
7171

7272
override fun scanningStarted(snykScan: SnykScanParams) {
7373
if (disposed) return
74-
ApplicationManager.getApplication().invokeLater {
75-
this.snykToolWindowPanel.cleanUiAndCaches()
76-
this.snykToolWindowPanel.updateTreeRootNodesPresentation()
77-
this.snykToolWindowPanel.displayScanningMessage()
78-
}
74+
75+
this.snykToolWindowPanel.cleanUiAndCaches()
76+
this.snykToolWindowPanel.updateTreeRootNodesPresentation()
77+
this.snykToolWindowPanel.displayScanningMessage()
7978
}
8079

8180
override fun scanningSnykCodeFinished() {
@@ -108,25 +107,26 @@ class SnykToolWindowSnykScanListener(
108107
}
109108

110109
override fun scanningError(snykScan: SnykScanParams) {
111-
when (LsProduct.getFor(snykScan.product)) {
112-
LsProduct.OpenSource -> {
113-
removeChildrenAndRefresh(rootOssIssuesTreeNode)
114-
this.rootOssIssuesTreeNode.userObject = "$OSS_ROOT_TEXT (error)"
115-
}
110+
if (disposed) return
111+
ApplicationManager.getApplication().invokeLater {
112+
when (LsProduct.getFor(snykScan.product)) {
113+
LsProduct.OpenSource -> {
114+
removeChildrenAndRefresh(rootOssIssuesTreeNode)
115+
}
116116

117-
LsProduct.Code -> {
118-
removeChildrenAndRefresh(rootSecurityIssuesTreeNode)
119-
rootSecurityIssuesTreeNode.userObject = "$CODE_SECURITY_ROOT_TEXT (error)"
120-
}
117+
LsProduct.Code -> {
118+
removeChildrenAndRefresh(rootSecurityIssuesTreeNode)
119+
}
121120

122-
LsProduct.InfrastructureAsCode -> {
123-
removeChildrenAndRefresh(rootIacIssuesTreeNode)
124-
rootIacIssuesTreeNode.userObject = "$IAC_ROOT_TEXT (error)"
125-
}
121+
LsProduct.InfrastructureAsCode -> {
122+
removeChildrenAndRefresh(rootIacIssuesTreeNode)
123+
}
126124

127-
LsProduct.Unknown -> Unit
125+
LsProduct.Unknown -> Unit
126+
}
127+
snykToolWindowPanel.updateTreeRootNodesPresentation()
128+
refreshAnnotationsForOpenFiles(project)
128129
}
129-
refreshAnnotationsForOpenFiles(project)
130130
}
131131

132132
private fun removeChildrenAndRefresh(node: DefaultMutableTreeNode) {

src/main/kotlin/snyk/common/SnykCachedResults.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ class SnykCachedResults(
109109
}
110110

111111
val errorMessage = snykScan.errorMessage ?: "Scanning error for project ${project.name}. Data: $snykScan"
112-
SnykBalloonNotificationHelper.showError(errorMessage, project)
112+
if (snykScan.showNotification) {
113+
SnykBalloonNotificationHelper.showError(errorMessage, project)
114+
}
113115
}
114116

115117
override fun onPublishDiagnostics(

src/main/kotlin/snyk/common/lsp/Types.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ data class SnykScanParams(
3737
val issues: List<ScanIssue>, // Issues contain the scan results in the common issues model
3838
val errorMessage: String? = null, // Error Message if applicable
3939
val cliError: CliError? = null, // Structured error information if applicable
40+
val showNotification: Boolean
4041
)
4142

4243
data class SnykScanSummaryParams(

0 commit comments

Comments
 (0)