Pass ResolveResult to ScriptNotificationPanel
This commit is contained in:
+9
-9
@@ -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<FileEditor, NewScriptDependenciesNotificationPanel>(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
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -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<ScriptReport>) {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user