Debugger: Smart Step Into inside lambda suggests methods from outer context
#KT-10148 Fixed
This commit is contained in:
@@ -44,15 +44,11 @@ class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
|||||||
override fun isAvailable(position: SourcePosition?) = position?.file is KtFile
|
override fun isAvailable(position: SourcePosition?) = position?.file is KtFile
|
||||||
|
|
||||||
override fun findSmartStepTargets(position: SourcePosition): List<SmartStepTarget> {
|
override fun findSmartStepTargets(position: SourcePosition): List<SmartStepTarget> {
|
||||||
if (position.line < 0) return emptyList()
|
|
||||||
|
|
||||||
val file = position.file
|
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, elementAtOffset.textRange.startOffset)
|
||||||
|
|
||||||
val element = CodeInsightUtils.getTopmostElementAtOffset(elementAtOffset, lineStart)
|
|
||||||
if (element !is KtElement) return emptyList()
|
if (element !is KtElement) return emptyList()
|
||||||
|
|
||||||
val elementTextRange = element.textRange ?: return emptyList()
|
val elementTextRange = element.textRange ?: return emptyList()
|
||||||
|
|||||||
@@ -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
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package smartStepIntoInsideLambda
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
// SMART_STEP_INTO_BY_INDEX: 1
|
||||||
|
//Breakpoint! (lambdaOrdinal = 0)
|
||||||
|
foo { bar() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(f: () -> Unit) {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
val a = 1
|
||||||
|
}
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.debugger
|
package org.jetbrains.kotlin.idea.debugger
|
||||||
|
|
||||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
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.debugger.stepping.KotlinSmartStepIntoHandler
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
@@ -33,7 +34,14 @@ abstract class AbstractSmartStepIntoTest : KotlinLightCodeInsightFixtureTestCase
|
|||||||
val offset = fixture.caretOffset
|
val offset = fixture.caretOffset
|
||||||
val line = fixture.getDocument(fixture.file!!)!!.getLineNumber(offset)
|
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 }
|
val actual = KotlinSmartStepIntoHandler().findSmartStepTargets(position).map { it.presentation }
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import com.intellij.xdebugger.XDebuggerUtil
|
|||||||
import com.intellij.xdebugger.breakpoints.*
|
import com.intellij.xdebugger.breakpoints.*
|
||||||
import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties
|
import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties
|
||||||
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties
|
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.KotlinFieldBreakpoint
|
||||||
import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinFieldBreakpointType
|
import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinFieldBreakpointType
|
||||||
import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinLineBreakpointType
|
import org.jetbrains.kotlin.idea.debugger.breakpoints.KotlinLineBreakpointType
|
||||||
@@ -205,16 +204,10 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createSmartStepIntoFilters(): List<MethodFilter> {
|
private fun createSmartStepIntoFilters(): List<MethodFilter> {
|
||||||
val contextElement = ContextUtil.getContextElement(evaluationContext)!!
|
|
||||||
val line = runReadAction { contextElement.getLineNumber() }
|
|
||||||
|
|
||||||
return runReadAction {
|
return runReadAction {
|
||||||
val containingFile = contextElement.containingFile
|
val position = debuggerContext.sourcePosition
|
||||||
|
|
||||||
val position = MockSourcePosition(_file = containingFile, _line = line)
|
|
||||||
|
|
||||||
val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position)
|
val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position)
|
||||||
|
|
||||||
stepTargets.filterIsInstance<SmartStepTarget>().mapNotNull {
|
stepTargets.filterIsInstance<SmartStepTarget>().mapNotNull {
|
||||||
stepTarget ->
|
stepTarget ->
|
||||||
when (stepTarget) {
|
when (stepTarget) {
|
||||||
|
|||||||
@@ -613,6 +613,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest {
|
|||||||
doCustomTest(fileName);
|
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")
|
@TestMetadata("smartStepIntoInterfaceImpl.kt")
|
||||||
public void testSmartStepIntoInterfaceImpl() throws Exception {
|
public void testSmartStepIntoInterfaceImpl() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInterfaceImpl.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/smartStepIntoInterfaceImpl.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user