Skip to content

Support breakpoints in untitled files in WinPS - #2248

Merged
Andy Jordan (andyleejordan) merged 4 commits into
PowerShell:mainfrom
jborean93:set-breakpoint-5.1
Aug 5, 2025
Merged

Support breakpoints in untitled files in WinPS#2248
Andy Jordan (andyleejordan) merged 4 commits into
PowerShell:mainfrom
jborean93:set-breakpoint-5.1

Conversation

@jborean93

Copy link
Copy Markdown
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.
CopilotAI review requested due to automatic review settings July 24, 2025 04:40

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.

FileDescription
BreakpointService.csImplements custom breakpoint creation logic using reflection to bypass file validation
BreakpointHandlers.csRemoves PowerShell version checks and simplifies untitled file support logic
ConfigurationDoneHandler.csRemoves unused dependencies and PowerShell version-specific parsing logic
DebugServiceTests.csEnhances 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
Copy Markdown
ContributorAuthor

An example of this running in 5.1

image

@JustinGroteJustin Grote (JustinGrote) left a comment

Copy link
Copy Markdown
Collaborator

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.

Andy Jordan (@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love it, thanks so much!

@andyleejordan
Andy Jordan (andyleejordan) merged commit 48c996c into PowerShell:mainAug 5, 2025
6 checks passed
@jborean93
Jordan Borean (jborean93) deleted the set-breakpoint-5.1 branch August 5, 2025 18:55
@jborean93

Copy link
Copy Markdown
ContributorAuthor

Appreciate the reviews and checks over these!

@andyleejordanAndy Jordan (andyleejordan) added the Issue-Enhancement A feature request (enhancement). label Sep 5, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-DebuggingIssue-EnhancementA feature request (enhancement).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore file path validation on Set-PSBreakpoint for attach scenarios

4 participants

@jborean93@andyleejordan@JustinGrote