diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index a4391c524793..629c37434e2a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -88,7 +88,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement }; private LightweightHint myHint; private final Semaphore myFreezeSemaphore; - private boolean myToRestart; + private Boolean myToRestart; private boolean myModifiersReleased; @@ -436,6 +436,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement } private void finishCompletionProcess() { + assert myToRestart == null; + myToRestart = false; cancel(); assert !myDisposed; @@ -474,7 +476,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement invokeLaterIfNotDispatch(new Runnable() { public void run() { if (isOutdated()) return; - if (isCanceled() && !myToRestart) return; // otherwise + if (isCanceled() && myToRestart != Boolean.TRUE) return; //what if a new completion was invoked by the user before this 'later'? if (CompletionProgressIndicator.this != CompletionServiceImpl.getCompletionService().getCurrentCompletion()) return; @@ -528,6 +530,11 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement } public void cancelByWriteAction() { + if (myToRestart != null) { + assert myToRestart == Boolean.FALSE; //explicit completionFinished was invoked before this write action + return; + } + myToRestart = true; cancel(); @@ -605,7 +612,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement } public void prefixUpdated() { - if (myToRestart) { + if (myToRestart == Boolean.TRUE) { scheduleRestart(); return; }