Disable "Add labeled return" for suspend lambdas #KT-23126 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
5d1f5d9bca
commit
e3a69d118f
@@ -9,6 +9,7 @@ import com.intellij.codeInsight.intention.LowPriorityAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
|
||||
|
||||
@@ -19,6 +20,7 @@ class AddLabeledReturnInLambdaIntention : SelfTargetingRangeIntention<KtBlockExp
|
||||
override fun applicabilityRange(element: KtBlockExpression): TextRange? {
|
||||
if (!isApplicableTo(element)) return null
|
||||
val labelName = element.getParentLambdaLabelName() ?: return null
|
||||
if (labelName == KtTokens.SUSPEND_KEYWORD.value) return null
|
||||
text = "Add return@$labelName"
|
||||
return element.statements.lastOrNull()?.textRange
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo() {
|
||||
suspend {
|
||||
<caret>true
|
||||
}
|
||||
}
|
||||
@@ -468,6 +468,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("suspend.kt")
|
||||
public void testSuspend() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addLabeledReturnInLambda/suspend.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unit.kt")
|
||||
public void testUnit() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addLabeledReturnInLambda/unit.kt");
|
||||
|
||||
Reference in New Issue
Block a user