Skip to content

Commit d886cd7

Browse files
committed
Fix breakpoints when inline call is in qualified expression (KT-16062)
Scope is stored for DOT_QUALIFIED_EXPRESSION not directly for CALL_EXPRESSION. #KT-16062 Fixed
1 parent 2719016 commit d886cd7

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerClassNameProvider.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.DumbService
2525
import com.intellij.openapi.roots.libraries.LibraryUtil
2626
import com.intellij.openapi.ui.MessageType
2727
import com.intellij.psi.PsiElement
28+
import com.intellij.psi.PsiFile
2829
import com.intellij.psi.search.GlobalSearchScope
2930
import com.intellij.psi.search.searches.ReferencesSearch
3031
import com.intellij.psi.util.PsiTreeUtil
@@ -49,12 +50,13 @@ import org.jetbrains.kotlin.idea.util.application.runReadAction
4950
import org.jetbrains.kotlin.load.java.JvmAbi
5051
import org.jetbrains.kotlin.name.Name
5152
import org.jetbrains.kotlin.psi.*
52-
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
5353
import org.jetbrains.kotlin.psi.psiUtil.parents
54+
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
5455
import org.jetbrains.kotlin.resolve.BindingContext
5556
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
5657
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
5758
import org.jetbrains.kotlin.resolve.inline.InlineUtil
59+
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
5860
import org.jetbrains.kotlin.resolve.source.getPsi
5961
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
6062

@@ -219,7 +221,7 @@ class DebuggerClassNameProvider(val myDebugProcess: DebugProcess, val scopes: Li
219221
}?.first
220222
} ?: return emptyList()
221223

222-
val lexicalScope = context[BindingContext.LEXICAL_SCOPE, inlineCall] ?: return emptyList()
224+
val lexicalScope = runReadAction { inlineCall.getExpressionResolutionScope(context) } ?: return emptyList()
223225
val baseClassName = classNamesForPosition(inlineCall, false).firstOrNull() ?: return emptyList()
224226

225227
val resolvedCall = runReadAction { inlineCall.getResolvedCall(context) } ?: return emptyList()
@@ -424,4 +426,11 @@ private fun String.substringIndex(): String {
424426
return substringBeforeLast("$") + "$"
425427
}
426428
return this
429+
}
430+
431+
private fun KtCallExpression.getExpressionResolutionScope(bindingContext: BindingContext): LexicalScope? {
432+
return parentsWithSelf
433+
.takeWhile { it !is KtClassBody && it !is KtBlockExpression && it !is PsiFile }
434+
.map { if (it is KtElement) bindingContext[BindingContext.LEXICAL_SCOPE, it] else null }
435+
.firstOrNull { it != null }
427436
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
LineBreakpoint created at stopInExtensionInlineCall.kt:8
2+
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stopInExtensionInlineCall.StopInExtensionInlineCallKt
3+
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
4+
stopInExtensionInlineCall.kt:8
5+
stopInExtensionInlineCall.kt:9
6+
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
7+
8+
Process finished with exit code 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package stopInExtensionInlineCall
2+
3+
fun main(args: Array<String>) {
4+
val a = 1
5+
12.apply {
6+
{
7+
//Breakpoint!
8+
foo(a)
9+
}()
10+
}
11+
}
12+
13+
inline fun <T> T.inlineApply(block: T.() -> kotlin.Unit) { this.block() }
14+
15+
fun foo(a: Any) {}

idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,12 @@ public void testStopInCrossinlineInSuspend() throws Exception {
722722
doStepOverTest(fileName);
723723
}
724724

725+
@TestMetadata("stopInExtensionInlineCall.kt")
726+
public void testStopInExtensionInlineCall() throws Exception {
727+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInExtensionInlineCall.kt");
728+
doStepOverTest(fileName);
729+
}
730+
725731
@TestMetadata("stopInInlineCallLocalFunLambda.kt")
726732
public void testStopInInlineCallLocalFunLambda() throws Exception {
727733
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInInlineCallLocalFunLambda.kt");

0 commit comments

Comments
 (0)