Check for script file validity on cache changes, fixes #EA-90318, #EA-87672
This commit is contained in:
+10
-1
@@ -60,7 +60,7 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
|||||||
val uncached = hashSetOf<String>()
|
val uncached = hashSetOf<String>()
|
||||||
files.forEach { file ->
|
files.forEach { file ->
|
||||||
val path = getFilePath(file)
|
val path = getFilePath(file)
|
||||||
if (!cache.containsKey(path) && !cacheOfNulls.contains(path) && !uncached.contains(path)) {
|
if (isValidFile(file) && !cache.containsKey(path) && !cacheOfNulls.contains(path) && !uncached.contains(path)) {
|
||||||
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
||||||
if (scriptDef != null) {
|
if (scriptDef != null) {
|
||||||
val deps = scriptDef.getDependenciesFor(file, project, null)
|
val deps = scriptDef.getDependenciesFor(file, project, null)
|
||||||
@@ -83,6 +83,14 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
|||||||
fun <TF: Any> updateExternalImportsCache(files: Iterable<TF>): Iterable<TF> = cacheLock.write {
|
fun <TF: Any> updateExternalImportsCache(files: Iterable<TF>): Iterable<TF> = cacheLock.write {
|
||||||
files.mapNotNull { file ->
|
files.mapNotNull { file ->
|
||||||
val path = getFilePath(file)
|
val path = getFilePath(file)
|
||||||
|
if (!isValidFile(file)) {
|
||||||
|
if (cache.remove(path) != null || cacheOfNulls.remove(path)) {
|
||||||
|
log.info("[kts] removed deps for invalid file $path")
|
||||||
|
file
|
||||||
|
} // cleared
|
||||||
|
else null // unknown
|
||||||
|
}
|
||||||
|
else {
|
||||||
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
||||||
if (scriptDef != null) {
|
if (scriptDef != null) {
|
||||||
val oldDeps = cache[path]
|
val oldDeps = cache[path]
|
||||||
@@ -113,6 +121,7 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
|
|||||||
else null // not a script
|
else null // not a script
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun invalidateCaches() {
|
fun invalidateCaches() {
|
||||||
cacheLock.write {
|
cacheLock.write {
|
||||||
|
|||||||
@@ -35,6 +35,13 @@ fun <TF> getFilePath(file: TF): String = when (file) {
|
|||||||
else -> throw IllegalArgumentException("Unsupported file type $file")
|
else -> throw IllegalArgumentException("Unsupported file type $file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <TF> isValidFile(file: TF): Boolean = when (file) {
|
||||||
|
is PsiFile -> file.isValid
|
||||||
|
is VirtualFile -> file.isValid
|
||||||
|
is File -> file.exists() && file.isFile
|
||||||
|
else -> throw IllegalArgumentException("Unsupported file type $file")
|
||||||
|
}
|
||||||
|
|
||||||
fun <TF> getFile(file: TF): File? = when (file) {
|
fun <TF> getFile(file: TF): File? = when (file) {
|
||||||
is PsiFile -> file.originalFile.run { File(virtualFile?.path) }
|
is PsiFile -> file.originalFile.run { File(virtualFile?.path) }
|
||||||
is VirtualFile -> File(file.path)
|
is VirtualFile -> File(file.path)
|
||||||
|
|||||||
Reference in New Issue
Block a user