Fix completion for codeFragments on functions with expression body
This commit is contained in:
@@ -30,27 +30,16 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
//TODO: this code should be moved into debugger which should set correct context for its code fragment
|
||||
private fun JetExpression.correctContextForExpression(): JetExpression {
|
||||
when (this) {
|
||||
is JetBlockExpression -> {
|
||||
return this.getStatements().lastOrNull() ?: this
|
||||
}
|
||||
is JetFunctionLiteral -> {
|
||||
return this.getBodyExpression()?.getStatements()?.lastOrNull() ?: this
|
||||
}
|
||||
return when (this) {
|
||||
is JetProperty -> this.getDelegateExpressionOrInitializer()
|
||||
is JetFunctionLiteral -> this.getBodyExpression()?.getStatements()?.lastOrNull()
|
||||
is JetDeclarationWithBody -> this.getBodyExpression()
|
||||
is JetBlockExpression -> this.getStatements().lastOrNull()
|
||||
else -> {
|
||||
val previousExpression = this.siblings(forward = false, withItself = false).firstIsInstanceOrNull<JetExpression>()
|
||||
if (previousExpression is JetExpression) {
|
||||
return previousExpression
|
||||
}
|
||||
else {
|
||||
val parentExpression = this.parents.firstIsInstanceOrNull<JetExpression>()
|
||||
if (parentExpression is JetExpression) {
|
||||
return parentExpression
|
||||
}
|
||||
}
|
||||
this.siblings(forward = false, withItself = false).firstIsInstanceOrNull<JetExpression>()
|
||||
?: this.parents.firstIsInstanceOrNull<JetExpression>()
|
||||
}
|
||||
}
|
||||
return this
|
||||
} ?: this
|
||||
}
|
||||
|
||||
public fun JetCodeFragment.getScopeAndDataFlowForAnalyzeFragment(
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<caret>fun foo(aaaB: Int) = aaaB
|
||||
@@ -0,0 +1 @@
|
||||
aaaB
|
||||
@@ -0,0 +1,6 @@
|
||||
package withoutBodyProperties
|
||||
|
||||
class A {
|
||||
val aaaB = 1
|
||||
<caret>val aaaC = 1
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
aaaB + aaaC
|
||||
+12
@@ -132,6 +132,18 @@ public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentH
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/smartCasts.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withoutBodyFunction.kt")
|
||||
public void testWithoutBodyFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/withoutBodyFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withoutBodyProperty.kt")
|
||||
public void testWithoutBodyProperty() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/codeFragments/withoutBodyProperty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/checker/codeFragments/imports")
|
||||
|
||||
Reference in New Issue
Block a user