Support breakpoints in untitled files in WinPS#2248
Support breakpoints in untitled files in WinPS#2248andyleejordan merged 4 commits intoPowerShell:mainfrom
Conversation
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.
There was a problem hiding this comment.
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-PSBreakpointcalls 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 = @"
There was a problem hiding this comment.
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.
andyleejordan
left a comment
There was a problem hiding this comment.
Love it, thanks so much!
|
Appreciate the reviews and checks over these! |

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+.