Indexes should be updated if there are new dependencies for script file
KT-26271 Fixed
This commit is contained in:
+1
-1
@@ -77,7 +77,7 @@ class ScriptDependenciesManager internal constructor(
|
||||
@TestOnly
|
||||
fun updateScriptDependenciesSynchronously(virtualFile: VirtualFile, project: Project) {
|
||||
val scriptDefinition = findScriptDefinition(virtualFile, project)!!
|
||||
SyncScriptDependenciesLoader(virtualFile, scriptDefinition, project, shouldNotifyRootsChanged = true).updateDependencies()
|
||||
SyncScriptDependenciesLoader(virtualFile, scriptDefinition, project).updateDependencies()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -57,7 +57,7 @@ class ScriptDependenciesUpdater(
|
||||
val scriptDef = findScriptDefinition(file, project) ?: return ScriptDependencies.Empty
|
||||
|
||||
FromFileAttributeScriptDependenciesLoader(file, scriptDef, project).updateDependencies()
|
||||
ScriptDependenciesLoader.updateDependencies(file, scriptDef, project, shouldNotifyRootsChanged = false)
|
||||
ScriptDependenciesLoader.updateDependencies(file, scriptDef, project)
|
||||
|
||||
return cache[file] ?: ScriptDependencies.Empty
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class ScriptDependenciesUpdater(
|
||||
val scriptDef = ktFile.script?.kotlinScriptDefinition ?: return
|
||||
|
||||
if (!ProjectRootsUtil.isInProjectSource(ktFile, includeScriptsOutsideSourceRoots = true)) return
|
||||
ScriptDependenciesLoader.updateDependencies(file, scriptDef, project, shouldNotifyRootsChanged = true)
|
||||
ScriptDependenciesLoader.updateDependencies(file, scriptDef, project)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -113,7 +113,7 @@ class ScriptDependenciesUpdater(
|
||||
scriptsQueue.addRequest(
|
||||
{
|
||||
FileDocumentManager.getInstance().saveDocument(document)
|
||||
ScriptDependenciesLoader.updateDependencies(file, scriptDef, project, shouldNotifyRootsChanged = true)
|
||||
ScriptDependenciesLoader.updateDependencies(file, scriptDef, project)
|
||||
},
|
||||
scriptChangesListenerDelay,
|
||||
true
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ class AsyncScriptDependenciesLoader(
|
||||
file: VirtualFile,
|
||||
scriptDef: KotlinScriptDefinition,
|
||||
project: Project
|
||||
) : ScriptDependenciesLoader(file, scriptDef, project, true) {
|
||||
) : ScriptDependenciesLoader(file, scriptDef, project) {
|
||||
|
||||
override fun loadDependencies() {
|
||||
if (!shouldSendNewRequest(lastRequest)) {
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ class FromFileAttributeScriptDependenciesLoader(
|
||||
file: VirtualFile,
|
||||
scriptDef: KotlinScriptDefinition,
|
||||
project: Project
|
||||
) : ScriptDependenciesLoader(file, scriptDef, project, true) {
|
||||
) : ScriptDependenciesLoader(file, scriptDef, project) {
|
||||
|
||||
override fun loadDependencies() {
|
||||
val deserializedDependencies = file.scriptDependencies ?: return
|
||||
|
||||
+5
-8
@@ -14,6 +14,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
|
||||
import com.intellij.openapi.util.EmptyRunnable
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.idea.core.script.*
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.script.*
|
||||
@@ -25,8 +26,7 @@ import kotlin.script.experimental.dependencies.ScriptDependencies
|
||||
abstract class ScriptDependenciesLoader(
|
||||
protected val file: VirtualFile,
|
||||
protected val scriptDef: KotlinScriptDefinition,
|
||||
protected val project: Project,
|
||||
private val shouldNotifyRootsChanged: Boolean
|
||||
protected val project: Project
|
||||
) {
|
||||
companion object {
|
||||
private val loaders = ConcurrentHashMap<VirtualFile, ScriptDependenciesLoader>()
|
||||
@@ -34,8 +34,7 @@ abstract class ScriptDependenciesLoader(
|
||||
fun updateDependencies(
|
||||
file: VirtualFile,
|
||||
scriptDef: KotlinScriptDefinition,
|
||||
project: Project,
|
||||
shouldNotifyRootsChanged: Boolean
|
||||
project: Project
|
||||
) {
|
||||
val existingLoader = loaders[file]
|
||||
if (existingLoader != null) return existingLoader.updateDependencies()
|
||||
@@ -43,7 +42,7 @@ abstract class ScriptDependenciesLoader(
|
||||
val newLoader = when (scriptDef.dependencyResolver) {
|
||||
is AsyncDependenciesResolver,
|
||||
is LegacyResolverWrapper -> AsyncScriptDependenciesLoader(file, scriptDef, project)
|
||||
else -> SyncScriptDependenciesLoader(file, scriptDef, project, shouldNotifyRootsChanged)
|
||||
else -> SyncScriptDependenciesLoader(file, scriptDef, project)
|
||||
}
|
||||
loaders.put(file, newLoader)
|
||||
newLoader.updateDependencies()
|
||||
@@ -107,8 +106,6 @@ abstract class ScriptDependenciesLoader(
|
||||
|
||||
@Suppress("EXPERIMENTAL_FEATURE_WARNING")
|
||||
protected fun notifyRootsChanged() {
|
||||
if (!shouldNotifyRootsChanged) return
|
||||
|
||||
val doNotifyRootsChanged = Runnable {
|
||||
runWriteAction {
|
||||
if (project.isDisposed) return@runWriteAction
|
||||
@@ -119,7 +116,7 @@ abstract class ScriptDependenciesLoader(
|
||||
}
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
doNotifyRootsChanged.run()
|
||||
UIUtil.invokeLaterIfNeeded(doNotifyRootsChanged)
|
||||
} else {
|
||||
TransactionGuard.getInstance().submitTransactionLater(project, doNotifyRootsChanged)
|
||||
}
|
||||
|
||||
+2
-3
@@ -12,9 +12,8 @@ import org.jetbrains.kotlin.script.KotlinScriptDefinition
|
||||
class SyncScriptDependenciesLoader(
|
||||
file: VirtualFile,
|
||||
scriptDef: KotlinScriptDefinition,
|
||||
project: Project,
|
||||
shouldNotifyRootsChanged: Boolean
|
||||
) : ScriptDependenciesLoader(file, scriptDef, project, shouldNotifyRootsChanged) {
|
||||
project: Project
|
||||
) : ScriptDependenciesLoader(file, scriptDef, project) {
|
||||
|
||||
override fun loadDependencies() {
|
||||
val result = contentLoader.loadContentsAndResolveDependencies(scriptDef, file)
|
||||
|
||||
Reference in New Issue
Block a user