Skip to content

Conversation

jborean93
Copy link
Contributor

PR Summary

Adds the pathMappings option to the debugger that can be used to map a local to remote path and vice versa. This is useful if the local environment has a checkout of the files being run on a remote target but at a different path. The mappings are used to translate the paths that will the breakpoint will be set to in the target PowerShell instance. It is also used to update the stack trace paths received from the remote.

For a launch scenario, the path mappings are also used when launching a script if the integrated terminal has entered a remote runspace.

PR Context

Fixes: #2242

@Copilot Copilot AI review requested due to automatic review settings July 31, 2025 06:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a pathMappings option to the PowerShell debugger that enables mapping between local and remote file paths during debugging sessions. This is particularly useful when debugging remote PowerShell instances where the local development environment has the same files but at different paths.

Key changes:

  • Adds PathMapping record to define local-to-remote path mappings
  • Integrates path mapping logic into breakpoint setting, stack trace handling, and script launching
  • Adds comprehensive end-to-end test for attach scenarios with path mappings

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
PathMapping.cs New record defining the structure for local/remote path mappings
DebugService.cs Core path mapping logic with methods to translate between local and remote paths
LaunchAndAttachHandler.cs Integration of path mappings into launch and attach request handling
StackTraceHandler.cs Updates stack trace paths using path mappings for remote debugging
BreakpointService.cs Modified to use mapped paths when setting breakpoints
BreakpointApiUtils.cs Added script path override parameter for breakpoint setting
DisconnectHandler.cs Cleanup of path mappings on disconnect
DscBreakpointCapability.cs Minor refactor to extract module name instead of full module info
DebugAdapterProtocolMessageTests.cs Comprehensive E2E test for path mapping functionality
Comments suppressed due to low confidence (1)

test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs:580

  • Spelling error: 'cotinue' should be 'continue'.
                // background and requesting the st is the only wait to ensure

@jborean93
Copy link
Contributor Author

An example of how the pathMappings can be used for launching when the interactive terminal has entered a remote runspace. The editor sees the file under /home/jborean/dev/vscode-powershell/examples/test.ps1 but the pathMappings will map it to C:\temp\test.ps1 where that same script is located on the remote host.

{
  "name": "PowerShell Launch Script",
  "type": "PowerShell",
  "request": "launch",
  "script": "${workspaceFolder}/test.ps1",
  "cwd": "${cwd}",
  "pathMappings": [
    {
      "localRoot": "${workspaceFolder}/",
      "remoteRoot": "C:\\temp\\"
    }
  ]
},
image

It looks like I need to update the logic for the client breakpoint to contain the original workspace path and not the mapped remote file so I will fix that.

Adds the `pathMappings` option to the debugger that can be used to map a
local to remote path and vice versa. This is useful if the local
environment has a checkout of the files being run on a remote target but
at a different path. The mappings are used to translate the paths that
will the breakpoint will be set to in the target PowerShell instance. It
is also used to update the stack trace paths received from the remote.

For a launch scenario, the path mappings are also used when launching a
script if the integrated terminal has entered a remote runspace.
Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@andyleejordan andyleejordan enabled auto-merge (squash) September 4, 2025 20:28
@andyleejordan andyleejordan changed the title Add pathMappings option to debugger Add pathMappings option to debugger Sep 4, 2025
@andyleejordan andyleejordan enabled auto-merge (squash) September 4, 2025 20:29
andyleejordan pushed a commit to PowerShell/vscode-powershell that referenced this pull request Sep 4, 2025
@andyleejordan andyleejordan merged commit 8d7e88f into PowerShell:main Sep 4, 2025
6 checks passed
@jborean93 jborean93 deleted the path-mapping branch September 4, 2025 21:01
@jborean93
Copy link
Contributor Author

Thanks for the review and merge!

@andyleejordan andyleejordan added the Issue-Enhancement A feature request (enhancement). label Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Path Mapping on Attach request
3 participants