From 49b4e3d63e6af27e28ade480e4f9831f03f732ac Mon Sep 17 00:00:00 2001 From: "andrey.matveev" Date: Thu, 2 Mar 2023 00:38:09 +0200 Subject: [PATCH] PY-55349 Fix find local paths for target remote files GitOrigin-RevId: 2b33e4233f353ed0f324362473273527de4ce707 --- .../debugger/PyTargetPositionConverters.kt | 12 +++++++----- .../ProcessHandlerWithPyPositionConverter.kt | 19 ++++++++++--------- .../python/run/PythonCommandLineState.java | 10 ++++++---- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/python/src/com/jetbrains/python/debugger/PyTargetPositionConverters.kt b/python/src/com/jetbrains/python/debugger/PyTargetPositionConverters.kt index fac522b8ac58..c4c105e6701a 100644 --- a/python/src/com/jetbrains/python/debugger/PyTargetPositionConverters.kt +++ b/python/src/com/jetbrains/python/debugger/PyTargetPositionConverters.kt @@ -11,6 +11,7 @@ import com.intellij.util.AbstractPathMapper import com.intellij.util.PathMappingSettings import com.jetbrains.python.debugger.remote.vfs.PyRemotePositionConverter import com.jetbrains.python.remote.PyRemotePathMapper +import org.jetbrains.annotations.ApiStatus /** * Creates [PyPositionConverter] for [debugProcess]. The converter uses [pathMappingSettings] for paths resolution and upload volumes @@ -29,14 +30,13 @@ import com.jetbrains.python.remote.PyRemotePathMapper * @see getTargetPaths */ internal fun createTargetedPositionConverter(debugProcess: PyDebugProcess, - targetEnvironment: TargetEnvironment, - pathMappingSettings: PathMappingSettings): PyPositionConverter { - val pathMapper = PyTargetPathMapper(targetEnvironment, pathMappingSettings) + pathMapper: PyTargetPathMapper): PyPositionConverter { return PyRemotePositionConverter(debugProcess, pathMapper) } -private class PyTargetPathMapper(private val targetEnvironment: TargetEnvironment, - private val pathMappingSettings: PathMappingSettings) : PyRemotePathMapper() { +@ApiStatus.Internal +internal class PyTargetPathMapper(private val targetEnvironment: TargetEnvironment, + private val pathMappingSettings: PathMappingSettings) : PyRemotePathMapper() { override fun convertToLocal(remotePath: String): String { return AbstractPathMapper.convertToLocal(remotePath, pathMappingSettings.pathMappings) ?: targetEnvironment.getLocalPaths(remotePath).firstOrNull() @@ -52,4 +52,6 @@ private class PyTargetPathMapper(private val targetEnvironment: TargetEnvironmen override fun isEmpty(): Boolean { return false } + + fun getFileMappings(): MutableList = pathMappingSettings.pathMappings } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/run/ProcessHandlerWithPyPositionConverter.kt b/python/src/com/jetbrains/python/run/ProcessHandlerWithPyPositionConverter.kt index 823dbd5d7d04..ec96e753bc8a 100644 --- a/python/src/com/jetbrains/python/run/ProcessHandlerWithPyPositionConverter.kt +++ b/python/src/com/jetbrains/python/run/ProcessHandlerWithPyPositionConverter.kt @@ -2,20 +2,21 @@ package com.jetbrains.python.run import com.intellij.execution.process.KillableColoredProcessHandler -import com.intellij.execution.target.TargetEnvironment +import com.intellij.remote.ProcessControlWithMappings +import com.intellij.util.PathMapper import com.intellij.util.PathMappingSettings -import com.jetbrains.python.debugger.PositionConverterProvider -import com.jetbrains.python.debugger.PyDebugProcess -import com.jetbrains.python.debugger.PyPositionConverter -import com.jetbrains.python.debugger.createTargetedPositionConverter +import com.jetbrains.python.debugger.* import java.nio.charset.Charset internal class ProcessHandlerWithPyPositionConverter(process: Process, commandLine: String, charset: Charset, - private val targetEnvironment: TargetEnvironment, - private val pathMappingSettings: PathMappingSettings) - : KillableColoredProcessHandler(process, commandLine, charset), PositionConverterProvider { + private val pathMapper: PyTargetPathMapper) + : KillableColoredProcessHandler(process, commandLine, charset), PositionConverterProvider, ProcessControlWithMappings { override fun createPositionConverter(debugProcess: PyDebugProcess): PyPositionConverter = - createTargetedPositionConverter(debugProcess, targetEnvironment, pathMappingSettings) + createTargetedPositionConverter(debugProcess, pathMapper) + + override fun getMappingSettings(): PathMapper = pathMapper + + override fun getFileMappings(): MutableList = pathMapper.getFileMappings() } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/run/PythonCommandLineState.java b/python/src/com/jetbrains/python/run/PythonCommandLineState.java index 11257f53c718..cb0f8a43b206 100644 --- a/python/src/com/jetbrains/python/run/PythonCommandLineState.java +++ b/python/src/com/jetbrains/python/run/PythonCommandLineState.java @@ -57,6 +57,7 @@ import com.jetbrains.python.PythonHelpersLocator; import com.jetbrains.python.console.PyDebugConsoleBuilder; import com.jetbrains.python.debugger.PyDebugRunner; import com.jetbrains.python.debugger.PyDebuggerOptionsProvider; +import com.jetbrains.python.debugger.PyTargetPathMapper; import com.jetbrains.python.facet.LibraryContributingFacet; import com.jetbrains.python.facet.PythonPathContributingFacet; import com.jetbrains.python.library.PythonLibraryType; @@ -484,18 +485,19 @@ public abstract class PythonCommandLineState extends CommandLineState { } return new PythonProcessHandler(process, commandLineString, commandLine.getCharset()); } - PathMappingSettings consolidatedPathMappings = new PathMappingSettings(); + PathMappingSettings pathMappingSettings = new PathMappingSettings(); // add mappings from run configuration on top PathMappingSettings runConfigurationPathMappings = myConfig.myMappingSettings; if (runConfigurationPathMappings != null) { - consolidatedPathMappings.addAll(runConfigurationPathMappings); + pathMappingSettings.addAll(runConfigurationPathMappings); } // add path mappings configured in SDK, they will be handled in second place PathMappingSettings sdkPathMappings = getSdkPathMappings(); if (sdkPathMappings != null) { - consolidatedPathMappings.addAll(sdkPathMappings); + pathMappingSettings.addAll(sdkPathMappings); } - return new ProcessHandlerWithPyPositionConverter(process, commandLineString, commandLine.getCharset(), targetEnvironment, + PyTargetPathMapper consolidatedPathMappings = new PyTargetPathMapper(targetEnvironment, pathMappingSettings); + return new ProcessHandlerWithPyPositionConverter(process, commandLineString, commandLine.getCharset(), consolidatedPathMappings); }