Skip to content

Fix: Prevent line breaks inside for loop headers during formatting - #127

Merged
davhdavh merged 2 commits into
mainfrom
copilot/fix-for-loop-formatting
May 4, 2026
Merged

Fix: Prevent line breaks inside for loop headers during formatting#127
davhdavh merged 2 commits into
mainfrom
copilot/fix-for-loop-formatting

Conversation

Copilot AI commented May 4, 2026

Copy link
Copy Markdown
Contributor

The formatter was splitting for loop headers across multiple lines by treating the ; separators inside the condition parentheses as statement terminators.

Before:

for(i = 0;
i < count;
i++) { }

After:

for (i = 0; i < count; i++) {
}

Changes

  • CgScriptFormatter.csSEMI handler: Skip newline emission when parenDepth > 0. Semicolons inside (...) are always for-header separators, never statement terminators.
  • CgScriptFormatter.csNeedsSpaceBefore: Add prevType == SEMI → true alongside the existing comma rule, so tokens following a suppressed ; still receive a space.

Tests added

  • CgScript foreach-style: for (i for 0; 10) { } → single-line header preserved
  • C-style: for (i = 0; i < count; i++) { } → single-line header preserved
  • Idempotency: re-formatting already-correct output is stable

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.antlr.org
    • Triggering command: /usr/bin/dotnet dotnet test Catglobe.CgScript.EditorSupport.Lsp.Tests/ (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix line breaks in 'for' loop formatting Fix: Prevent line breaks inside for loop headers during formatting May 4, 2026
Copilot AI requested a review from davhdavh May 4, 2026 07:53
@davhdavh
davhdavh marked this pull request as ready for review May 4, 2026 07:55
@davhdavh
davhdavh merged commit 5852c6b into main May 4, 2026
@davhdavh
davhdavh deleted the copilot/fix-for-loop-formatting branch May 4, 2026 07:55
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.32.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formating: Prevent Line Breaks in 'for' Loop Formatting

2 participants