diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHints.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHints.kt index 6ffe3639249..2deaf1d7b5d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHints.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHints.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.parameterInfo import com.intellij.codeInsight.hints.InlayInfo import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isOneLiner import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType @@ -15,7 +16,15 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsResultOfLambda fun provideLambdaReturnValueHints(expression: KtExpression): List { - if (expression is KtIfExpression || expression is KtWhenExpression || expression is KtBlockExpression) { + if (expression is KtWhenExpression || expression is KtBlockExpression) { + return emptyList() + } + + if (expression is KtIfExpression && !expression.isOneLiner()) { + return emptyList() + } + + if (expression.getParentOfType(true)?.isOneLiner() == true) { return emptyList() } diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayHintTypeTestUtil.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayHintTypeTestUtil.kt index 1eaa0df5eae..94e400a9bb7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayHintTypeTestUtil.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayHintTypeTestUtil.kt @@ -19,6 +19,10 @@ internal fun JavaCodeInsightTestFixture.checkHintType(text: String, hintType: Hi configureByText("A.kt", text.trimIndent()) doHighlighting() + checkHintType(hintType) +} + +internal fun JavaCodeInsightTestFixture.checkHintType(hintType: HintType) { val hintInfo = getHintInfoFromProvider(caretOffset, file, editor) Assert.assertNotNull("No hint available at caret", hintInfo) Assert.assertEquals(hintType.option.name, (hintInfo as HintInfo.OptionInfo).optionName) diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaImplicitHintsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaImplicitHintsTest.kt index 6236dd9906c..ca74107a3fe 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaImplicitHintsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaImplicitHintsTest.kt @@ -5,11 +5,9 @@ package org.jetbrains.kotlin.idea.parameterInfo -import com.intellij.codeInsight.hints.HintInfo import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.junit.Assert class LambdaImplicitHintsTest : KotlinLightCodeInsightFixtureTestCase() { override fun getProjectDescriptor(): KotlinLightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt index ebe796d516d..e6b2a9d5478 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/LambdaReturnValueHintsTest.kt @@ -15,18 +15,10 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { fun check(text: String) { myFixture.configureByText("A.kt", text.trimIndent()) myFixture.testInlays() - } - fun testHintType() { - myFixture.checkHintType( - """ - val x = run { - println("foo") - 1 - } - """, - HintType.LAMBDA_RETURN_EXPRESSION - ) + if (myFixture.editor.caretModel.offset != 0) { + myFixture.checkHintType(HintType.LAMBDA_RETURN_EXPRESSION) + } } fun testSimple() { @@ -34,7 +26,7 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { """ val x = run { println("foo") - 1 + 1 } """ ) @@ -65,6 +57,17 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { ) } + fun testOneLineIf() { + check( + """ + val x = run { + println(1) + if (true) 1 else { 0 } + } + """ + ) + } + fun testWhen() { check( """