diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 08cf1e0800f7..a69074d6fee9 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -312,14 +312,14 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase { } """) edt { myFixture.type 'A' } - joinAlarm() // completion started + joinAutopopup() // completion started boolean tooQuick = false edt { tooQuick = lookup == null myFixture.type 'IO' } - joinAlarm() //I - joinAlarm() //O + joinAutopopup() //I + joinAutopopup() //O joinCompletion() assert lookup assert 'ArrayIndexOutOfBoundsException' in myFixture.lookupElementStrings @@ -495,7 +495,7 @@ public interface Test { }""" edt { myFixture.type 'A' } - joinAlarm() + joinAutopopup() def first = lookup assert first edt { @@ -503,9 +503,9 @@ public interface Test { lookup.hide() myFixture.type 'a' } - joinAlarm() - joinAlarm() - joinAlarm() + joinAutopopup() + joinAutopopup() + joinAutopopup() assert lookup != first } @@ -519,25 +519,24 @@ public interface Test { } public void testDuringCompletionMustFinish() { + registerLongCompletionContributor() + + edt { myFixture.addFileToProject 'directory/foo.txt', '' } + myFixture.configureByText "a.java", 'public interface Test { RuntiExcexxx }' + myFixture.completeBasic() + while (!lookup.items) { + Thread.sleep(10) + edt { lookup.refreshUi() } + } + edt { myFixture.type '\t' } + myFixture.checkResult 'public interface Test { RuntimeExceptionx }' + } + + private def registerLongCompletionContributor() { def ep = Extensions.rootArea.getExtensionPoint("com.intellij.completion.contributor") def bean = new CompletionContributorEP(language: 'JAVA', implementationClass: LongReplacementOffsetContributor.name) ep.registerExtension(bean, LoadingOrder.LAST) - - try { - edt { myFixture.addFileToProject 'directory/foo.txt', '' } - myFixture.configureByText "a.java", 'public interface Test { RuntiExcexxx }' - myFixture.completeBasic() - while (!lookup.items) { - Thread.sleep(10) - edt { lookup.refreshUi() } - } - edt { myFixture.type '\t' } - myFixture.checkResult 'public interface Test { RuntimeExceptionx }' - } - finally { - ep.unregisterExtension(bean) - } - + disposeOnTearDown({ ep.unregisterExtension(bean) } as Disposable) } public void testLeftRightMovements() { @@ -563,7 +562,7 @@ public interface Test { assertEquals 'iterable', lookup.currentItem.lookupString edt { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT) } - joinAlarm() + joinAutopopup() joinCompletion() assert lookup.items.size() > 3 @@ -595,7 +594,7 @@ public interface Test { wca.execute() assert 'x' == another.document.text } - joinAlarm() + joinAutopopup() joinCompletion() LookupImpl l1 = LookupManager.getActiveLookup(another) if (l1) { @@ -680,11 +679,89 @@ class Foo { public void testNoAutopopupAfterSpace() { myFixture.configureByText("a.java", """ class Foo { { int newa; } } """) edt { myFixture.type('new ') } - joinAlarm() + joinAutopopup() joinCompletion() assert !lookup } + public void testRestartAndTypingDuringCopyCommit() { + registerLongCompletionContributor() + + myFixture.configureByText("a.java", """ class Foo { { int newa; } } """) + myFixture.type 'n' + joinAutopopup() + myFixture.type 'e' + joinCommit() // original commit + myFixture.type 'w' + joinAutopopup() + joinCompletion() + myFixture.type '\n' + myFixture.checkResult(" class Foo { { int newa; new } } ") + assert !lookup + } + + private void joinSomething(int degree) { + if (degree == 0) return + joinAlarm() + if (degree == 1) return + joinCommit() + if (degree == 2) return + joinCommit() + if (degree == 3) return + edt {} + if (degree == 4) return + joinCompletion() + } + + public void testEveryPossibleWayToTypeIf() { + def src = "class Foo { { int ifa; } }" + def result = "class Foo { { int ifa; if } }" + int actions = 5 + + for (a1 in 0..actions) { + for (a2 in 0..actions) { + myFixture.configureByText("$a1 $a2 .java", src) + myFixture.type 'i' + joinSomething(a1) + myFixture.type 'f' + joinSomething(a2) + myFixture.type ' ' + + joinAutopopup() + joinCompletion() + myFixture.checkResult(result) + assert !lookup + } + } + + for (a1 in 0..actions) { + myFixture.configureByText("$a1 if .java", src) + edt { myFixture.type 'if' } + joinSomething(a1) + + myFixture.type ' ' + + joinAutopopup() + joinCompletion() + myFixture.checkResult(result) + assert !lookup + } + + for (a1 in 0..actions) { + myFixture.configureByText("$a1 if .java", src) + myFixture.type 'i' + joinSomething(a1) + + edt { myFixture.type 'f ' } + + joinAutopopup() + joinCompletion() + myFixture.checkResult(result) + assert !lookup + } + + } + public void testNonFinishedParameterComma() { myFixture.configureByText("a.java", """ class Foo { void foo(int aaa, int aaaaa) { foo() } } """) type 'a,' diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy index 802c1dcb630c..34912ef0d2b3 100644 --- a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy +++ b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy @@ -16,18 +16,17 @@ package com.intellij.codeInsight.completion import com.intellij.codeInsight.AutoPopupController -import com.intellij.codeInsight.CodeInsightSettings import com.intellij.codeInsight.completion.impl.CompletionServiceImpl import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler import com.intellij.codeInsight.lookup.LookupManager import com.intellij.codeInsight.lookup.impl.LookupImpl +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.editor.ex.DocumentEx import com.intellij.psi.PsiDocumentManager -import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import com.intellij.util.concurrency.Semaphore import com.intellij.util.ui.UIUtil import java.util.concurrent.atomic.AtomicBoolean -import com.intellij.openapi.application.ApplicationManager /** * @author peter @@ -58,17 +57,12 @@ abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCa for (i in 0..= 10000) { + fail('too long waiting for a document to be committed') + } UIUtil.pump(); } } - protected void joinAlarm() { - joinCommit() - edt { PlatformTestUtil.waitForAlarm(CodeInsightSettings.instance.AUTO_LOOKUP_DELAY)} + protected void joinAutopopup() { + joinAlarm(); + joinCommit() // physical document commit + joinCommit() // file copy commit in background + } + + protected def joinAlarm() { + AutoPopupController.getInstance(getProject()).executePendingRequests() } @Override protected void runTest() { 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 f028179b006f..86ef2a2f74db 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -599,7 +599,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement } public void scheduleRestart() { - if (isAutopopupCompletion() && hideAutopopupIfMeaningless()) { + if (isAutopopupCompletion() && (!myProcessingDelayedActions || hideAutopopupIfMeaningless())) { AutoPopupController.getInstance(getProject()).scheduleAutoPopup(myEditor, null); return; }