Enter-tainer / typstyle

Beautiful and reliable typst code formatter
https://enter-tainer.github.io/typstyle
Apache License 2.0
320 stars 10 forks source link

Column option has no effect #75

Closed mweinelt closed 5 months ago

mweinelt commented 5 months ago

Hi, thank you for creating and maintaining typstyle!

I noticed an issue with the --column option on 0.11.22 (from nixpkgs), where it would not enforce the default or any other configured column width. Wondering if my understanding of this option is wrong, or if the option is just broken at this point.

$ cat test.typ
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, 
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et ju
sto duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

$ typstyle --column 80 test.typ
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, 
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et ju
sto duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
typstyle 
Version:             0.11.22
Build Timestamp:     1980-01-01T00:00:00.000000000Z
Build Git Describe:  VERGEN_IDEMPOTENT_OUTPUT
Commit SHA:          VERGEN_IDEMPOTENT_OUTPUT
Commit Date:         None
Commit Branch:       None
Cargo Target Triple: x86_64-unknown-linux-gnu
Enter-tainer commented 5 months ago

one thing to notice is that column width is not a hard limit. and it mostly apply to scripting mode at this moment.

currently typsyle tend to keep content untouched. so the behavior is expected

Dioprz commented 4 months ago

@Enter-tainer Hi! I'm migrating from typstfmt where max_line_length acted as a hard limit, so I'm noticing a difference in how typstyle handles this. Could you clarify what you meant by "it mostly apply to scripting mode at this moment"?

I'd also like to understand the purpose of a soft limit option. Is there a way to configure typstyle to enforce a hard limit like typstfmt did? I'm curious about the reasoning behind this design choice. Thanks!

Enter-tainer commented 4 months ago

can you show relevant code snippets so we can better understand it?

Enter-tainer commented 4 months ago

Is there a way to configure typstyle to enforce a hard limit like typstfmt did?

To clarify this, typstyle only format code. this is one of the main design goals of typstyle:

Code only: We want to format only the code. Contents should be left untouched as much as possible.

I'd also like to understand the purpose of a soft limit option. I'm curious about the reasoning behind this design choice.

reflowing content is very risky and error prone. and this only works for languages that use spaces to seprate words. for other languages, it is not even possible to do reflow.

Since we cannot do it well, i prefer not touch it and leave it as is.

why soft limit: hard limit is impossible to have on corner cases. like you have a variable name of 81 characters. no matter how you format the code, there is always a line exceed the 80 char limit. so typstyle cannot guarantee a hard limit. it can only try its best to meet the soft limit

Enter-tainer commented 4 months ago

reflowing content is very risky and error prone.

see https://github.com/astrale-sharp/typstfmt/issues/164 for example.

Dioprz commented 4 months ago

Hm, yes, everything you say makes a lot of sense to me. I didn't think about the risks involved, but that example is a very strong argument (as well as the reasoning to create soft limits instead of hard limits).

Thanks for your time and the detailed explanation, I really appreciate it.

Wulfheart commented 4 months ago

But it would be nice if there was an option if "normal" text would get broken up after the column limit.

Enter-tainer commented 4 months ago

@Wulfheart tracking in #104