IDEA-195668 Do not show completion hints in improper context

This commit is contained in:
Dmitry Batrak
2018-07-17 15:05:49 +03:00
parent 717484f15a
commit ef01d133bc
2 changed files with 15 additions and 2 deletions
@@ -310,11 +310,18 @@ public class JavaMethodCallElement extends LookupItem<PsiMethod> implements Type
CaretModel caretModel = editor.getCaretModel();
int offset = caretModel.getOffset();
int afterParenOffset = offset + 1;
if (afterParenOffset < document.getTextLength() &&
Character.isJavaIdentifierPart(document.getImmutableCharSequence().charAt(afterParenOffset))) {
return;
}
int braceOffset = offset - 1;
int numberOfParametersToDisplay = parametersCount > 1 && PsiImplUtil.isVarArgs(method) ? parametersCount - 1 : parametersCount;
int numberOfCommas = Math.min(numberOfParametersToDisplay, limit) - 1;
String commas = Registry.is("editor.completion.hints.virtual.comma") ? "" : StringUtil.repeat(", ", numberOfCommas);
editor.getDocument().insertString(offset, commas);
document.insertString(offset, commas);
PsiDocumentManager.getInstance(project).commitDocument(document);
MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
@@ -1369,7 +1369,7 @@ public class CompletionHintsTest extends AbstractParameterInfoTestCase {
"}");
}
public void testCaretMovementOverVirtualComma() throws Exception {
public void testCaretMovementOverVirtualComma() {
enableVirtualComma();
configureJava("class C { void m() { System.getPro<caret> } }");
@@ -1380,6 +1380,12 @@ public class CompletionHintsTest extends AbstractParameterInfoTestCase {
checkResultWithInlays("class C { void m() { System.getProperty(<Hint text=\"key:\"/>, <HINT text=\"def:\"/><caret>) } }");
}
public void testHintsAreNotShownInImproperContext() {
configureJava("class C { void m() { int a = Math.ma<caret>5; } }");
complete("max(int a, int b)");
checkResult("class C { void m() { int a = Math.max(<caret>)5; } }");
}
private void checkResultWithInlays(String text) {
myFixture.checkResultWithInlays(text);
}