gradle.kts: update notification only after caches updated
This commit is contained in:
+10
-3
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesModificationTracker
|
||||
import org.jetbrains.kotlin.idea.core.script.configuration.listener.ScriptChangesNotifier
|
||||
import org.jetbrains.kotlin.idea.core.script.configuration.utils.getKtFile
|
||||
import org.jetbrains.kotlin.idea.core.script.ucache.ScriptClassRootsBuilder
|
||||
import org.jetbrains.kotlin.idea.core.script.ucache.ScriptClassRootsCache
|
||||
import org.jetbrains.kotlin.idea.core.script.ucache.ScriptClassRootsUpdater
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -52,9 +53,15 @@ class CompositeScriptConfigurationManager(val project: Project) : ScriptConfigur
|
||||
|
||||
val default = DefaultScriptingSupport(this)
|
||||
|
||||
val updater = ScriptClassRootsUpdater(project, this) { builder ->
|
||||
default.collectConfigurations(builder)
|
||||
plugins.forEach { it.collectConfigurations(builder) }
|
||||
val updater = object : ScriptClassRootsUpdater(project, this) {
|
||||
override fun gatherRoots(builder: ScriptClassRootsBuilder) {
|
||||
default.collectConfigurations(builder)
|
||||
plugins.forEach { it.collectConfigurations(builder) }
|
||||
}
|
||||
|
||||
override fun afterUpdate() {
|
||||
plugins.forEach { it.afterUpdate() }
|
||||
}
|
||||
}
|
||||
|
||||
fun tryGetScriptDefinitionFast(locationId: String): ScriptDefinition? {
|
||||
|
||||
+1
@@ -35,6 +35,7 @@ interface ScriptingSupport {
|
||||
fun isApplicable(file: VirtualFile): Boolean
|
||||
fun isConfigurationLoadingInProgress(file: KtFile): Boolean
|
||||
fun collectConfigurations(builder: ScriptClassRootsBuilder)
|
||||
fun afterUpdate()
|
||||
|
||||
companion object {
|
||||
val EPN: ExtensionPointName<ScriptingSupport> =
|
||||
|
||||
+12
-3
@@ -47,16 +47,19 @@ import java.util.concurrent.atomic.AtomicReference
|
||||
* This will start indexing.
|
||||
* Also analysis cache will be cleared and changed opened script files will be reanalyzed.
|
||||
*/
|
||||
class ScriptClassRootsUpdater(
|
||||
abstract class ScriptClassRootsUpdater(
|
||||
val project: Project,
|
||||
val manager: CompositeScriptConfigurationManager,
|
||||
private val gatherRoots: (ScriptClassRootsBuilder) -> Unit
|
||||
val manager: CompositeScriptConfigurationManager
|
||||
) {
|
||||
private var lastSeen: ScriptClassRootsCache? = null
|
||||
private var invalidated: Boolean = false
|
||||
private var syncUpdateRequired: Boolean = false
|
||||
private val concurrentUpdates = AtomicInteger()
|
||||
|
||||
abstract fun gatherRoots(builder: ScriptClassRootsBuilder)
|
||||
|
||||
abstract fun afterUpdate()
|
||||
|
||||
private fun recreateRootsCache(): ScriptClassRootsCache {
|
||||
val builder = ScriptClassRootsBuilder(project)
|
||||
gatherRoots(builder)
|
||||
@@ -68,6 +71,11 @@ class ScriptClassRootsUpdater(
|
||||
*/
|
||||
private val cache: AtomicReference<ScriptClassRootsCache> = AtomicReference(recreateRootsCache())
|
||||
|
||||
init {
|
||||
@Suppress("LeakingThis")
|
||||
afterUpdate()
|
||||
}
|
||||
|
||||
val classpathRoots: ScriptClassRootsCache
|
||||
get() = cache.get()
|
||||
|
||||
@@ -196,6 +204,7 @@ class ScriptClassRootsUpdater(
|
||||
val old = cache.get()
|
||||
val new = recreateRootsCache()
|
||||
if (cache.compareAndSet(old, new)) {
|
||||
afterUpdate()
|
||||
return new.diff(lastSeen)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user