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

Strange formatting of long show-set rule #143

Closed
Andrew15-5 opened this issue Oct 19, 2024 · 5 comments · Fixed by #173
Closed

Strange formatting of long show-set rule #143

Andrew15-5 opened this issue Oct 19, 2024 · 5 comments · Fixed by #173

Comments

@Andrew15-5
Copy link

#show heading.where(level: 2): set heading(numbering: (..n) => [#n.pos().at(1).])

with typstyle -c 80:

#show heading.where(level: 2): set heading(numbering: (
  ..n,
) => [#n.pos().at(1).])

I think it's much more readable to prefer first breaking by 1 parameter per line:

#show heading.where(level: 2): set heading(
  numbering: (..n) => [#n.pos().at(1).],
)
@Enter-tainer
Copy link
Owner

I'm not entirely sure what's happending but it looks like this falls into a special handling for single parameter function call. I will look into it later.

@QuadnucYard
Copy link
Collaborator

In the current implementation, as long as the call/set has exactly one arg which is not func-call, we will force that arg to stick with the paren. Without this rule, the code will be formatted as you suggested.
Maybe we can decide this behavior based on context, e.g., in show-rule, the arg is complex enough, etc.
Anyway, it's tough to strike a balance between simple cases (the arg is just one literal or ident) and complex cases (as put here).

@Andrew15-5
Copy link
Author

Andrew15-5 commented Dec 8, 2024

Now it's 7 lines instead of 3. Isn't this too much? It's really unnecessary stretched, considering that there is a lot of room on the right. Which line limit is used for tests?

https://github.com/QuadnucYard/typstyle/blob/58791a2f22a376dc4363bd9d55bf38bd455ce324/tests/snapshots/assets__check_file%40unit-show-show-set.typ-0.snap

@Enter-tainer
Copy link
Owner

Enter-tainer commented Dec 8, 2024

Now it's 7 lines instead of 3. Isn't this too much? It's really unnecessary stretched, considering that there is a lot of room on the right. Which line limit is used for tests?

https://github.com/QuadnucYard/typstyle/blob/58791a2f22a376dc4363bd9d55bf38bd455ce324/tests/snapshots/assets__check_file%40unit-show-show-set.typ-0.snap

you are seeing the 0 width snapshot. typstyle will break at every possible position in case. this is only for debugging. for real world use case, please see -80 and -120 snapshots.

@Andrew15-5
Copy link
Author

Oh, I didn't notice that there are multiple tests for the same thing. All good.

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 a pull request may close this issue.

3 participants