Skip to content

Commit 58df1ec

Browse files
Repaint UI only when insights list was changed
1 parent 773d5db commit 58df1ec

File tree

1 file changed

+22
-4
lines changed
  • ide-common/src/main/java/org/digma/intellij/plugin/refreshInsightsTask

1 file changed

+22
-4
lines changed

ide-common/src/main/java/org/digma/intellij/plugin/refreshInsightsTask/RefreshService.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import com.intellij.openapi.fileEditor.FileEditorManager
66
import com.intellij.openapi.project.Project
77
import com.intellij.openapi.rd.util.withUiContext
88
import com.intellij.openapi.vfs.VirtualFile
9+
import org.apache.commons.collections4.CollectionUtils
910
import org.digma.intellij.plugin.common.Backgroundable
1011
import org.digma.intellij.plugin.document.DocumentInfoContainer
1112
import org.digma.intellij.plugin.document.DocumentInfoService
1213
import org.digma.intellij.plugin.log.Log
14+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight
1315
import org.digma.intellij.plugin.ui.model.MethodScope
1416
import org.digma.intellij.plugin.ui.service.ErrorsViewService
1517
import org.digma.intellij.plugin.ui.service.InsightsViewService
@@ -75,11 +77,27 @@ class RefreshService(private val project: Project) {
7577

7678
private fun updateInsightsCacheForActiveDocument(selectedTextEditor: Editor?, documentInfoContainer: DocumentInfoContainer?, scope: MethodScope) {
7779
val selectedDocument = selectedTextEditor?.document
78-
if (selectedDocument != null) {
79-
documentInfoContainer?.updateCache()
80+
if (selectedDocument != null && documentInfoContainer != null) {
81+
val oldInsights = documentInfoContainer.allInsights
82+
83+
documentInfoContainer.updateCache()
84+
85+
val newInsights = documentInfoContainer.allInsights
86+
87+
// refresh the UI ONLY if newInsights list is different from oldInsights
88+
if (dataChanged(oldInsights, newInsights)) {
89+
insightsViewService.updateInsightsModel(scope.getMethodInfo())
90+
errorsViewService.updateErrorsModel(scope.getMethodInfo())
91+
}
8092
}
81-
insightsViewService.updateInsightsModel(scope.getMethodInfo())
82-
errorsViewService.updateErrorsModel(scope.getMethodInfo())
93+
}
94+
95+
private fun dataChanged(oldInsights: List<CodeObjectInsight?>, newInsights: List<CodeObjectInsight?>): Boolean {
96+
val isEqual = CollectionUtils.isEqualCollection(
97+
oldInsights,
98+
newInsights
99+
)
100+
return !isEqual
83101
}
84102

85103
private fun notifyRefreshInsightsTaskStarted(fileUri: String?) {

0 commit comments

Comments
 (0)