提交 076870ee 编写于 作者: N Nikolay Krasko

Fix double return hint in lambda for annotated expression (KT-23238)

#KT-23238 Fixed
上级 c5d5f0c2
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.idea.parameterInfo package org.jetbrains.kotlin.idea.parameterInfo
import com.intellij.codeInsight.hints.InlayInfo import com.intellij.codeInsight.hints.InlayInfo
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
...@@ -18,12 +19,11 @@ fun provideLambdaReturnValueHints(expression: KtExpression): List<InlayInfo> { ...@@ -18,12 +19,11 @@ fun provideLambdaReturnValueHints(expression: KtExpression): List<InlayInfo> {
return emptyList() return emptyList()
} }
val parent = expression.parent if (!KtPsiUtil.isStatement(expression)) {
if (parent is KtDotQualifiedExpression || if (!allowLabelOnExpressionPart(expression)) {
parent is KtSafeQualifiedExpression || return emptyList()
parent is KtBinaryExpression || }
parent is KtUnaryExpression } else if (forceLabelOnExpressionPart(expression)) {
) {
return emptyList() return emptyList()
} }
...@@ -53,3 +53,18 @@ private fun getNameOfFunctionThatTakesLambda(expression: KtExpression): String? ...@@ -53,3 +53,18 @@ private fun getNameOfFunctionThatTakesLambda(expression: KtExpression): String?
} }
return null return null
} }
private fun allowLabelOnExpressionPart(expression: KtExpression): Boolean {
val parent = expression.parent
return parent is KtAnnotatedExpression && parent.baseExpression == expression && parent.lineSeparatorBeforeBase()
}
private fun forceLabelOnExpressionPart(expression: KtExpression): Boolean {
return expression is KtAnnotatedExpression && expression.lineSeparatorBeforeBase()
}
private fun KtAnnotatedExpression.lineSeparatorBeforeBase(): Boolean {
val base = baseExpression ?: return false
val whiteSpace = base.node.treePrev?.psi as? PsiWhiteSpace ?: return false
return whiteSpace.text.contains("\n")
}
...@@ -136,4 +136,26 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() { ...@@ -136,4 +136,26 @@ class LambdaReturnValueHintsTest : KotlinLightCodeInsightFixtureTestCase() {
""" """
) )
} }
fun testAnnotatedStatement() {
check(
"""
@Target(AnnotationTarget.EXPRESSION)
annotation class Some
fun test() {
run {
val files: Any? = null
@Some
<hint text="^run"/>12
}
run {
val files: Any? = null
<hint text="^run"/>@Some 12
}
}
"""
)
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册