From 18c9d968f9a575d8b9dc7c98572f52586c7c12e1 Mon Sep 17 00:00:00 2001 From: Natalia Selezneva Date: Fri, 2 Nov 2018 12:58:41 +0300 Subject: [PATCH] Pass ResolveResult to ScriptNotificationPanel --- .../ScriptNewDependenciesNotification.kt | 18 ++++++++-------- .../dependencies/ScriptDependenciesLoader.kt | 21 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptNewDependenciesNotification.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptNewDependenciesNotification.kt index e7058300ca9..14bcc09418b 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptNewDependenciesNotification.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/ScriptNewDependenciesNotification.kt @@ -15,7 +15,7 @@ import com.intellij.ui.EditorNotificationPanel import com.intellij.ui.HyperlinkLabel import org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings import org.jetbrains.kotlin.psi.UserDataProperty -import kotlin.script.experimental.dependencies.ScriptDependencies +import kotlin.script.experimental.dependencies.DependenciesResolver.ResolveResult fun VirtualFile.removeScriptDependenciesNotificationPanel(project: Project) { val editor = FileEditorManager.getInstance(project).getSelectedEditor(this) ?: return @@ -24,20 +24,20 @@ fun VirtualFile.removeScriptDependenciesNotificationPanel(project: Project) { } fun VirtualFile.addScriptDependenciesNotificationPanel( - dependencies: ScriptDependencies, + resolveResult: ResolveResult, project: Project, - onClick: (ScriptDependencies) -> Unit + onClick: (ResolveResult) -> Unit ) { val editor = FileEditorManager.getInstance(project).getSelectedEditor(this) ?: return val existingPanel = editor.notificationPanel if (existingPanel != null) { - if (existingPanel.dependencies == dependencies) return + if (existingPanel.resolveResult.dependencies == resolveResult.dependencies) return editor.notificationPanel?.let { FileEditorManager.getInstance(project).removeTopComponent(editor, it) } } - val panel = NewScriptDependenciesNotificationPanel(onClick, dependencies, project) + val panel = NewScriptDependenciesNotificationPanel(onClick, resolveResult, project) editor.notificationPanel = panel FileEditorManager.getInstance(project).addTopComponent(editor, panel) } @@ -45,19 +45,19 @@ fun VirtualFile.addScriptDependenciesNotificationPanel( private var FileEditor.notificationPanel: NewScriptDependenciesNotificationPanel? by UserDataProperty(Key.create("script.dependencies.panel")) private class NewScriptDependenciesNotificationPanel( - onClick: (ScriptDependencies) -> Unit, - val dependencies: ScriptDependencies, + onClick: (ResolveResult) -> Unit, + val resolveResult: ResolveResult, project: Project ) : EditorNotificationPanel() { init { setText("There are new script dependencies available.") createComponentActionLabel("Apply dependencies") { - onClick(dependencies) + onClick(resolveResult) } createComponentActionLabel("Enable auto-reload") { - onClick(dependencies) + onClick(resolveResult) KotlinScriptingSettings.getInstance(project).isAutoReloadEnabled = true } } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/ScriptDependenciesLoader.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/ScriptDependenciesLoader.kt index c2e5f65afca..16c372167f2 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/ScriptDependenciesLoader.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/ScriptDependenciesLoader.kt @@ -21,8 +21,6 @@ import org.jetbrains.kotlin.script.* import java.util.concurrent.ConcurrentHashMap import kotlin.script.experimental.dependencies.AsyncDependenciesResolver import kotlin.script.experimental.dependencies.DependenciesResolver -import kotlin.script.experimental.dependencies.ScriptDependencies -import kotlin.script.experimental.dependencies.ScriptReport abstract class ScriptDependenciesLoader( protected val file: VirtualFile, @@ -75,16 +73,16 @@ abstract class ScriptDependenciesLoader( val newDependencies = result.dependencies?.adjustByDefinition(scriptDef) ?: return if (cache[file] != newDependencies) { if (shouldShowNotification() && cache[file] != null && !ApplicationManager.getApplication().isUnitTestMode) { - file.addScriptDependenciesNotificationPanel(newDependencies, project) { - saveDependencies(newDependencies) - attachReports(result.reports) + file.addScriptDependenciesNotificationPanel(result, project) { + saveDependencies(it) + attachReports(it) } } else { - saveDependencies(newDependencies) - attachReports(result.reports) + saveDependencies(result) + attachReports(result) } } else { - attachReports(result.reports) + attachReports(result) if (shouldShowNotification()) { file.removeScriptDependenciesNotificationPanel(project) @@ -92,15 +90,16 @@ abstract class ScriptDependenciesLoader( } } - private fun attachReports(reports: List) { - ServiceManager.getService(project, ScriptReportSink::class.java)?.attachReports(file, reports) + private fun attachReports(result: DependenciesResolver.ResolveResult) { + ServiceManager.getService(project, ScriptReportSink::class.java)?.attachReports(file, result.reports) } - private fun saveDependencies(dependencies: ScriptDependencies) { + private fun saveDependencies(result: DependenciesResolver.ResolveResult) { if (shouldShowNotification()) { file.removeScriptDependenciesNotificationPanel(project) } + val dependencies = result.dependencies?.adjustByDefinition(scriptDef) ?: return val rootsChanged = cache.hasNotCachedRoots(dependencies) if (cache.save(file, dependencies)) { file.scriptDependencies = dependencies