diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSmartStepIntoHandler.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSmartStepIntoHandler.kt index 36102c9477f..7386dfb3777 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSmartStepIntoHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/stepping/KotlinSmartStepIntoHandler.kt @@ -44,15 +44,11 @@ class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { override fun isAvailable(position: SourcePosition?) = position?.file is KtFile override fun findSmartStepTargets(position: SourcePosition): List { - if (position.line < 0) return emptyList() - val file = position.file - val lineStart = CodeInsightUtils.getStartLineOffset(file, position.line) ?: return emptyList() + val elementAtOffset = position.elementAt ?: return emptyList() - val elementAtOffset = file.findElementAt(lineStart) ?: return emptyList() - - val element = CodeInsightUtils.getTopmostElementAtOffset(elementAtOffset, lineStart) + val element = CodeInsightUtils.getTopmostElementAtOffset(elementAtOffset, elementAtOffset.textRange.startOffset) if (element !is KtElement) return emptyList() val elementTextRange = element.textRange ?: return emptyList() diff --git a/idea/testData/debugger/tinyApp/outs/smartStepIntoInsideLambda.out b/idea/testData/debugger/tinyApp/outs/smartStepIntoInsideLambda.out new file mode 100644 index 00000000000..9390ecfe235 --- /dev/null +++ b/idea/testData/debugger/tinyApp/outs/smartStepIntoInsideLambda.out @@ -0,0 +1,8 @@ +LineBreakpoint created at smartStepIntoInsideLambda.kt:6 lambdaOrdinal = 0 +!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! smartStepIntoInsideLambda.SmartStepIntoInsideLambdaKt +Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' +smartStepIntoInsideLambda.kt:6 +smartStepIntoInsideLambda.kt:14 +Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket' + +Process finished with exit code 0 diff --git a/idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInsideLambda.kt b/idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInsideLambda.kt new file mode 100644 index 00000000000..3bb6a2276d7 --- /dev/null +++ b/idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInsideLambda.kt @@ -0,0 +1,16 @@ +package smartStepIntoInsideLambda + +fun main(args: Array) { + // SMART_STEP_INTO_BY_INDEX: 1 + //Breakpoint! (lambdaOrdinal = 0) + foo { bar() } +} + +fun foo(f: () -> Unit) { + f() +} + +fun bar() { + val a = 1 +} + diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractSmartStepIntoTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractSmartStepIntoTest.kt index 5249b58276c..0fff365b6da 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractSmartStepIntoTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractSmartStepIntoTest.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.idea.debugger import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture +import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import org.jetbrains.kotlin.idea.debugger.stepping.KotlinSmartStepIntoHandler import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor @@ -33,7 +34,14 @@ abstract class AbstractSmartStepIntoTest : KotlinLightCodeInsightFixtureTestCase val offset = fixture.caretOffset val line = fixture.getDocument(fixture.file!!)!!.getLineNumber(offset) - val position = MockSourcePosition(_file = fixture.file, _line = line, _offset = offset, _editor = fixture.editor) + val lineStart = CodeInsightUtils.getStartLineOffset(file, line)!! + val elementAtOffset = file.findElementAt(lineStart) + + val position = MockSourcePosition(_file = fixture.file, + _line = line, + _offset = offset, + _editor = fixture.editor, + _elementAt = elementAtOffset) val actual = KotlinSmartStepIntoHandler().findSmartStepTargets(position).map { it.presentation } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt index bcadb2ff368..a49845039f8 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt @@ -45,7 +45,6 @@ import com.intellij.xdebugger.XDebuggerUtil import com.intellij.xdebugger.breakpoints.* import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties -import org.jetbrains.kotlin.idea.refactoring.getLineNumber import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinFieldBreakpoint import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinFieldBreakpointType import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinLineBreakpointType @@ -205,16 +204,10 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { } private fun createSmartStepIntoFilters(): List { - val contextElement = ContextUtil.getContextElement(evaluationContext)!! - val line = runReadAction { contextElement.getLineNumber() } - return runReadAction { - val containingFile = contextElement.containingFile - - val position = MockSourcePosition(_file = containingFile, _line = line) + val position = debuggerContext.sourcePosition val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position) - stepTargets.filterIsInstance().mapNotNull { stepTarget -> when (stepTarget) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java index 85b3e20798f..2726ac6691e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -613,6 +613,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doCustomTest(fileName); } + @TestMetadata("smartStepIntoInsideLambda.kt") + public void testSmartStepIntoInsideLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInsideLambda.kt"); + doCustomTest(fileName); + } + @TestMetadata("smartStepIntoInterfaceImpl.kt") public void testSmartStepIntoInterfaceImpl() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInterfaceImpl.kt");