Add AlignObjectKeys and AutoPadSubObjects formatting properties#167
Open
Add AlignObjectKeys and AutoPadSubObjects formatting properties#167
AlignObjectKeys and AutoPadSubObjects formatting properties#167Conversation
AlignObjectKeys: aligns the colon separator for keys within an object,
padding each key to the width of the longest key in the same object.
AutoPadSubObjects: treats sibling ObjectKey values that are inline
objects as rows of a table. Computes the max rendered value-width per
sub-key name across all siblings and pads values so each named column
starts at the same position across all rows. Complex sub-values
(multi-item Objects/Arrays) are excluded from width computation and do
not influence column widths.
Also fixes transposeAndFormat crashing on empty input, and updates
scalarLength to exclude multiline text rather than just { and [
prefixes from column width calculation.
Adds a glowMap section to examples/jbeam/frame.jbeam as a test fixture
demonstrating both properties together, matching the formatting style
seen in real-world jbeam files.
- Update minimal.jbfl with AlignObjectKeys and AutoPadSubObjects rules - Regenerate all affected formatted/transformed jbeam fixtures - Regenerate minimal.jbfl AST
c7d261b to
4d68115
Compare
- Guard maxKeyW computation behind alignObjectKeysEnabled to avoid unconditional work when the feature is off - Remove redundant newKeyWidth/newSubWidths intermediate bindings - Check isComplexNode before calling formatWithCursor in subObjectWidths to short-circuit the expensive recursive format call
In objectParser, comments were parsed with `skipWhiteSpace` which consumed whitespace without updating `lastSeparatorHadBlankLine`. This meant `cHadNewlineBefore` was never set on comments inside objects, so blank lines between consecutive comments were lost during formatting. Fix: use `separatorParser` instead of `skipWhiteSpace` after comments in objectParser, so blank-line state is tracked correctly. Additionally, the formatter was suppressing newlines before comments whenever `any isObjectKeyNode rest` was true, regardless of `cHadNewlineBefore`. This caused blank lines between comments that precede object keys to be dropped. Fix: only suppress the newline when `cHadNewlineBefore` is false, so that blank lines present in the source are preserved. Add a blank line and extra comment in the glowMap section of examples/jbeam/frame.jbeam to cover this case in the test fixtures.
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.
Summary
Two new JBFL formatting properties for aligning object key/value pairs within and across sibling objects.
AlignObjectKeysPads object keys with spaces so the
:separators align vertically across all entries in the same object.AutoPadSubObjectsTreats sibling
ObjectKeyentries whose values are inline objects as table rows. Computes the maximum value width per named sub-key across all siblings and pads so matching sub-key columns align.Designed for
glowMap-style structures where multiple top-level keys map to small inline objects sharing the same sub-keys:Implementation
Formatting/Rules.hs: AddedAlignObjectKeysandAutoPadSubObjectsasPropertyKey Boolconstructors; registered inboolProperties,eqKey, andpropertyName.Parsing/DSL.hs: AddedparseValueForKeycases for both new properties.Formatting.hs:fsObjectKeyWidth :: Maybe IntandfsSubObjectWidths :: Map Text InttoFormattingState.doFormatNode: computes max key width (maxKeyW) and per-sub-key max value widths (subObjectWidths); passes them intoFormattingStatewhen the respective property is enabled.formatWithCursor (ObjectKey): pads the key tofsObjectKeyWidthand forwardsfsSubObjectWidthsinto the value's formatting state.addDelimiters (ObjectKey): applies column padding viaT.justifyLeft (kw + 3 + vw + 1)for non-last entries when the key is found infsSubObjectWidths. Complex (multi-line) sub-object values are excluded from width computation.transposeAndFormatcrash on empty input (V.null vvsguard).scalarLengthto exclude multiline values (changedisPrefixOf "{"|"["toT.any (== '\n')).Example JBFL usage
Files changed
src/JbeamEdit/Formatting.hssrc/JbeamEdit/Formatting/Rules.hssrc/JbeamEdit/Parsing/DSL.hsexamples/jbfl/complex.jbfl: added new rulesexamples/jbfl/minimal.jbfl: updated with new rulesexamples/jbeam/frame.jbeam: added glowMap section as a realistic test fixtureexamples/formatted_jbeam/,examples/transformed_jbeam/,examples/ast/fixtures regenerated