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

Avoid squeezing reaction, method, or preamble bodies onto a single line #1984

Merged
merged 8 commits into from Sep 3, 2023

Conversation

petervdonovan
Copy link
Collaborator

@petervdonovan petervdonovan commented Sep 1, 2023

Fixes #1975.

This is in response to readability issues. Additionally, I personally find that when statements are put on one line, that makes refactoring more cumbersome because one must add newlines before adding additional statements to a reaction.

An example of a project that made a similar decision to this is rustfmt, which never seems to put if statements all on one line.

This change has a code smell -- it does matching on raw strings without parsing them. Also it only has effects in the case where the target language has semicolons, which may or may not be what we want. I am thinking about changing the implementation of this to be based on whether the code is a reaction body instead of whether it has a semicolon. This is now resolved.

Since this change is late, we do not need to squeeze it into the 0.5.0 release. However, it might behoove us to release it soon, e.g. in 0.5.1, because the changes to the appearance of LF code could be highly disruptive; ideally users could transition straight from the 0.4.0 format to the 0.5.1 format without bothering with the 0.5.0 format in between.

@petervdonovan petervdonovan added enhancement Enhancement of existing feature formatter labels Sep 1, 2023
Copy link
Collaborator

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

I think this change is a good one, but it doesn't solve the problem for TypeScript, since semicolons are optional. Would it be possible for the formatter to simply accept whatever the user chooses in this regard? I still think we should reformat all our examples and tests to not inline single-line reactions, however. I've been doing that manually for all the examples in the Handbook (please do not run the formatter on them!!).

@petervdonovan petervdonovan changed the title Avoid putting ";" on same line as "=}" in formatter Avoid squeezing reaction bodies onto a single line Sep 2, 2023
@petervdonovan petervdonovan marked this pull request as ready for review September 2, 2023 04:04
@petervdonovan
Copy link
Collaborator Author

I undid the changes that I had originally implemented and changed to a completely different implementation that I think is less kludgy. I think this PR is ready now.

@petervdonovan petervdonovan marked this pull request as draft September 2, 2023 18:57
@petervdonovan petervdonovan marked this pull request as ready for review September 2, 2023 19:11
@petervdonovan petervdonovan changed the title Avoid squeezing reaction bodies onto a single line Avoid squeezing reaction, method, and preamble bodies onto a single line Sep 2, 2023
@petervdonovan petervdonovan changed the title Avoid squeezing reaction, method, and preamble bodies onto a single line Avoid squeezing reaction, method, or preamble bodies onto a single line Sep 2, 2023
@petervdonovan petervdonovan force-pushed the update-formatter branch 2 times, most recently from 4bfcbb3 to 3baaf1d Compare September 3, 2023 07:38
Copy link
Collaborator

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

LGTM. This should definitely be merged soon given the number of files changed.

@petervdonovan petervdonovan force-pushed the update-formatter branch 3 times, most recently from c3846f0 to d920e24 Compare September 3, 2023 17:50
This adds state, but it is a private non-static member and the formatter
is not parallelized, so it should be OK. The technique employed here is
I think the most reasonable way to account for context-sensitive
formatting rules.
The comment about thread-safety in the previous commit message was
incorrect because I forget that we were using the singleton pattern on
ToLf. To my knowledge there was no good reason for us to do that.
This preamble was not even appearing in the generated code, which causes
LSP test to fail.
Reactions, preambles, and methods typically consist of multiple
statements appearing on distinct lines, and if they consist of only a
single statement, they commonly evolve into multiple statements.
Therefore these three constructs should all use multiline code blocks.
@petervdonovan petervdonovan added this pull request to the merge queue Sep 3, 2023
Merged via the queue into master with commit ff64ce4 Sep 3, 2023
41 checks passed
@petervdonovan petervdonovan deleted the update-formatter branch September 3, 2023 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of existing feature formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Single line reactions should not be inlined
2 participants