201: proper implementation for AsyncFileChangeListenerHelper.kt
updateFile is called before changes in vfs, so the timestamp is old there. The proper implementation is to collect changed files in list and get timestamp in apply.
This commit is contained in:
+15
-5
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.scripting.gradle
|
package org.jetbrains.kotlin.idea.scripting.gradle
|
||||||
|
|
||||||
import com.intellij.openapi.externalSystem.autoimport.AsyncFileChangeListenerBase
|
import com.intellij.openapi.externalSystem.autoimport.AsyncFileChangeListenerBase
|
||||||
|
import com.intellij.openapi.vfs.LocalFileSystem
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.openapi.vfs.VirtualFileManager
|
import com.intellij.openapi.vfs.VirtualFileManager
|
||||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
|
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
|
||||||
@@ -17,18 +18,27 @@ fun addVfsListener(
|
|||||||
) {
|
) {
|
||||||
VirtualFileManager.getInstance().addAsyncFileListener(
|
VirtualFileManager.getInstance().addAsyncFileListener(
|
||||||
object : AsyncFileChangeListenerBase() {
|
object : AsyncFileChangeListenerBase() {
|
||||||
|
val changedFiles = mutableListOf<String>()
|
||||||
|
|
||||||
|
override fun init() {
|
||||||
|
changedFiles.clear()
|
||||||
|
}
|
||||||
|
|
||||||
override fun isRelevant(path: String): Boolean {
|
override fun isRelevant(path: String): Boolean {
|
||||||
return buildRootsManager.maybeAffectedGradleProjectFile(path)
|
return buildRootsManager.maybeAffectedGradleProjectFile(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateFile(file: VirtualFile, event: VFileEvent) {
|
override fun updateFile(file: VirtualFile, event: VFileEvent) {
|
||||||
watcher.fileChanged(event.path, file.timeStamp)
|
changedFiles.add(event.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// do nothing
|
override fun apply() {
|
||||||
override fun apply() {}
|
changedFiles.forEach {
|
||||||
override fun init() {}
|
LocalFileSystem.getInstance().findFileByPath(it)?.let { f ->
|
||||||
|
watcher.fileChanged(f.path, f.timeStamp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
watcher.project
|
watcher.project
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user