Add --preserve-lambda-breaks option#614
Open
ZacSweers wants to merge 10 commits intofacebook:mainfrom
Open
Conversation
Add new boolean configuration option to FormattingOptions and wire it through the command-line interface. This option will enable cascading lambda break decisions to nested trailing lambdas, useful for DSLs like Jetpack Compose. Changes: - Add cascadeNestedLambdaBreaks field to FormattingOptions data class - Add --cascade-nested-lambda-breaks command-line flag to ParsedArgs - Update CLI help text to document the new option - Default value is false to maintain backward compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add parentLambdaBroke parameter to track parent lambda break state through nested lambda expressions. Add helper method to identify trailing lambdas that should inherit hierarchy preservation. Changes: - Add parentLambdaBroke parameter to visitLambdaExpressionInternal - Add isTrailingLambda helper method to detect trailing lambdas - Update method documentation to explain new parameter - All call sites use default value (false) for now No functional changes yet - context is passed but not used. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implement the core cascading lambda break functionality. When cascadeNestedLambdaBreaks is enabled and a parent lambda breaks to multi-line, all nested trailing lambdas are forced to break as well, preserving visual hierarchy. Changes: - Add insideBreakingLambda member variable to track break state - Detect when current lambda will break to multi-line - Force nested trailing lambdas to multi-line when parent broke - Propagate break state through nested lambda visitor calls - Update visitArgumentInternal and visitLambdaOrScopingFunction The feature is now functional when --cascade-nested-lambda-breaks flag is enabled. Backward compatible - default behavior unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add 7 comprehensive test cases covering various scenarios for the cascadeNestedLambdaBreaks feature. Tests verify basic hierarchy preservation, backward compatibility, deep nesting, edge cases, and that only trailing lambdas are affected. Changes: - Add test for forcing nested lambda hierarchy when option enabled - Add test for maintaining single line when option disabled - Add test for forcing only trailing lambdas (not map/filter) - Add test for forcing behavior when parent breaks - Add test for preserving hierarchy with multiple statements - Add test for handling deep nesting levels - Add test for no effect on non-nested lambdas - Fix containsTrailingLambdas to correctly detect nested lambdas - Update break detection logic to handle hierarchy properly All tests pass, feature fully functional. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Document the new --cascade-nested-lambda-breaks command-line option in the README with examples and usage guidelines. The documentation explains how the feature helps preserve visual hierarchy in DSL code like Jetpack Compose. Changes: - Add "Cascading Lambda Breaks" section to README.md - Include usage examples showing before/after formatting - Clarify that option only affects trailing lambdas - Note that it's useful for DSLs with semantic nesting Feature is now fully implemented, tested, and documented. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
The CI failure looks like a bootstrap compatibility issue - can't add a new param without breaking ktfmt-gradle since it's statically compiled against the only one? I tried adding |
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.
This is a continuation of #574 with the updated option control to orient around the requested
--preserve-lambda-breakssimple option. With this, lambda block line breaks are simply just respected rather than have ktfmt impose anything.Aside from finishing up the previous PR, this also adds a setting to the IJ plugin.
I cherrypicked the original commits to preserve authorship history (CC @loganj)
Resolves #547