Indent catch arm bodies relative to enclosing blocks#3710
Draft
ATX24 wants to merge 2 commits into
Draft
Conversation
Co-authored-by: Dhilan Shah <[email protected]>
Co-authored-by: Dhilan Shah <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
|
No description provided. |
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.
Pull Request Template
Thanks for taking the time to fill out this pull request!
Issue Reference
Please link to any related issues
The error
Running
baml fmton a catch expression in a function body preserved raw catch-body indentation after the first line, producing mixed 4-space/2-space layout:Incorrect formatted output before this change:
The formatter exited successfully, so this was a formatter layout bug rather than a parse/type error.
Root cause
CATCH_EXPRwas not handled by the strong formatter AST inbaml_language/crates/baml_fmt/src/ast/expressions.rs.Expression::from_cstfell through toExpression::Unknown(TextRange), whose printer usesprint_input_range_trimmed_start: it strips only the first line's leading whitespace and then emits continuation lines at their original absolute indentation. That raw fallback made catch arms keep whatever source indentation they had instead of being indented from the enclosing block'sShape.The fix
Expression::CatchplusCatchExpr,CatchClause,CatchArm, andCatchKeywordformatter nodes inbaml_language/crates/baml_fmt/src/ast/expressions.rs.catchandcatch_allinbaml_language/crates/baml_fmt/src/ast/tokens.rs.shape.indent + indent_width, and the catch closing brace uses the enclosingshape.indent.catch_allindentation inbaml_language/crates/baml_fmt/src/lib.rs.catch_return_type_mismatch.Verification
Focused formatter tests:
Full formatter crate:
Existing catch formatter snapshots:
Workspace library tests for crates that support plain
cargo test --lib:bridge_nodejsdocuments in itsCargo.tomlthat standalone Rust test binaries cannot link N-API symbols; the TypeScript SDK crate documents that plaincargo testskips its setup and must be run with nextest. I ran that documented suite separately:CLI reproduction after the fix:
Formatted output now succeeds with catch arms indented relative to the enclosing function body:
Changes
Please describe the changes proposed in this pull request
See The fix above.
Testing
Please describe how you tested these changes
Screenshots
If applicable, add screenshots to help explain your changes
N/A
PR Checklist
Please ensure you've completed these items
Additional Notes
Environment setup performed during verification: installed
python3.12-devsobridge_pythontests could linklibpython3.12; installed/trusted mise and installeduv/cargo-nextestfor the SDK test suites.