Skip to content
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

feat: format most commented elements #161

Merged
merged 9 commits into from
Nov 29, 2024

Conversation

QuadnucYard
Copy link
Contributor

@QuadnucYard QuadnucYard commented Nov 27, 2024

This PR makes the most elements formattable. The only untouched expressions are Parenthesized, FieldAccess, and FuncCall, which have special treatment. Other elements are all marked formattable if not in math. No style change.
Fixes a bug with destructuring introduced in #154. Destruct and params with line comments should not fold into one line.

We treat elements focused on in this PR as flow of items. They are joined by spaces (can be optional) or blocks, and no line break is allowed within.

We use a trick. When formatting these elements, we need not care about the syntax, but simply consider their types and make corresponding countermeasures. In some cases where Expr and Pattern coexist, we need to record the order.

The implementations are subject to change for simplicity and expressiveness.

@QuadnucYard QuadnucYard force-pushed the format-comments-3 branch 3 times, most recently from ec0c60a to cf5b2af Compare November 28, 2024 12:33
@QuadnucYard QuadnucYard marked this pull request as ready for review November 28, 2024 12:37
Copy link
Owner

@Enter-tainer Enter-tainer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. The idea of flow is fantastic.

Could you please also edit the changelog and the limitation doc to reflect latest changes? For example, https://enter-tainer.github.io/typstyle/limitations/#when-there-are-block-comment-child-gives-up-formatting-the-whole-node is no longer valid

src/pretty/flow_like.rs Outdated Show resolved Hide resolved
src/pretty/flow_like.rs Outdated Show resolved Hide resolved
src/pretty/flow_like.rs Outdated Show resolved Hide resolved
src/pretty/flow_like.rs Outdated Show resolved Hide resolved
src/pretty/flow_like.rs Outdated Show resolved Hide resolved
src/pretty/flow_like.rs Outdated Show resolved Hide resolved
src/pretty/func_call.rs Outdated Show resolved Hide resolved
src/pretty/list.rs Outdated Show resolved Hide resolved
@Enter-tainer Enter-tainer merged commit 7ab4277 into Enter-tainer:master Nov 29, 2024
11 checks passed
@Enter-tainer
Copy link
Owner

Thanks!

@QuadnucYard QuadnucYard deleted the format-comments-3 branch November 29, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants