-
Notifications
You must be signed in to change notification settings - Fork 1
Add Doc.align that aligns subsequent line breaks to the current line position
#155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #155 +/- ##
============================================
- Coverage 94.18% 93.98% -0.20%
- Complexity 283 286 +3
============================================
Files 12 12
Lines 946 965 +19
Branches 171 173 +2
============================================
+ Hits 891 907 +16
- Misses 44 47 +3
Partials 11 11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ignment and add tests that exercise the interaction between indentation, grouping and alignment
| * | ||
| * Sets the indentation for line breaks within its inner {@link Doc} at the current line position. | ||
| */ | ||
| public static class Align extends Doc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may also be worth adding an absolute Position variant of Align that takes a user-provided position argument to be applied after line breaks
| return align(this); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit wary of adding too much stuff to this library, but it's possible to get "hanging" style indent by adding a variant of bracket with the following implementation:
return group(align(
left
.append(align(lineDoc.append(this).indent(indent).margin(marginDoc)))
.append(lineDoc.append(right))));| void testBracketFlatteningWithAlign() { | ||
| // Note: the arguments are aligned with the "functionCall" element because bracket doesn't support alignment. | ||
| // TODO: Consider adding a `hangingBracket` combinator that aligns the bracket docs with the starting line position | ||
| // and the arguments with the opening bracket doc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hangingBracket refers to the variant of bracket I describe above
Doc.align that aligns subsequent line breaks to the current line position
| } else if (entryDoc instanceof LineOr) { | ||
| // Reset line length | ||
| position = entryIndent; | ||
| position = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is based on this observation that sending out the indent text below already manipulates the position to add the entryIndent.
I missed this while implementing Margin.
|
Hey @DavidGregory084 when you have a moment, can you please release a new library version? Thanks! And thanks for fixing this so quickly :) |
Fixes #154.
This adds a combinator for
Docthat indents text within the doc to the line position at the start of theDoc: