From d3c7a89650e0b7afc36efb526c8a534a032d9c6e Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 13 Apr 2012 18:23:47 +0400 Subject: [PATCH] Index not ready exception from short diff: check for dumb mode and repeat details refresh after some time --- .../vcs/changes/AbstractRefreshablePanel.java | 9 ++++- .../changes/PreparedFragmentedContent.java | 8 ++++- .../ModalityIgnorantBackgroundableTask.java | 35 ++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractRefreshablePanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractRefreshablePanel.java index 32a8085acedd..21f7954a3e37 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractRefreshablePanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractRefreshablePanel.java @@ -19,6 +19,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.BackgroundTaskQueue; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.Comparing; @@ -60,7 +61,13 @@ public abstract class AbstractRefreshablePanel implements RefreshablePanel { myDetailsLoader = new GenericDetailsLoader(new Consumer() { @Override public void consume(Ticket ticket) { - myQueue.run(new Loader(project, loadingTitle, myTicket.copy())); + final Loader loader = new Loader(project, loadingTitle, myTicket.copy()); + loader.runSteadily(new Consumer() { + @Override + public void consume(Task.Backgroundable backgroundable) { + myQueue.run(backgroundable); + } + }); } }, new PairConsumer() { @Override diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/PreparedFragmentedContent.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/PreparedFragmentedContent.java index b134fd61a55c..dc56cb400b9e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/PreparedFragmentedContent.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/PreparedFragmentedContent.java @@ -24,6 +24,7 @@ import com.intellij.openapi.editor.highlighter.*; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.Pair; @@ -36,6 +37,7 @@ import com.intellij.openapi.vcs.impl.ContentRevisionCache; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.BeforeAfter; import com.intellij.util.Consumer; +import com.intellij.util.continuation.ModalityIgnorantBackgroundableTask; import java.util.ArrayList; import java.util.Collections; @@ -108,9 +110,13 @@ public class PreparedFragmentedContent { } private void fromFragmentedContent(final FragmentedContent fragmentedContent) { - ApplicationManager.getApplication().runReadAction(new Runnable() { + ApplicationManager.getApplication().runReadAction(new Runnable() { // todo @Override public void run() { + if (DumbService.isDumb(myProject)) { + throw new ModalityIgnorantBackgroundableTask.ToBeRepeatedException(); + } + myOneSide = fragmentedContent.isOneSide(); myIsAddition = fragmentedContent.isAddition(); List> expandedRanges = diff --git a/platform/vcs-impl/src/com/intellij/util/continuation/ModalityIgnorantBackgroundableTask.java b/platform/vcs-impl/src/com/intellij/util/continuation/ModalityIgnorantBackgroundableTask.java index e3e349d18c16..aa0997ff947e 100644 --- a/platform/vcs-impl/src/com/intellij/util/continuation/ModalityIgnorantBackgroundableTask.java +++ b/platform/vcs-impl/src/com/intellij/util/continuation/ModalityIgnorantBackgroundableTask.java @@ -19,6 +19,7 @@ import com.intellij.openapi.progress.PerformInBackgroundOption; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; +import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,6 +32,9 @@ import javax.swing.*; * Time: 12:14 PM */ public abstract class ModalityIgnorantBackgroundableTask extends Task.Backgroundable { + private Consumer myRunner; + private int myCnt; + public ModalityIgnorantBackgroundableTask(@Nullable Project project, @NotNull String title, boolean canBeCancelled, @@ -38,7 +42,9 @@ public abstract class ModalityIgnorantBackgroundableTask extends Task.Background super(project, title, canBeCancelled, backgroundOption); } - public ModalityIgnorantBackgroundableTask(@Nullable Project project, @NotNull String title, boolean canBeCancelled) { + public ModalityIgnorantBackgroundableTask(@Nullable Project project, + @NotNull String title, + boolean canBeCancelled) { super(project, title, canBeCancelled); } @@ -51,10 +57,35 @@ public abstract class ModalityIgnorantBackgroundableTask extends Task.Background protected abstract void doInAwtIfSuccess(); protected abstract void runImpl(@NotNull ProgressIndicator indicator); + public void runSteadily(final Consumer consumer) { + myRunner = consumer; + myCnt = 100; + consumer.consume(this); + } + @Override public void run(@NotNull final ProgressIndicator indicator) { try { runImpl(indicator); + } catch (final ToBeRepeatedException tbre) { + if (myRunner != null && myCnt > 0) { + -- myCnt; + // we are on some background thread and do not want to reschedule too often + try { + Thread.sleep(100); + } + catch (InterruptedException e) { + // + } + myRunner.consume(this); + return; + } + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + doInAwtIfFail(tbre); + } + }); } catch (final Exception e) { SwingUtilities.invokeLater(new Runnable() { @Override @@ -76,4 +107,6 @@ public abstract class ModalityIgnorantBackgroundableTask extends Task.Background } }); } + + public static class ToBeRepeatedException extends RuntimeException {} }