Skip to content

Support breakpoints in untitled files in WinPS #2248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jborean93
Copy link
Contributor

PR Summary

Adds support for setting breakpoints in untitled/unsaved files for Windows PowerShell 5.1. This aligns the breakpoint validation behaviour with the PowerShell 7.x API so that a breakpoint can be set for any ScriptBlock with a filename if it aligns with the client's filename.

PR Context

Fixes: #2243

This also means that breakpoints in untitled files will work in Windows PowerShell 5.1 and not just PowerShell 7+.

Adds support for setting breakpoints in untitled/unsaved files for
Windows PowerShell 5.1. This aligns the breakpoint validation behaviour
with the PowerShell 7.x API so that a breakpoint can be set for any
ScriptBlock with a filename if it aligns with the client's filename.
@Copilot Copilot AI review requested due to automatic review settings July 24, 2025 04:40
Copy link

@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 support for setting breakpoints in untitled/unsaved files for Windows PowerShell 5.1, aligning the breakpoint validation behavior with PowerShell 7.x. This enables debugging of untitled files across all supported PowerShell versions.

  • Replaced direct Set-PSBreakpoint calls with custom logic that bypasses file path validation
  • Removed PowerShell Core version checks that previously limited untitled file breakpoint support
  • Updated tests to verify both command and line breakpoints work in untitled files

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
BreakpointService.cs Implements custom breakpoint creation logic using reflection to bypass file validation
BreakpointHandlers.cs Removes PowerShell version checks and simplifies untitled file support logic
ConfigurationDoneHandler.cs Removes unused dependencies and PowerShell version-specific parsing logic
DebugServiceTests.cs Enhances test coverage with parameterized tests and removes constructor parameter
Comments suppressed due to low confidence (1)

src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs:21

  • [nitpick] The constant name '_setPSBreakpointLegacy' uses an underscore prefix which is typically reserved for private fields, but this is a constant. Consider renaming to 'SetPSBreakpointLegacyScript' for clarity.
        private const string _setPSBreakpointLegacy = @"

@jborean93
Copy link
Contributor Author

An example of this running in 5.1

image

Copy link
Collaborator

@JustinGrote JustinGrote left a comment

Choose a reason for hiding this comment

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

LGTM. For other reviewers, the reason the _runspaceContext isn't needed anymore is because reflection is used to determine which API to use at the command call and PSES no longer does the work.

@andyleejordan this does use reflection to access a private 5.1 API in that runtime, but since that is basically done and "stable" I don't see a risk here since 7+ uses the public API, and we are in "best effort" status on 5.1 anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore file path validation on Set-PSBreakpoint for attach scenarios
2 participants