IDEA-184991 Parameter info popup doesn't highlight current item

simplify test
This commit is contained in:
Dmitry Batrak
2018-01-29 17:40:25 +03:00
parent 1329bdc92e
commit 5542ec580e
4 changed files with 114 additions and 101 deletions
@@ -1,7 +0,0 @@
class A {
void foo() {}
void foo(int a, int b, int c) {}
{
foo(<caret>)
}
}
@@ -0,0 +1,81 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight;
import com.intellij.codeInsight.AutoPopupController;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager;
import com.intellij.codeInsight.hint.ParameterInfoController;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.Editor;
import com.intellij.testFramework.fixtures.EditorHintFixture;
import com.intellij.util.ui.UIUtil;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.LockSupport;
public abstract class AbstractParameterInfoTestCase extends LightFixtureCompletionTestCase {
private EditorHintFixture myHintFixture;
private int myStoredAutoPopupDelay;
@Override
protected void setUp() throws Exception {
super.setUp();
myHintFixture = new EditorHintFixture(getTestRootDisposable());
myStoredAutoPopupDelay = CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY;
CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY = 100; // speed up tests
}
@Override
protected void tearDown() throws Exception {
try {
CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY = myStoredAutoPopupDelay;
}
finally {
super.tearDown();
}
}
public void configureJava(String text) {
myFixture.configureByText(JavaFileType.INSTANCE, text);
}
public void showParameterInfo() {
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_SHOW_PARAMETER_INFO);
UIUtil.dispatchAllInvocationEvents();
}
public void checkHintContents(String hintText) {
assertEquals(hintText, myHintFixture.getCurrentHintText());
}
public void type(String text) {
myFixture.type(text);
}
private void waitForParameterInfoUpdate() throws TimeoutException {
ParameterInfoController.waitForDelayedActions(getEditor(), 1, TimeUnit.MINUTES);
}
public static void waitTillAnimationCompletes(Editor editor) {
long deadline = System.currentTimeMillis() + 60_000;
while (ParameterHintsPresentationManager.getInstance().isAnimationInProgress(editor)) {
if (System.currentTimeMillis() > deadline) fail("Too long waiting for animation to finish");
LockSupport.parkNanos(10_000_000);
UIUtil.dispatchAllInvocationEvents();
}
}
private void waitForAutoPopup() throws TimeoutException {
AutoPopupController.getInstance(getProject()).waitForDelayedActions(1, TimeUnit.MINUTES);
}
public void waitForAllAsyncStuff() throws TimeoutException {
waitForParameterInfoUpdate();
myFixture.doHighlighting();
waitTillAnimationCompletes(getEditor());
waitForAutoPopup();
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight;
import com.intellij.JavaTestUtil;
@@ -19,14 +19,13 @@ import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.EditorHintFixture;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext;
import com.intellij.testFramework.utils.parameterInfo.MockParameterInfoUIContext;
import com.intellij.testFramework.utils.parameterInfo.MockUpdateParameterInfoContext;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
public class ParameterInfoTest extends LightCodeInsightFixtureTestCase {
public class ParameterInfoTest extends AbstractParameterInfoTestCase {
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/parameterInfo/";
@@ -361,27 +360,22 @@ public class ParameterInfoTest extends LightCodeInsightFixtureTestCase {
myFixture.checkResultByFile(getTestName(false) + "_after.java");
}
public void _testHighlightCurrentParameterAfterTypingFirstArgumentOfThree() {
myFixture.configureByFile(getTestName(false) + ".java");
MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
CreateParameterInfoContext context = new MockCreateParameterInfoContext(getEditor(), getFile());
PsiExpressionList argList = handler.findElementForParameterInfo(context);
assertNotNull(argList);
Object[] items = context.getItemsToShow();
assertSize(2, items);
MockUpdateParameterInfoContext updateContext = updateParameterInfo(handler, argList, items);
assertTrue(updateContext.isUIComponentEnabled(0));
assertTrue(updateContext.isUIComponentEnabled(1));
assertEquals(0, updateContext.getCurrentParameter());
myFixture.type("1, ");
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
handler.updateParameterInfo(argList, updateContext);
assertFalse(updateContext.isUIComponentEnabled(0));
assertTrue(updateContext.isUIComponentEnabled(1));
assertEquals(1, updateContext.getCurrentParameter());
public void testHighlightCurrentParameterAfterTypingFirstArgumentOfThree() throws Exception {
configureJava("class A {\n" +
" void foo() {}\n" +
" void foo(int a, int b, int c) {}\n" +
" {\n" +
" foo(<caret>)\n" +
" }\n" +
"}");
showParameterInfo();
checkHintContents("[<html>&lt;no parameters&gt;</html>]\n" +
"-\n" +
"<html><b>int a</b>, int b, int c</html>");
type("1, ");
waitForAllAsyncStuff();
checkHintContents("[<html><font color=gray>&lt;no parameters&gt;</font color=gray></html>]\n" +
"-\n" +
"<html>int a, <b>int b</b>, int c</html>");
}
}
@@ -1,22 +1,15 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.completion;
import com.intellij.codeInsight.AutoPopupController;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager;
import com.intellij.codeInsight.hint.ParameterInfoController;
import com.intellij.codeInsight.hints.JavaInlayParameterHintsProvider;
import com.intellij.codeInsight.hints.Option;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.java.codeInsight.AbstractParameterInfoTestCase;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.registry.Registry;
@@ -24,33 +17,22 @@ import com.intellij.openapi.util.registry.RegistryValue;
import com.intellij.psi.JavaCodeFragmentFactory;
import com.intellij.psi.PsiExpressionCodeFragment;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.fixtures.EditorHintFixture;
import com.intellij.util.ui.UIUtil;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.LockSupport;
import java.util.stream.Stream;
public class CompletionHintsTest extends LightFixtureCompletionTestCase {
public class CompletionHintsTest extends AbstractParameterInfoTestCase {
private boolean myStoredSettingValue;
private EditorHintFixture myHintFixture;
private int myStoredAutoPopupDelay;
@Override
protected void setUp() throws Exception {
super.setUp();
myStoredSettingValue = CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION;
CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION = true;
myHintFixture = new EditorHintFixture(getTestRootDisposable());
myStoredAutoPopupDelay = CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY;
CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY = 100; // speed up tests
}
@Override
protected void tearDown() throws Exception {
try {
CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY = myStoredAutoPopupDelay;
CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION = myStoredSettingValue;
}
finally {
@@ -77,9 +59,9 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
checkResultWithInlays("class C { void m() { System.setProperty(<HINT text=\"key:\"/><caret>, <Hint text=\"value:\"/>) } }");
// test hints remain shown while entering parameter values
myFixture.type("\"a");
type("\"a");
next();
myFixture.type("\"b");
type("\"b");
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { System.setProperty(<Hint text=\"key:\"/>\"a\", <HINT text=\"value:\"/>\"b<caret>\") } }");
@@ -112,9 +94,9 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
checkResultWithInlays("class C { void m() { Character.forDigit(<HINT text=\"digit:\"/><caret>, <Hint text=\"radix:\"/>) } }");
// test hints remain shown while entering parameter values
myFixture.type("1");
type("1");
next();
myFixture.type("2");
type("2");
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { Character.forDigit(<Hint text=\"digit:\"/>1, <HINT text=\"radix:\"/>2<caret>) } }");
@@ -214,7 +196,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
complete("setProperty");
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { System.setProperty(<HINT text=\"key:\"/><caret>, <Hint text=\"value:\"/>) } }");
myFixture.type("System.getPro");
type("System.getPro");
complete("getProperty(String key, String def)");
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { System.setProperty(<hint text=\"key:\"/>System.getProperty(<HINT text=\"key:\"/><caret>, <Hint text=\"def:\"/>), <hint text=\"value:\"/>) } }");
@@ -224,7 +206,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
configureJava("class C { void m() { System.setPro<caret> } }");
complete("setProperty");
waitForAllAsyncStuff();
myFixture.type("System.getPro");
type("System.getPro");
complete("getProperty(String key, String def)");
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { System.setProperty(<hint text=\"key:\"/>System.getProperty(<HINT text=\"key:\"/><caret>, <Hint text=\"def:\"/>), <hint text=\"value:\"/>) } }");
@@ -506,9 +488,9 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
checkResultWithInlays("class C { void m() { Character.forDigit(<HINT text=\"digit:\"/><caret>, <Hint text=\"radix:\"/>) } }");
// test hints remain shown while entering parameter values
myFixture.type("1");
type("1");
next();
myFixture.type("2");
type("2");
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { Character.forDigit(<Hint text=\"digit:\"/>1, <HINT text=\"radix:\"/>2<caret>) } }");
@@ -541,7 +523,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
configureJava("class C { void m() { System.setPro<caret> } }");
complete("setProperty");
waitForAllAsyncStuff();
myFixture.type("System.getPro");
type("System.getPro");
complete("getProperty(String key, String def)");
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { System.setProperty(<hint text=\"key:\"/>System.getProperty(<HINT text=\"key:\"/><caret>, <Hint text=\"def:\"/>), <hint text=\"value:\"/>) } }");
@@ -815,9 +797,9 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
checkResultWithInlays("class C { C(int a, int b) {} void m() { new C(<HINT text=\"a:\"/><caret>, <Hint text=\"b:\"/>) } }");
// test hints remain shown while entering parameter values
myFixture.type("1");
type("1");
next();
myFixture.type("2");
type("2");
waitForAllAsyncStuff();
checkResultWithInlays("class C { C(int a, int b) {} void m() { new C(<Hint text=\"a:\"/>1, <HINT text=\"b:\"/>2<caret>) } }");
@@ -932,10 +914,6 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
myFixture.checkResultWithInlays(text);
}
private void checkHintContents(String hintText) {
assertEquals(hintText, myHintFixture.getCurrentHintText());
}
private void prev() {
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREV_PARAMETER);
}
@@ -980,19 +958,6 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_ESCAPE);
}
private void configureJava(String text) {
myFixture.configureByText(JavaFileType.INSTANCE, text);
}
private void waitForParameterInfoUpdate() throws TimeoutException {
ParameterInfoController.waitForDelayedActions(getEditor(), 1, TimeUnit.MINUTES);
}
private void showParameterInfo() {
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_SHOW_PARAMETER_INFO);
UIUtil.dispatchAllInvocationEvents();
}
private void complete(String partOfItemText) {
LookupElement[] elements = myFixture.completeBasic();
LookupElement element = Stream.of(elements).filter(e -> {
@@ -1002,24 +967,4 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
}).findAny().get();
selectItem(element);
}
public static void waitTillAnimationCompletes(Editor editor) {
long deadline = System.currentTimeMillis() + 60_000;
while (ParameterHintsPresentationManager.getInstance().isAnimationInProgress(editor)) {
if (System.currentTimeMillis() > deadline) fail("Too long waiting for animation to finish");
LockSupport.parkNanos(10_000_000);
UIUtil.dispatchAllInvocationEvents();
}
}
private void waitForAutoPopup() throws TimeoutException {
AutoPopupController.getInstance(getProject()).waitForDelayedActions(1, TimeUnit.MINUTES);
}
private void waitForAllAsyncStuff() throws TimeoutException {
waitForParameterInfoUpdate();
myFixture.doHighlighting();
waitTillAnimationCompletes(getEditor());
waitForAutoPopup();
}
}