diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 5fdad4454373..29cbf4159452 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -490,6 +490,8 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { // the insert handler may have started a live template with completion if (CompletionService.getCompletionService().getCurrentCompletion() == null) { indicator.liveAfterDeath(null); + } else { + LOG.assertTrue(indicator.isZombie(), indicator); } } } 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 c26d7ec94574..e88451ece076 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -289,7 +289,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement if (code == KeyEvent.VK_CONTROL || code == KeyEvent.VK_META || code == KeyEvent.VK_ALT || code == KeyEvent.VK_SHIFT) { myState.modifiersChanged(); if (myState.isWaitingAfterAutoInsertion()) { - unregisterItself(); + unregisterItself(true); } contentComponent.removeKeyListener(this); } @@ -297,6 +297,10 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement }); } + boolean isZombie() { + return myState.isZombie(); + } + private void setMergeCommand() { CommandProcessor.getInstance().setCurrentCommandGroupId(getCompletionCommandName()); } @@ -330,23 +334,23 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement final HintListener hintListener = new HintListener() { public void hintHidden(final EventObject event) { - unregisterItself(); + unregisterItself(true); } }; final DocumentAdapter documentListener = new DocumentAdapter() { @Override public void beforeDocumentChange(DocumentEvent e) { - unregisterItself(); + unregisterItself(true); } }; final SelectionListener selectionListener = new SelectionListener() { public void selectionChanged(SelectionEvent e) { - unregisterItself(); + unregisterItself(true); } }; final CaretListener caretListener = new CaretListener() { public void caretPositionChanged(CaretEvent e) { - unregisterItself(); + unregisterItself(true); } }; @@ -475,7 +479,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement ApplicationManager.getApplication().assertIsDispatchThread(); Disposer.dispose(myQueue); - unregisterItself(); + unregisterItself(false); } @TestOnly @@ -486,8 +490,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement } } - private void unregisterItself() { - myState.handleDeath(); + private void unregisterItself(boolean afterDeath) { + myState.handleDeath(afterDeath); CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCompletionService().getCurrentCompletion(); assert currentCompletion == this : currentCompletion + "!=" + this; CompletionServiceImpl.getCompletionService().setCurrentCompletion(null); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionState.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionState.java index 892bf983363e..979b3c76f21c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionState.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionState.java @@ -91,7 +91,7 @@ public class CompletionState { } public boolean isWaitingAfterAutoInsertion() { - return myRestorePrefix != null; + return myRestorePrefix != null && isZombie(); } public void setRestorePrefix(Runnable restorePrefix) { @@ -127,10 +127,12 @@ public class CompletionState { } } - public void handleDeath() { + public void handleDeath(boolean afterDeath) { ApplicationManager.getApplication().assertIsDispatchThread(); + boolean zombie = isZombie(); + LOG.assertTrue(afterDeath == zombie, this); assertDisposed(); - if (myZombieCleanup != null) { + if (zombie) { myZombieCleanup.run(); } myZombieCleanup = null; @@ -138,6 +140,10 @@ public class CompletionState { setRestorePrefix(null); } + public boolean isZombie() { + return myZombieCleanup != null; + } + int incCount() { return ++myCount; }