From 09fe662262e8fd00c371e8741f7f29d933d5e968 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Wed, 20 Mar 2024 17:20:29 +0100 Subject: [PATCH] fix: UI freezes, code vision refreshes --- src/main/kotlin/io/snyk/plugin/Utils.kt | 7 +------ .../snyk/plugin/services/download/CliDownloaderService.kt | 2 +- src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt | 8 ++++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/io/snyk/plugin/Utils.kt b/src/main/kotlin/io/snyk/plugin/Utils.kt index 215a0eb65..19b098589 100644 --- a/src/main/kotlin/io/snyk/plugin/Utils.kt +++ b/src/main/kotlin/io/snyk/plugin/Utils.kt @@ -3,10 +3,7 @@ package io.snyk.plugin import com.intellij.codeInsight.codeVision.CodeVisionHost -import com.intellij.codeInsight.codeVision.CodeVisionInitializer import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer -import com.intellij.codeInsight.hints.VcsCodeVisionProvider -import com.intellij.codeInsight.hints.codeVision.CodeVisionFusCollector import com.intellij.ide.util.PsiNavigationSupport import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager @@ -34,7 +31,6 @@ import com.intellij.psi.PsiManager import com.intellij.util.Alarm import com.intellij.util.FileContentUtil import com.intellij.util.messages.Topic -import com.jetbrains.rd.util.reactive.Signal import io.snyk.plugin.analytics.AnalyticsScanListener import io.snyk.plugin.net.ClientException import io.snyk.plugin.services.SnykAnalyticsService @@ -52,7 +48,6 @@ import io.snyk.plugin.ui.SnykBalloonNotificationHelper import io.snyk.plugin.ui.toolwindow.SnykToolWindowFactory import io.snyk.plugin.ui.toolwindow.SnykToolWindowPanel import org.apache.commons.lang3.SystemUtils -import org.jetbrains.kotlin.idea.codeinsight.utils.findExistingEditor import snyk.advisor.AdvisorService import snyk.advisor.AdvisorServiceImpl import snyk.advisor.SnykAdvisorModel @@ -309,7 +304,7 @@ fun findPsiFileIgnoringExceptions(virtualFile: VirtualFile, project: Project): P fun refreshAnnotationsForOpenFiles(project: Project) { if (project.isDisposed) return - VirtualFileManager.getInstance().asyncRefresh(); + VirtualFileManager.getInstance().asyncRefresh() val openFiles = FileEditorManager.getInstance(project).openFiles diff --git a/src/main/kotlin/io/snyk/plugin/services/download/CliDownloaderService.kt b/src/main/kotlin/io/snyk/plugin/services/download/CliDownloaderService.kt index 2ce3581c5..943dd00b0 100644 --- a/src/main/kotlin/io/snyk/plugin/services/download/CliDownloaderService.kt +++ b/src/main/kotlin/io/snyk/plugin/services/download/CliDownloaderService.kt @@ -83,7 +83,7 @@ class SnykCliDownloaderService { val languageServerWrapper = LanguageServerWrapper.getInstance() try { - if (languageServerWrapper.ensureLanguageServerInitialized()) { + if (languageServerWrapper.isInitialized) { try { languageServerWrapper.shutdown().get(2, TimeUnit.SECONDS) } catch (e: RuntimeException) { diff --git a/src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt b/src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt index 83f2fffc9..05fabf5eb 100644 --- a/src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt +++ b/src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt @@ -220,13 +220,13 @@ class LanguageServerWrapper( } fun ensureLanguageServerInitialized(): Boolean { - try { - if (!isInitialized) { + if (!isInitialized) { + try { isInitializing.lock() initialize() + } finally { + isInitializing.unlock() } - } finally { - if (isInitializing.isHeldByCurrentThread) isInitializing.unlock() } return isInitialized }