Skip to content

fix(format): keep function spacing around characters and metadata - #969

Merged
LunaStev merged 3 commits into
wavefnd:masterfrom
hiyouwhatsapp:fix/888-891-rust-function-spacing
Oct 25, 2026
Merged

LunaStev merged 3 commits into
wavefnd:masterfrom
hiyouwhatsapp:fix/888-891-rust-function-spacing

Conversation

@hiyouwhatsapp

Copy link
Copy Markdown
Contributor

Fixes #888
Fixes #891

After a literal like 'a', the helper could treat the closing quote as the start of another character and miss the next function. It now checks for that closing quote before deciding that a name is a lifetime

The other part was the gap before a function. Attributes, docs and attached comments now stay with that function, with the blank line inserted before them. Unrelated items and comments already separated from the function keep their place

Added cases for escaped and byte characters, Unicode, lifetimes and loop labels, multiline attributes and comments, and methods inside an impl. The tests also check that formatting twice gives the same result

Testing: PYTHONUTF8=1 python -m unittest tools.test_case_manifest tools.test_test_contracts tools.test_process_tree tools.test_format_rust passes on Windows with Python 3.13 — 60 tests run, 58 passed and 2 POSIX-only tests skipped. Earlier runs of the unchanged process-tree tests had timing failures under the concurrent test workload; the isolated run and final combined run pass

Also checked all 220 tracked Rust files: formatting is idempotent and every nonblank line is preserved. The updated helper finds spacing gaps in 17 files; I haven't included a repository-wide reformat here. git diff --check passes. Full Rust workspace and Wave language corpus checks weren't run for this Python tooling change

Commits include the DCO sign-off

@LunaStev

Copy link
Copy Markdown
Member

Thanks for the fixes! The changes address both issues, and the added regression tests provide good coverage.

Before merging, could you please check two additional edge cases?

  1. Multiline block comments in attached_item_start(): Please verify that ordinary multiline block comments immediately preceding a function are correctly treated as attached comments. The current lexical scanning logic may return function_start instead of inserting a blank line before the comment.

  2. Unicode lifetime identifiers in strip_lexical_content(): Python's isidentifier() does not exactly match Rust's identifier rules. Please verify that multi-character Unicode lifetime identifiers and combining characters are handled correctly, and add regression tests where appropriate.

Please also ensure that these cases preserve formatting idempotency.

Once these are addressed and the tests pass, this should be ready to merge. Thanks!

Copy link
Copy Markdown
Contributor Author

Apologies for the hiatus, fixed

@LunaStev
LunaStev merged commit 0c80ebd into wavefnd:master Oct 25, 2026
50 checks passed
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.

Separate Rust functions before their attributes and documentation Distinguish Rust character literals from lifetimes in the spacing helper

2 participants