feat: compact layout for args of func_call#261
Merged
QuadnucYard merged 12 commits intotypstyle-rs:masterfrom Apr 30, 2025
Merged
feat: compact layout for args of func_call#261QuadnucYard merged 12 commits intotypstyle-rs:masterfrom
QuadnucYard merged 12 commits intotypstyle-rs:masterfrom
Conversation
📊 Benchmark Performance Reportgroup base pr
----- ---- --
pretty-cetz-manual 1.00 843.9±7.54µs ? ?/sec 1.15 969.7±6.32µs ? ?/sec
pretty-codly 1.00 1882.7±21.92µs ? ?/sec 1.10 2.1±0.02ms ? ?/sec
pretty-cpe 1.04 13.6±0.16ms ? ?/sec 1.00 13.1±0.24ms ? ?/sec
pretty-fletcher-diagram 1.00 533.6±8.52µs ? ?/sec 1.09 583.1±8.82µs ? ?/sec
pretty-fletcher-draw 1.00 1283.4±12.58µs ? ?/sec 1.12 1440.3±16.20µs ? ?/sec
pretty-tablex 1.00 3.5±0.02ms ? ?/sec 1.10 3.8±0.02ms ? ?/sec
pretty-touying-core 1.00 2.2±0.02ms ? ?/sec 1.13 2.5±0.01ms ? ?/sec
pretty-touying-utils 1.00 1258.7±12.32µs ? ?/sec 1.10 1385.0±21.11µs ? ?/sec
pretty-undergraduate-math 1.00 993.0±16.31µs ? ?/sec 1.03 1025.5±21.78µs ? ?/secGenerated by GitHub Actions on Wed Apr 30 12:57:29 UTC 2025 |
Collaborator
Author
|
problems with compact layout:
|
QuadnucYard
commented
Apr 26, 2025
7ff683e to
f91fee5
Compare
Collaborator
Author
|
there are some weird behaviors with pretty, causing compact layout unexpectedly fail to fit #{
{
{
cetz.group(
{
{
cetz.draw.set-style(
fill: if i == 0 { node.fill },
stroke: if i == 0 { node.fill },
)
}
},
)
}
}
}modifying almost any piece of code can make the compact layout of |
Collaborator
Author
|
Maybe we can hold on to sticky braces to bypass such problems. |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new "Compact" fold style and adjusts the layout for function call arguments to use a compact layout under specific conditions.
- Added Compact variant to FoldStyle in style.rs.
- Updated list and chain layout logic to support the compact layout.
- Revised function call argument processing and introduced new helper traits in doc_ext.rs, as well as a new args_width method in config.rs.
Reviewed Changes
Copilot reviewed 156 out of 170 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/typstyle-core/src/pretty/style.rs | Added the new Compact variant to FoldStyle. |
| crates/typstyle-core/src/pretty/layout/list.rs | Introduced a compact layout branch for list items with conditional grouping and union logic. |
| crates/typstyle-core/src/pretty/layout/chain.rs | Simplified grouping logic for chain layouts. |
| crates/typstyle-core/src/pretty/func_call.rs | Updated fold style selection logic for function call arguments based on expression types. |
| crates/typstyle-core/src/pretty/doc_ext.rs | Added new arena flattening extension traits for document builders. |
| crates/typstyle-core/src/config.rs | Added a new args_width method to compute argument width with a fixed ratio. |
Files not reviewed (14)
- tests/fixtures/articles/snap/book.typ-0.snap: Language not supported
- tests/fixtures/articles/snap/book.typ-40.snap: Language not supported
- tests/fixtures/articles/snap/undergraduate-math.typ-0.snap: Language not supported
- tests/fixtures/articles/snap/undergraduate-math.typ-120.snap: Language not supported
- tests/fixtures/articles/snap/undergraduate-math.typ-40.snap: Language not supported
- tests/fixtures/articles/snap/undergraduate-math.typ-80.snap: Language not supported
- tests/fixtures/packages/snap/cetz-manual.typ-0.snap: Language not supported
- tests/fixtures/packages/snap/cetz-manual.typ-120.snap: Language not supported
- tests/fixtures/packages/snap/cetz-manual.typ-40.snap: Language not supported
- tests/fixtures/packages/snap/cetz-manual.typ-80.snap: Language not supported
- tests/fixtures/packages/snap/cetz-tree.typ-0.snap: Language not supported
- tests/fixtures/packages/snap/cetz-tree.typ-120.snap: Language not supported
- tests/fixtures/packages/snap/cetz-tree.typ-40.snap: Language not supported
- tests/fixtures/packages/snap/cetz-tree.typ-80.snap: Language not supported
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.
Resolves #95.
Compact layout is preferred when the args does not contain comments or linebreaks, and the last arg is not binary expression.
Now the flavor of args is ignored. Otherwise, the compact layout will not apply to existing multiline args.
Added a width limit for the initial args except the last, which is a hardcoded 80% width.This does not work well with inline chainsSome problems:
unionand a brute-forceflatten, which are not performant.