Add debug log for script dependencies loading process
This commit is contained in:
+7
@@ -74,6 +74,8 @@ class AsyncScriptDependenciesLoader internal constructor(project: Project) : Scr
|
|||||||
|
|
||||||
private fun runDependenciesUpdate(file: VirtualFile) {
|
private fun runDependenciesUpdate(file: VirtualFile) {
|
||||||
val scriptDef = runReadAction { file.findScriptDefinition(project) } ?: return
|
val scriptDef = runReadAction { file.findScriptDefinition(project) } ?: return
|
||||||
|
|
||||||
|
debug(file) { "start async dependencies loading" }
|
||||||
// runBlocking is using there to avoid loading dependencies asynchronously
|
// runBlocking is using there to avoid loading dependencies asynchronously
|
||||||
// because it leads to starting more than one gradle daemon in case of resolving dependencies in build.gradle.kts
|
// because it leads to starting more than one gradle daemon in case of resolving dependencies in build.gradle.kts
|
||||||
// It is more efficient to use one hot daemon consistently than multiple daemon in parallel
|
// It is more efficient to use one hot daemon consistently than multiple daemon in parallel
|
||||||
@@ -84,6 +86,9 @@ class AsyncScriptDependenciesLoader internal constructor(project: Project) : Scr
|
|||||||
t.asResolveFailure(scriptDef)
|
t.asResolveFailure(scriptDef)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug(file) { "finish async dependencies loading" }
|
||||||
|
|
||||||
processResult(result, file, scriptDef)
|
processResult(result, file, scriptDef)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +145,8 @@ class AsyncScriptDependenciesLoader internal constructor(project: Project) : Scr
|
|||||||
fun addTask(file: VirtualFile) {
|
fun addTask(file: VirtualFile) {
|
||||||
if (sequenceOfFiles.contains(file)) return
|
if (sequenceOfFiles.contains(file)) return
|
||||||
|
|
||||||
|
debug(file) { "added to update queue" }
|
||||||
|
|
||||||
sequenceOfFiles.add(file)
|
sequenceOfFiles.add(file)
|
||||||
|
|
||||||
// If the queue is longer than 3, show progress and cancel button
|
// If the queue is longer than 3, show progress and cancel button
|
||||||
|
|||||||
+1
@@ -17,6 +17,7 @@ class FromFileAttributeScriptDependenciesLoader(project: Project) : ScriptDepend
|
|||||||
|
|
||||||
override fun loadDependencies(file: VirtualFile) {
|
override fun loadDependencies(file: VirtualFile) {
|
||||||
val deserializedDependencies = file.scriptDependencies ?: return
|
val deserializedDependencies = file.scriptDependencies ?: return
|
||||||
|
debug(file) { "dependencies from fileAttributes = $deserializedDependencies" }
|
||||||
saveToCache(file, deserializedDependencies)
|
saveToCache(file, deserializedDependencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -18,7 +18,9 @@ class OutsiderFileDependenciesLoader(project: Project) : ScriptDependenciesLoade
|
|||||||
|
|
||||||
override fun loadDependencies(file: VirtualFile) {
|
override fun loadDependencies(file: VirtualFile) {
|
||||||
val fileOrigin = OutsidersPsiFileSupportUtils.getOutsiderFileOrigin(project, file) ?: return
|
val fileOrigin = OutsidersPsiFileSupportUtils.getOutsiderFileOrigin(project, file) ?: return
|
||||||
saveToCache(file, ScriptDependenciesManager.getInstance(project).getScriptDependencies(fileOrigin))
|
val originDependencies = ScriptDependenciesManager.getInstance(project).getScriptDependencies(fileOrigin)
|
||||||
|
debug(file) { "dependencies for outsider file = $originDependencies" }
|
||||||
|
saveToCache(file, originDependencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldShowNotification(): Boolean = false
|
override fun shouldShowNotification(): Boolean = false
|
||||||
|
|||||||
+24
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.core.script.dependencies
|
|||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.application.TransactionGuard
|
import com.intellij.openapi.application.TransactionGuard
|
||||||
import com.intellij.openapi.components.ServiceManager
|
import com.intellij.openapi.components.ServiceManager
|
||||||
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
|
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
|
||||||
import com.intellij.openapi.util.EmptyRunnable
|
import com.intellij.openapi.util.EmptyRunnable
|
||||||
@@ -48,6 +49,8 @@ abstract class ScriptDependenciesLoader(protected val project: Project) {
|
|||||||
private val reporter: ScriptReportSink = ServiceManager.getService(project, ScriptReportSink::class.java)
|
private val reporter: ScriptReportSink = ServiceManager.getService(project, ScriptReportSink::class.java)
|
||||||
|
|
||||||
protected fun processResult(result: DependenciesResolver.ResolveResult, file: VirtualFile, scriptDef: KotlinScriptDefinition) {
|
protected fun processResult(result: DependenciesResolver.ResolveResult, file: VirtualFile, scriptDef: KotlinScriptDefinition) {
|
||||||
|
debug(file) { "dependencies from ${this.javaClass} received = $result" }
|
||||||
|
|
||||||
if (cache[file] == null) {
|
if (cache[file] == null) {
|
||||||
saveDependencies(result, file, scriptDef)
|
saveDependencies(result, file, scriptDef)
|
||||||
attachReportsIfChanged(result, file, scriptDef)
|
attachReportsIfChanged(result, file, scriptDef)
|
||||||
@@ -57,12 +60,18 @@ abstract class ScriptDependenciesLoader(protected val project: Project) {
|
|||||||
val newDependencies = result.dependencies?.adjustByDefinition(scriptDef)
|
val newDependencies = result.dependencies?.adjustByDefinition(scriptDef)
|
||||||
if (cache[file] != newDependencies) {
|
if (cache[file] != newDependencies) {
|
||||||
if (shouldShowNotification() && !ApplicationManager.getApplication().isUnitTestMode) {
|
if (shouldShowNotification() && !ApplicationManager.getApplication().isUnitTestMode) {
|
||||||
|
debug(file) {
|
||||||
|
"dependencies changed, notification was shown: old = ${cache[file]}, new = $newDependencies"
|
||||||
|
}
|
||||||
file.addScriptDependenciesNotificationPanel(result, project) {
|
file.addScriptDependenciesNotificationPanel(result, project) {
|
||||||
saveDependencies(it, file, scriptDef)
|
saveDependencies(it, file, scriptDef)
|
||||||
attachReportsIfChanged(it, file, scriptDef)
|
attachReportsIfChanged(it, file, scriptDef)
|
||||||
submitMakeRootsChange()
|
submitMakeRootsChange()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
debug(file) {
|
||||||
|
"dependencies changed, new dependencies were applied automatically: old = ${cache[file]}, new = $newDependencies"
|
||||||
|
}
|
||||||
saveDependencies(result, file, scriptDef)
|
saveDependencies(result, file, scriptDef)
|
||||||
attachReportsIfChanged(result, file, scriptDef)
|
attachReportsIfChanged(result, file, scriptDef)
|
||||||
}
|
}
|
||||||
@@ -93,6 +102,9 @@ abstract class ScriptDependenciesLoader(protected val project: Project) {
|
|||||||
protected fun saveToCache(file: VirtualFile, dependencies: ScriptDependencies) {
|
protected fun saveToCache(file: VirtualFile, dependencies: ScriptDependencies) {
|
||||||
val rootsChanged = cache.hasNotCachedRoots(dependencies)
|
val rootsChanged = cache.hasNotCachedRoots(dependencies)
|
||||||
if (cache.save(file, dependencies)) {
|
if (cache.save(file, dependencies)) {
|
||||||
|
debug(file) {
|
||||||
|
"dependencies were saved to file attributes: dependencies = $dependencies"
|
||||||
|
}
|
||||||
file.scriptDependencies = dependencies
|
file.scriptDependencies = dependencies
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +122,8 @@ abstract class ScriptDependenciesLoader(protected val project: Project) {
|
|||||||
runWriteAction {
|
runWriteAction {
|
||||||
if (project.isDisposed) return@runWriteAction
|
if (project.isDisposed) return@runWriteAction
|
||||||
|
|
||||||
|
debug(null) { "root change event for ${this.javaClass}" }
|
||||||
|
|
||||||
shouldNotifyRootsChanged = false
|
shouldNotifyRootsChanged = false
|
||||||
ProjectRootManagerEx.getInstanceEx(project)?.makeRootsChange(EmptyRunnable.getInstance(), false, true)
|
ProjectRootManagerEx.getInstanceEx(project)?.makeRootsChange(EmptyRunnable.getInstance(), false, true)
|
||||||
ScriptDependenciesModificationTracker.getInstance(project).incModificationCount()
|
ScriptDependenciesModificationTracker.getInstance(project).incModificationCount()
|
||||||
@@ -124,4 +138,14 @@ abstract class ScriptDependenciesLoader(protected val project: Project) {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val LOG = Logger.getInstance("#org.jetbrains.kotlin.idea.script")
|
||||||
|
|
||||||
|
internal fun debug(file: VirtualFile? = null, message: () -> String) {
|
||||||
|
if (LOG.isDebugEnabled) {
|
||||||
|
LOG.debug("[KOTLIN SCRIPT] " + (file?.let { "file = ${file.path}, " } ?: "") + message())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -18,7 +18,9 @@ class SyncScriptDependenciesLoader internal constructor(project: Project) : Scri
|
|||||||
|
|
||||||
override fun loadDependencies(file: VirtualFile) {
|
override fun loadDependencies(file: VirtualFile) {
|
||||||
val scriptDef = file.findScriptDefinition(project) ?: return
|
val scriptDef = file.findScriptDefinition(project) ?: return
|
||||||
|
debug(file) { "start sync dependencies loading" }
|
||||||
val result = contentLoader.loadContentsAndResolveDependencies(scriptDef, file)
|
val result = contentLoader.loadContentsAndResolveDependencies(scriptDef, file)
|
||||||
|
debug(file) { "finish sync dependencies loading" }
|
||||||
processResult(result, file, scriptDef)
|
processResult(result, file, scriptDef)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user