Add script files changes monitoring, logic for initialization during index rebuilding
This commit is contained in:
committed by
Pavel V. Talanov
parent
8dac72f465
commit
5bea5bcc37
@@ -69,6 +69,13 @@ class KotlinScriptExternalDependenciesUnion(val dependencies: Iterable<KotlinScr
|
||||
override val sources: Iterable<File> get() = dependencies.flatMap { it.sources }
|
||||
}
|
||||
|
||||
fun Iterable<File>.isSameClasspathAs(other: Iterable<File>): Boolean {
|
||||
val c1 = map { it.canonicalPath }.toHashSet()
|
||||
val c2 = other.map { it.canonicalPath }.toHashSet()
|
||||
return c1.size == c2.size &&
|
||||
c1.zip(c2).all { it.first == it.second }
|
||||
}
|
||||
|
||||
data class ScriptParameter(val name: Name, val type: KotlinType)
|
||||
|
||||
fun <TF> getFileName(file: TF): String = when (file) {
|
||||
|
||||
+31
@@ -49,6 +49,7 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
||||
}
|
||||
}
|
||||
|
||||
// optimized for initial caching, additional handling of possible duplicates to save a call to distinct
|
||||
fun <TF> cacheExternalImports(files: Iterable<TF>): Unit = cacheLock.write {
|
||||
val uncached = hashSetOf<String>()
|
||||
files.forEach { file ->
|
||||
@@ -71,6 +72,36 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
||||
}
|
||||
}
|
||||
|
||||
// optimized for update, no special duplicates handling
|
||||
fun <TF: Any> updateExternalImportsCache(files: Iterable<TF>): Iterable<TF> = cacheLock.write {
|
||||
files.mapNotNull { file ->
|
||||
val path = getFilePath(file)
|
||||
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
||||
if (scriptDef != null) {
|
||||
val deps = scriptDef.getDependenciesFor(file, project)
|
||||
val oldDeps = cache[path]
|
||||
when {
|
||||
deps != null && (oldDeps == null ||
|
||||
!deps.classpath.isSameClasspathAs(oldDeps.classpath) || !deps.sources.isSameClasspathAs(oldDeps.sources)) -> {
|
||||
// changed or new
|
||||
cache.put(path, deps)
|
||||
cacheOfNulls.remove(path)
|
||||
file
|
||||
}
|
||||
deps != null -> {
|
||||
// same as before
|
||||
null
|
||||
}
|
||||
else -> {
|
||||
if (cache.remove(path) != null || cacheOfNulls.remove(path)) file // cleared
|
||||
else null // same as before
|
||||
}
|
||||
}
|
||||
}
|
||||
else null // not a script
|
||||
}
|
||||
}
|
||||
|
||||
fun invalidateCaches() {
|
||||
cacheLock.write {
|
||||
cache.keys.toList().apply {
|
||||
|
||||
Reference in New Issue
Block a user