Show notification that script dependencies are not ready yet
This commit is contained in:
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.idea.caches.project.NotUnderContentRootModuleInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.getModuleInfo
|
||||
import org.jetbrains.kotlin.idea.core.script.IdeScriptReportSink
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManager
|
||||
import org.jetbrains.kotlin.idea.core.script.scriptDependencies
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesUpdater
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.idea.util.isRunningInCidrIde
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
@@ -67,7 +67,7 @@ object KotlinHighlightingUtil {
|
||||
@Suppress("DEPRECATION")
|
||||
private fun shouldHighlightScript(ktFile: KtFile): Boolean {
|
||||
if (isRunningInCidrIde) return false // There is no Java support in CIDR. So do not highlight errors in KTS if running in CIDR.
|
||||
if (ktFile.virtualFile.scriptDependencies == null) return false
|
||||
if (!ScriptDependenciesUpdater.areDependenciesCached(ktFile)) return false
|
||||
if (ktFile.virtualFile.getUserData(IdeScriptReportSink.Reports)?.any { it.severity == ScriptReport.Severity.FATAL } == true) {
|
||||
return false
|
||||
}
|
||||
|
||||
+27
-12
@@ -38,6 +38,7 @@ import com.intellij.psi.PsiFile
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.idea.core.script.IdeScriptReportSink
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManager
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesUpdater
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import kotlin.script.experimental.dependencies.ScriptReport
|
||||
|
||||
@@ -53,18 +54,17 @@ class ScriptExternalHighlightingPass(
|
||||
if (!file.isScript()) return
|
||||
|
||||
if (!ScriptDefinitionsManager.getInstance(file.project).isReady()) {
|
||||
UIUtil.invokeLaterIfNeeded {
|
||||
val ideFrame = WindowManager.getInstance().getIdeFrame(file.project)
|
||||
if (ideFrame != null) {
|
||||
val statusBar = ideFrame.statusBar as StatusBarEx
|
||||
statusBar.notifyProgressByBalloon(
|
||||
MessageType.WARNING,
|
||||
"Highlighting in scripts is not available until all Script Definitions are loaded",
|
||||
null,
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
showNotification(
|
||||
file,
|
||||
"Highlighting in scripts is not available until all Script Definitions are loaded"
|
||||
)
|
||||
}
|
||||
|
||||
if (!ScriptDependenciesUpdater.areDependenciesCached(file)) {
|
||||
showNotification(
|
||||
file,
|
||||
"Highlighting in scripts is not available until all Script Dependencies are loaded"
|
||||
)
|
||||
}
|
||||
|
||||
val reports = file.virtualFile.getUserData(IdeScriptReportSink.Reports) ?: return
|
||||
@@ -118,6 +118,21 @@ class ScriptExternalHighlightingPass(
|
||||
}
|
||||
}
|
||||
|
||||
private fun showNotification(file: KtFile, message: String) {
|
||||
UIUtil.invokeLaterIfNeeded {
|
||||
val ideFrame = WindowManager.getInstance().getIdeFrame(file.project)
|
||||
if (ideFrame != null) {
|
||||
val statusBar = ideFrame.statusBar as StatusBarEx
|
||||
statusBar.notifyProgressByBalloon(
|
||||
MessageType.WARNING,
|
||||
message,
|
||||
null,
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Factory(registrar: TextEditorHighlightingPassRegistrar) : ProjectComponent,
|
||||
TextEditorHighlightingPassFactory {
|
||||
init {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.core.script
|
||||
|
||||
import com.intellij.openapi.application.Application
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.editor.EditorFactory
|
||||
import com.intellij.openapi.editor.event.DocumentEvent
|
||||
import com.intellij.openapi.editor.event.DocumentListener
|
||||
@@ -148,6 +149,20 @@ class ScriptDependenciesUpdater(
|
||||
}
|
||||
}, project.messageBus.connect())
|
||||
}
|
||||
|
||||
private fun areDependenciesCached(file: VirtualFile): Boolean {
|
||||
return cache[file] != null
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project): ScriptDependenciesUpdater =
|
||||
ServiceManager.getService(project, ScriptDependenciesUpdater::class.java)
|
||||
|
||||
fun areDependenciesCached(file: KtFile): Boolean {
|
||||
return getInstance(file.project).areDependenciesCached(file.virtualFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@set: TestOnly
|
||||
|
||||
Reference in New Issue
Block a user