don't show completion hints when call's PSI is broken due to typo

showing no hints seems a better option than showing hints for all parameters at a single offset
This commit is contained in:
Dmitry Batrak
2018-01-12 16:47:41 +03:00
parent 93fb05b67b
commit 242d39f98a
2 changed files with 22 additions and 4 deletions
@@ -1,4 +1,6 @@
// 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.codeInsight.hints
import com.intellij.codeInsight.completion.CompletionMemory
@@ -16,10 +18,14 @@ object JavaInlayHintsProvider {
fun hints(callExpression: PsiCallExpression): Set<InlayInfo> {
if (JavaMethodCallElement.isCompletionMode(callExpression)) {
val argumentList = callExpression.argumentList?:return emptySet()
val text = argumentList.text
if (text == null || !text.startsWith('(') || !text.endsWith(')')) return emptySet()
val method = CompletionMemory.getChosenMethod(callExpression)?:return emptySet()
val params = method.parameterList.parameters
val arguments = callExpression.argumentList?.expressions ?: emptyArray()
val arguments = argumentList.expressions
return params.mapIndexedNotNull { i, parameter ->
val paramName = parameter.name ?: return@mapIndexedNotNull null
@@ -28,7 +34,7 @@ object JavaInlayHintsProvider {
val paramToShow = (if (varargHint) ", " else "") + paramName
val offset = if (i < arguments.size) inlayOffset(arguments[i])
else if (varargHint && i == arguments.size) callExpression.textRange.endOffset - 1
else (callExpression.argumentList?.textOffset?:return@mapIndexedNotNull null) + 1
else argumentList.textOffset + 1
InlayInfo(paramToShow, offset, false, params.size == 1, varargHint)
}.toSet()
}
@@ -837,6 +837,18 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
checkHintContents("<html><b>String</b></html>");
}
public void testBrokenPsiCall() throws Exception {
configureJava("class C { void m() { System.setPro<caret> } }");
complete("setProperty");
checkResultWithInlays("class C { void m() { System.setProperty(<HINT text=\"key:\"/><caret>, <Hint text=\"value:\"/>) } }");
type(';');
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { System.setProperty(;<caret>, ) } }");
backspace();
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { System.setProperty(<HINT text=\"key:\"/><caret>, <Hint text=\"value:\"/>) } }");
}
private void enableConstructorVariantsCompletion() {
Registry.get("java.completion.show.constructors").setValue(true);
Disposer.register(myFixture.getTestRootDisposable(), () -> Registry.get("java.completion.show.constructors").setValue(false));