Skip to content

Preserve CR-only line endings when formatting files - #2234

Merged
Christoph Bergmeister (bergmeister) merged 3 commits into
copilot/add-path-parameter-to-invoke-formatterfrom
copilot/fix-code-review-comment-2230
Oct 23, 2026
Merged

Christoph Bergmeister (bergmeister) merged 3 commits into
copilot/add-path-parameter-to-invoke-formatterfrom
copilot/fix-code-review-comment-2230

Conversation

Copilot AI commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

CR-only scripts could fail during indentation inference because parser line numbers were matched against LF-only splits. The formatter also needs to retain CR-only separators throughout edits.

  • Line handling: Split on CRLF, CR, or LF, and use the same splitting for indentation inference.
  • Regression coverage: Add an in-place formatting test that checks CR-only line endings remain unchanged.
$script = "function foo {`r`t`$x=1`r}"
# Invoke-Formatter preserves the CR-only line endings.

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code based on review comment for pull request 2230 Preserve CR-only line endings when formatting files Oct 23, 2026
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

Copilot AI 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.

🟢 Approval recommended

The focused changes consistently handle CR-only lines and include regression coverage, with no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes CR-only line handling so the formatter can infer indentation correctly and preserve those line endings when formatting files.

Changes:

  • Recognizes CRLF, CR, and LF separators through the shared line-splitting helper.
  • Uses that helper for indentation inference.
  • Adds an in-place CR-only regression test and makes the legacy-encoding fixture independent of the test file’s encoding.
File Description
Tests/​Engine/​InvokeFormatter.tests.ps1 Verifies CR-only formatting output and saved contents; updates the legacy-encoding fixture.
Engine/​Extensions.cs Splits text on CRLF, CR, or LF.
Engine/​Commands/​InvokeFormatterCommand.cs Uses shared line splitting for indentation inference.

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) removed this pull request from stack #2235 October 23, 2026 17:45
@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 23, 2026 17:45
@bergmeister
Christoph Bergmeister (bergmeister) merged commit ae4cac8 into copilot/add-path-parameter-to-invoke-formatter Oct 23, 2026
8 checks passed
@bergmeister
Christoph Bergmeister (bergmeister) deleted the copilot/fix-code-review-comment-2230 branch October 23, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants