Repository navigation
Track formatter ranges through iterative corrections - #2264
Open
Christoph Bergmeister (bergmeister) with Copilot wants to merge 4 commits into
Open
Christoph Bergmeister (bergmeister) with Copilot wants to merge 4 commits into
Christoph Bergmeister (bergmeister) with Copilot wants to merge 4 commits into
Conversation
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix issue with Invoke-Formatter -Range dropping corrections
Track formatter ranges through iterative corrections
Oct 27, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Empty replacements can cause range-endpoint mapping to throw after deleting selected lines, so zero-line replacements need explicit handling, including when no selected lines remain.
1 open issue
What changed in this PR
This PR addresses #2211 by tracking formatter selection boundaries as corrections change the text, so later fixes remain within the intended range.
Changes:
- Update the range endpoint after each correction, accounting for line and column changes.
- Add regression coverage for expanding and shortening selections, inserting and removing lines, and preserving adjacent unselected lines.
| File | Description |
|---|---|
| Tests/Engine/InvokeFormatter.tests.ps1 | Adds range-formatting regression cases. |
| Engine/ScriptAnalyzer.cs | Replaces per-pass line-count adjustment with per-correction endpoint tracking. |
Review effort: Balanced
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Zero-line replacements mishandle selection endpoints, potentially causing negative-column exceptions or allowing subsequent formatting to modify originally unselected text.
2 open issues
1 resolved since last review
Review effort: Balanced
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Christoph Bergmeister (bergmeister)
marked this pull request as ready for review
October 28, 2026 11:40
Christoph Bergmeister (bergmeister)
requested a review
from a team
as a code owner
October 28, 2026 11:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Invoke-Formatter -Rangecould silently drop later corrections when earlier edits moved them beyond the original range end. Shortening a selected line could also leave invalid range coordinates.Produces:
Invoke-Formatter -Rangesilently drops corrections after earlier fixes shift text #2211