Skip to content

Conversation

@kabugatti
Copy link

📝 Fix multi-line %define formatter alignment and loop issue

🛠️ Issue

📖 Description

  • Rewrite the format_buffer_inplace function in src/fmt.rs to correctly handle multi-line preprocessor directives (%define ... \).
  • Ensure only true multi-line directives (lines that start with % and end with \) are processed, preventing an infinite loop on single-line directives.
  • Improve trimming and spacing logic to align backslashes at column 88 without corrupting content.
  • Rebuild the buffer after processing to maintain integrity and avoid in-place index errors.

✅ Changes made

  • Updated the main loop to only enter the formatting block when line.starts_with(b"%") && line.ends_with(b"\\").
  • Added logic to collect all consecutive continuation lines into a directive_lines vector, then trim trailing spaces and insert the correct number of spaces before each backslash.
  • Ensured the index i advances past the entire directive block, preventing infinite loops and hangs.
  • Rebuilt the entire src buffer at the end by concatenating modified lines, ensuring safe byte-level operations.
  • Retained existing error handling (FmtError) and file read/write patterns.

📜 Additional Notes

  • Manual and automated tests were run against tests/formatter and existing test suites to confirm no regressions.
  • The formatter now exits cleanly and aligns backslashes correctly for all tested cases.
  • Future improvements could include extending formatting support beyond preprocessor directives and integrating more Goboscript style rules.

@kabugatti kabugatti changed the title chore: fix file formatter chore: fix goboscript file formatter Aug 1, 2025
@aspizu
Copy link
Owner

aspizu commented Aug 2, 2025

slop

@aspizu aspizu closed this Aug 2, 2025
@kabugatti kabugatti deleted the formatter branch August 6, 2025 06:48
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.

Fix goboscript files formatter

2 participants