From fcd20343cdf4a0f096099938f3825f66627a371c Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 5 Sep 2015 22:51:48 +0200 Subject: [PATCH] file property pushers: re-queue on task cancellation, start dumb mode after large synchronous push --- .../impl/PushedFilePropertiesUpdaterImpl.java | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java index f99cb308423a..34aee995b70e 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java @@ -20,12 +20,14 @@ package com.intellij.openapi.roots.impl; import com.intellij.ProjectTopics; +import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionException; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.util.ProgressWrapper; @@ -92,6 +94,7 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater } public void processAfterVfsChanges(@NotNull List events) { + boolean pushedSomething = false; List delayedTasks = ContainerUtil.newArrayList(); for (VFileEvent event : events) { final VirtualFile file = event.getFile(); @@ -105,6 +108,7 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater // push synchronously to avoid entering dumb mode in the middle of a meaningful write action // avoid dumb mode for just one file doPushRecursively(file, pushers, ProjectRootManager.getInstance(myProject).getFileIndex()); + pushedSomething = true; } else if (!ProjectCoreUtil.isProjectOrWorkspaceFile(file)) { ContainerUtil.addIfNotNull(delayedTasks, createRecursivePushTask(file, pushers)); @@ -115,11 +119,26 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater } // push synchronously to avoid entering dumb mode in the middle of a meaningful write action doPushRecursively(file, pushers, ProjectRootManager.getInstance(myProject).getFileIndex()); + pushedSomething = true; } } if (!delayedTasks.isEmpty()) { queueTasks(delayedTasks); } + if (pushedSomething) { + Application application = ApplicationManager.getApplication(); + Runnable runnable = new Runnable() { + @Override + public void run() { + scheduleDumbModeReindexingIfNeeded(); + } + }; + if (application.isUnitTestMode()) { + runnable.run(); + } else { + application.invokeLater(runnable); + } + } } @Override @@ -194,15 +213,27 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater if (task == null) { break; } - hadTasks = true; - task.run(); + try { + task.run(); + hadTasks = true; + } + catch (ProcessCanceledException e) { + queueTasks(Collections.singletonList(task)); // reschedule dumb mode and ensure the canceled task is enqueued again + throw e; + } } - if (hadTasks && !myProject.isDisposed()) { - DumbModeTask task = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(myProject); - if (task != null) { - DumbService.getInstance(myProject).queueTask(task); - } + if (hadTasks) { + scheduleDumbModeReindexingIfNeeded(); + } + } + + private void scheduleDumbModeReindexingIfNeeded() { + if (myProject.isDisposed()) return; + + DumbModeTask task = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(myProject); + if (task != null) { + DumbService.getInstance(myProject).queueTask(task); } }