From 4246fcf2561d8f3221f312317e4d2986cedb1529 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 27 Oct 2016 13:48:29 +0200 Subject: [PATCH] "Show expression type" no longer shows elements which enclose the element at caret (KT-14436) --- .../kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt | 6 ++++-- idea/testData/codeInsight/expressionType/IfAsExpression.kt | 1 - .../codeInsight/expressionType/IfAsExpressionInsideBlock.kt | 2 -- idea/testData/codeInsight/expressionType/Lambda.kt | 6 +----- idea/testData/codeInsight/expressionType/MethodReference.kt | 1 - .../codeInsight/expressionType/MultiDeclarationInLambda.kt | 2 -- .../expressionType/SoftSmartCastMultipleTypes.kt | 1 - 7 files changed, 5 insertions(+), 14 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt index 801994c40d6..dae47806fd9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt @@ -36,8 +36,10 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider() { textFormat = RenderingFormat.HTML } - override fun getExpressionsAt(elementAt: PsiElement): List = - elementAt.parentsWithSelf.filterIsInstance().filter { it.shouldShowType() }.toList() + override fun getExpressionsAt(elementAt: PsiElement): List { + val candidates = elementAt.parentsWithSelf.filterIsInstance().filter { it.shouldShowType() }.toList() + return candidates.takeWhile { it.textRange.startOffset == candidates.first().textRange.startOffset } + } private fun KtExpression.shouldShowType() = when (this) { is KtFunctionLiteral -> false diff --git a/idea/testData/codeInsight/expressionType/IfAsExpression.kt b/idea/testData/codeInsight/expressionType/IfAsExpression.kt index 821e17f92e6..ddb4638481a 100644 --- a/idea/testData/codeInsight/expressionType/IfAsExpression.kt +++ b/idea/testData/codeInsight/expressionType/IfAsExpression.kt @@ -1,4 +1,3 @@ val x = if (2 > 1) 3 else 4 // TYPE: if (2 > 1) 3 else 4 -> Int -// TYPE: val x = if (2 > 1) 3 else 4 -> Int diff --git a/idea/testData/codeInsight/expressionType/IfAsExpressionInsideBlock.kt b/idea/testData/codeInsight/expressionType/IfAsExpressionInsideBlock.kt index e40e44ece69..abdaf33f78e 100644 --- a/idea/testData/codeInsight/expressionType/IfAsExpressionInsideBlock.kt +++ b/idea/testData/codeInsight/expressionType/IfAsExpressionInsideBlock.kt @@ -3,5 +3,3 @@ val x = if (flag) { } else 42 // TYPE: if (flag2) 13 else 7 -> Int -// TYPE: if (flag) { if (flag2) 13 else 7 } else 42 -> Int -// TYPE: val x = if (flag) { if (flag2) 13 else 7 } else 42 -> Int diff --git a/idea/testData/codeInsight/expressionType/Lambda.kt b/idea/testData/codeInsight/expressionType/Lambda.kt index b85e0361e12..af62f63126a 100644 --- a/idea/testData/codeInsight/expressionType/Lambda.kt +++ b/idea/testData/codeInsight/expressionType/Lambda.kt @@ -1,7 +1,3 @@ -val x = listOf(1).map { q -> println(q) } +val x = listOf(1).map { q -> println(q) } -// TYPE: q -> Int -// TYPE: println(q) -> Unit // TYPE: { q -> println(q) } -> (Int) → Unit -// TYPE: listOf(1).map { q -> println(q) } -> List<Unit> -// TYPE: val x = listOf(1).map { q -> println(q) } -> List<Unit> diff --git a/idea/testData/codeInsight/expressionType/MethodReference.kt b/idea/testData/codeInsight/expressionType/MethodReference.kt index a0746270a2c..aef9b2db70c 100644 --- a/idea/testData/codeInsight/expressionType/MethodReference.kt +++ b/idea/testData/codeInsight/expressionType/MethodReference.kt @@ -6,4 +6,3 @@ fun bar() { } // TYPE: ::foo -> KFunction0<Unit> -// TYPE: run(::foo) -> Unit diff --git a/idea/testData/codeInsight/expressionType/MultiDeclarationInLambda.kt b/idea/testData/codeInsight/expressionType/MultiDeclarationInLambda.kt index 029875c8120..9e2cd14fa9f 100644 --- a/idea/testData/codeInsight/expressionType/MultiDeclarationInLambda.kt +++ b/idea/testData/codeInsight/expressionType/MultiDeclarationInLambda.kt @@ -6,5 +6,3 @@ fun f(x: List) { } // TYPE: first -> Int -// TYPE: { (first, second) -> } -> (IntStringPair) → Unit -// TYPE: x.forEach { (first, second) -> } -> Unit diff --git a/idea/testData/codeInsight/expressionType/SoftSmartCastMultipleTypes.kt b/idea/testData/codeInsight/expressionType/SoftSmartCastMultipleTypes.kt index 479538973bc..b5843e4c64d 100644 --- a/idea/testData/codeInsight/expressionType/SoftSmartCastMultipleTypes.kt +++ b/idea/testData/codeInsight/expressionType/SoftSmartCastMultipleTypes.kt @@ -11,4 +11,3 @@ fun fn(value: Any) { } // TYPE: value -> A & B (smart cast from Any) -// TYPE: println(value) -> Unit