Index not ready exception from short diff: check for dumb mode and repeat details refresh after some time

This commit is contained in:
irengrig
2012-04-13 18:23:47 +04:00
parent 38b535f09e
commit d3c7a89650
3 changed files with 49 additions and 3 deletions
@@ -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<T> implements RefreshablePanel {
myDetailsLoader = new GenericDetailsLoader<Ticket, T>(new Consumer<Ticket>() {
@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<Task.Backgroundable>() {
@Override
public void consume(Task.Backgroundable backgroundable) {
myQueue.run(backgroundable);
}
});
}
}, new PairConsumer<Ticket, T>() {
@Override
@@ -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<BeforeAfter<TextRange>> expandedRanges =
@@ -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<Task.Backgroundable> 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<Backgroundable> 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 {}
}