From 0ec30a6935531506b7d71d6a2de36b4e24b9fc45 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Wed, 20 Mar 2024 18:13:07 +0100 Subject: [PATCH] fix: run more UI refreshes async & in read action --- .../io/snyk/plugin/services/SnykTaskQueueService.kt | 8 +++++--- .../io/snyk/plugin/ui/toolwindow/SnykToolWindowPanel.kt | 2 +- src/main/kotlin/snyk/common/AnnotatorCommon.kt | 5 +++-- .../kotlin/snyk/container/ContainerBulkFileListener.kt | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt b/src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt index 9812ed63d..6ddc50dd4 100644 --- a/src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt +++ b/src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt @@ -1,6 +1,8 @@ package io.snyk.plugin.services import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.ReadAction +import com.intellij.openapi.application.invokeLater import com.intellij.openapi.components.Service import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.fileEditor.FileDocumentManager @@ -153,7 +155,7 @@ class SnykTaskQueueService(val project: Project) { } } logger.debug("Container scan completed") - refreshAnnotationsForOpenFiles(project) + invokeLater { refreshAnnotationsForOpenFiles(project) } } }) } @@ -228,7 +230,7 @@ class SnykTaskQueueService(val project: Project) { ossResult.getFirstError()?.let { scanPublisher?.scanningOssError(it) } } } - refreshAnnotationsForOpenFiles(project) + invokeLater { refreshAnnotationsForOpenFiles(project) } } }) } @@ -271,7 +273,7 @@ class SnykTaskQueueService(val project: Project) { } } logger.debug("IaC scan completed") - refreshAnnotationsForOpenFiles(project) + invokeLater { refreshAnnotationsForOpenFiles(project) } } }) } diff --git a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowPanel.kt b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowPanel.kt index ffb14b715..83207e65d 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowPanel.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowPanel.kt @@ -444,10 +444,10 @@ class SnykToolWindowPanel(val project: Project) : JPanel(), Disposable { } } - refreshAnnotationsForOpenFiles(project) ApplicationManager.getApplication().invokeLater { doCleanUi(true) + refreshAnnotationsForOpenFiles(project) } } diff --git a/src/main/kotlin/snyk/common/AnnotatorCommon.kt b/src/main/kotlin/snyk/common/AnnotatorCommon.kt index 531f7b30e..651705f3d 100644 --- a/src/main/kotlin/snyk/common/AnnotatorCommon.kt +++ b/src/main/kotlin/snyk/common/AnnotatorCommon.kt @@ -1,5 +1,6 @@ package snyk.common +import com.intellij.openapi.application.invokeLater import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project import com.intellij.psi.PsiFile @@ -33,7 +34,7 @@ object AnnotatorCommon { SnykProductsOrSeverityListener.SNYK_ENABLEMENT_TOPIC, object : SnykProductsOrSeverityListener { override fun enablementChanged() { - refreshAnnotationsForOpenFiles(project) + invokeLater { refreshAnnotationsForOpenFiles(project) } } } ) @@ -42,7 +43,7 @@ object AnnotatorCommon { SnykSettingsListener.SNYK_SETTINGS_TOPIC, object : SnykSettingsListener { override fun settingsChanged() { - refreshAnnotationsForOpenFiles(project) + invokeLater { refreshAnnotationsForOpenFiles(project) } } } ) diff --git a/src/main/kotlin/snyk/container/ContainerBulkFileListener.kt b/src/main/kotlin/snyk/container/ContainerBulkFileListener.kt index d95bce367..f9553361a 100644 --- a/src/main/kotlin/snyk/container/ContainerBulkFileListener.kt +++ b/src/main/kotlin/snyk/container/ContainerBulkFileListener.kt @@ -74,8 +74,8 @@ class ContainerBulkFileListener : SnykBulkFileListener() { snykCachedResults.currentContainerResult = newContainerCache ApplicationManager.getApplication().invokeLater { getSnykToolWindowPanel(project)?.displayContainerResults(newContainerCache) + refreshAnnotationsForOpenFiles(project) } - refreshAnnotationsForOpenFiles(project) } private fun makeObsolete(containerIssuesForImage: ContainerIssuesForImage): ContainerIssuesForImage =