@@ -8,6 +8,7 @@ import com.intellij.openapi.project.DumbService
88import com.intellij.openapi.project.Project
99import com.intellij.openapi.project.waitForSmartMode
1010import com.intellij.openapi.roots.ProjectFileIndex
11+ import com.intellij.openapi.vfs.AsyncFileListener
1112import com.intellij.openapi.vfs.VirtualFile
1213import com.intellij.openapi.vfs.VirtualFileManager
1314import com.intellij.openapi.vfs.VirtualFileManagerListener
@@ -104,25 +105,26 @@ abstract class AbstractNavigationDiscoveryManager(protected val project: Project
104105 }
105106 })
106107
107- // this listener send too many events
108- // VirtualFileManager.getInstance().addAsyncFileListener({ it ->
109- // val count = it.size
110- // object : AsyncFileListener.ChangeApplier {
111- // override fun beforeVfsChange() {
112- // // if(count > 10) {
113- // Log.trace(logger, project, "Event: beforeVfsChange, count=$count")
114- // jonManager.stop("stop because beforeVfsChange")
115- // // }
116- // }
117- //
118- // override fun afterVfsChange() {
119- // // if (count > 10) {
120- // Log.trace(logger, project, "Event: afterVfsChange, count=$count")
121- // jonManager.startWithDelay()
122- // // }
123- // }
124- // }
125- // }, this)
108+ VirtualFileManager .getInstance().addAsyncFileListener({ it ->
109+ val minSizeToActivate = 50
110+ val count = it.size
111+ object : AsyncFileListener .ChangeApplier {
112+ private val isInBulkUpdate = AtomicBoolean (false )
113+ override fun beforeVfsChange () {
114+ if (isInBulkUpdate.compareAndSet(false , true ) && count > minSizeToActivate) {
115+ Log .trace(logger, project, " Event: beforeVfsChange, count=$count " )
116+ jonManager.stop(" stop because beforeVfsChange" )
117+ }
118+ }
119+
120+ override fun afterVfsChange () {
121+ if (isInBulkUpdate.compareAndSet(true , false ) && count > minSizeToActivate) {
122+ Log .trace(logger, project, " Event: afterVfsChange, count=$count " )
123+ jonManager.startWithDelay()
124+ }
125+ }
126+ }
127+ }, this )
126128
127129
128130 VirtualFileManager .getInstance().addVirtualFileManagerListener(object : VirtualFileManagerListener {
@@ -169,7 +171,7 @@ abstract class AbstractNavigationDiscoveryManager(protected val project: Project
169171 private var stuckTimerJob: Job ? = null
170172
171173 init {
172- managementJob = cs.launchWithErrorReporting(" ${this ::class .java.simpleName} .JobManager" , logger){
174+ managementJob = cs.launchWithErrorReporting(" ${this ::class .java.simpleName} .JobManager" , logger) {
173175 Log .trace(logger, project, " JobManager: managementJob started" )
174176 jobManagementChannel.consumeEach { command: JobCommand ->
175177 Log .trace(logger, project, " JobManager: processing command: {}" , command::class .java.simpleName)
@@ -208,7 +210,7 @@ abstract class AbstractNavigationDiscoveryManager(protected val project: Project
208210 // is not 0, then restart the jobs and hope for the best.
209211 private fun startStuckTimer () {
210212 stuckTimerJob?.cancel()
211- stuckTimerJob = cs.launchWithErrorReporting(" $ {this::class.java.simpleName}.JobManager.startStuckTimer" , logger){
213+ stuckTimerJob = cs.launchWithErrorReporting(" $ {this::class.java.simpleName}.JobManager.startStuckTimer" , logger) {
212214 delay(5 .minutes)
213215 @Suppress(" UnstableApiUsage" )
214216 project.waitForSmartMode()
@@ -227,7 +229,7 @@ abstract class AbstractNavigationDiscoveryManager(protected val project: Project
227229 }
228230
229231 fun startup () {
230- cs.launchWithErrorReporting(" ${this ::class .java.simpleName} .JobManager.startup" , logger){
232+ cs.launchWithErrorReporting(" ${this ::class .java.simpleName} .JobManager.startup" , logger) {
231233 // on startup currentState is not relevant, if its 0 the jobs will start, if it was changed by any listener,
232234 // the jobs will not start until the currentState is 0 again when a listener calls startWithDelay
233235 Log .trace(logger, project, " JobManager: startup called, sending RestartWithDelay command" )
@@ -256,7 +258,10 @@ abstract class AbstractNavigationDiscoveryManager(protected val project: Project
256258 } else {
257259 Log .warn(logger, project, " JobManager: RestartWithDelay command failed with ${result.exceptionOrNull()} " )
258260 ErrorReporter .getInstance()
259- .reportError(" AbstractNavigationDiscoveryManager.JobManager.startWithDelay" , result.exceptionOrNull() ? : Exception (" Unknown error" ))
261+ .reportError(
262+ " AbstractNavigationDiscoveryManager.JobManager.startWithDelay" ,
263+ result.exceptionOrNull() ? : Exception (" Unknown error" )
264+ )
260265 }
261266 }
262267 }
0 commit comments