From 7384c89dddcb8bdc65805dff003cd394461d9215 Mon Sep 17 00:00:00 2001 From: Sergey Rostov Date: Fri, 29 May 2020 12:53:05 +0300 Subject: [PATCH] GradleBuildRootsManager, minor: fix notifications --- .../gradle/roots/GradleBuildRootsManager.kt | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/scripting/gradle/roots/GradleBuildRootsManager.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/scripting/gradle/roots/GradleBuildRootsManager.kt index e38053ac575..7f3e353f350 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/scripting/gradle/roots/GradleBuildRootsManager.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/scripting/gradle/roots/GradleBuildRootsManager.kt @@ -115,7 +115,6 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(), fun markImportingInProgress(workingDir: String, inProgress: Boolean = true) { actualizeBuildRoot(workingDir)?.importing = inProgress updateNotifications { it.startsWith(workingDir) } - hideNotificationForProjectImport(project) } fun update(build: KotlinDslGradleBuildSync) { @@ -125,8 +124,9 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(), if (root is Imported && root.data.models.isEmpty()) return } - val root = actualizeBuildRoot(build.workingDir) ?: return - root.importing = false + try { + val root = actualizeBuildRoot(build.workingDir) ?: return + root.importing = false if (root is Legacy) return @@ -139,9 +139,10 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(), GradleBuildRootDataSerializer.write(newSupport.dir ?: return, mergedData) newSupport.saveLastModifiedFiles() - add(newSupport) - - hideNotificationForProjectImport(project) + add(newSupport) + } finally { + updateNotifications { it.startsWith(build.workingDir) } + } } private fun merge(old: GradleBuildRootData, new: GradleBuildRootData): GradleBuildRootData { @@ -172,18 +173,7 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(), val changes = StandaloneScriptsUpdater.collectChanges(delegate = roots, update) updateNotifications { it in changes.new || it in changes.removed } - - runReadAction { - changes.new.forEach { - val virtualFile = LocalFileSystem.getInstance().findFileByPath(it) - if (virtualFile != null) { - val ktFile = PsiManager.getInstance(project).findFile(virtualFile) as? KtFile - if (ktFile != null) { - ScriptConfigurationManager.getInstance(project).getConfiguration(ktFile) - } - } - } - } + loadStandaloneScriptConfigurations(changes.new) } init { @@ -333,16 +323,19 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(), private fun updateNotifications(shouldUpdatePath: (String) -> Boolean) { if (!project.isOpen) return + // import notification is a balloon, so should be shown only for selected editor + FileEditorManager.getInstance(project).selectedEditor?.file?.let { + if (shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path)) { + checkUpToDate(it) + } + } + val openedScripts = FileEditorManager.getInstance(project).openFiles.filter { shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path) } if (openedScripts.isEmpty()) return - openedScripts.forEach { - checkUpToDate(it) - } - GlobalScope.launch(EDT(project)) { if (project.isDisposed) return@launch @@ -354,6 +347,20 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(), } } + private fun loadStandaloneScriptConfigurations(files: MutableSet) { + runReadAction { + files.forEach { + val virtualFile = LocalFileSystem.getInstance().findFileByPath(it) + if (virtualFile != null) { + val ktFile = PsiManager.getInstance(project).findFile(virtualFile) as? KtFile + if (ktFile != null) { + ScriptConfigurationManager.getInstance(project).getConfiguration(ktFile) + } + } + } + } + } + companion object { fun getInstance(project: Project): GradleBuildRootsManager = EPN.getPoint(project).extensionList.firstIsInstance()