Fix warning in scripts that dependencies are not available
^KT-30441 Fixed
This commit is contained in:
+2
-1
@@ -60,7 +60,8 @@ class ScriptExternalHighlightingPass(
|
||||
)
|
||||
}
|
||||
|
||||
if (!ScriptDependenciesUpdater.areDependenciesCached(file)) {
|
||||
// show notification only for async resolvers, for others file analysis is in progress until all dependencies are ready
|
||||
if (!ScriptDependenciesUpdater.areDependenciesCached(file) && ScriptDependenciesUpdater.isAsyncDependencyResolver(file)) {
|
||||
showNotification(
|
||||
file,
|
||||
"Highlighting in scripts is not available until all Script Dependencies are loaded"
|
||||
|
||||
+13
-3
@@ -92,8 +92,8 @@ class ScriptDependenciesUpdater(
|
||||
}
|
||||
|
||||
private fun updateDependencies(file: VirtualFile, scriptDef: KotlinScriptDefinition) {
|
||||
val loader = when (scriptDef.dependencyResolver) {
|
||||
is AsyncDependenciesResolver, is LegacyResolverWrapper -> asyncLoader
|
||||
val loader = when {
|
||||
isAsyncDependencyResolver(scriptDef) -> asyncLoader
|
||||
else -> syncLoader
|
||||
}
|
||||
loader.updateDependencies(file, scriptDef)
|
||||
@@ -167,13 +167,18 @@ class ScriptDependenciesUpdater(
|
||||
}
|
||||
|
||||
private fun areDependenciesCached(file: VirtualFile): Boolean {
|
||||
return cache[file] != null
|
||||
return cache[file] != null || file.scriptDependencies != null
|
||||
}
|
||||
|
||||
private fun areDependenciesCached(files: List<VirtualFile>): Boolean {
|
||||
return files.all { areDependenciesCached(it) }
|
||||
}
|
||||
|
||||
private fun isAsyncDependencyResolver(scriptDef: KotlinScriptDefinition): Boolean {
|
||||
val dependencyResolver = scriptDef.dependencyResolver
|
||||
return dependencyResolver is AsyncDependenciesResolver || dependencyResolver is LegacyResolverWrapper
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project): ScriptDependenciesUpdater =
|
||||
@@ -182,6 +187,11 @@ class ScriptDependenciesUpdater(
|
||||
fun areDependenciesCached(file: KtFile): Boolean {
|
||||
return getInstance(file.project).areDependenciesCached(file.virtualFile)
|
||||
}
|
||||
|
||||
fun isAsyncDependencyResolver(file: KtFile): Boolean {
|
||||
val scriptDefinition = file.virtualFile.findScriptDefinition(file.project) ?: return false
|
||||
return getInstance(file.project).isAsyncDependencyResolver(scriptDefinition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user