mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
+12
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user