-
Notifications
You must be signed in to change notification settings - Fork 82
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
Preserve comments on language pragmas #216
Comments
This seems to be in a conflict with the idea of automated grouping of language pragmas. |
The pragmas could only be sorted by groups split using comments as delimiters. This is similar to what |
I don't see a good way to implement it. What we currently do is we check every comment to detect those that are language pragmas. Keeping track of comments between pragmas would require more state. Seems to be quite troublesome for little benefit. I'm keeping this one with low priority. |
There are semantic problems with this approach. Some language extensions enable other language extensions implicitly. If you want to disable them, you must specify that after the extension that implicitly enables them is specified. Consider this input:
This module will not have If the styler groups the language extensions and alphabetizes them like so, there will be problems:
Because This grouping and alphabetizing of language extensions will cause semantic differences in the input and output modules. The former does not have |
In light of this, perhaps we should reorder only inside groups separated by a newline. |
It seems like "don't reorder extensions at all" is safer. Or perhaps we
should put all "NoX" extensions into their own group at the end?
…On Mon, Sep 16, 2019, 11:57 Mathieu Boespflug ***@***.***> wrote:
In light of this, perhaps we should reorder only inside groups separated
by a newline.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#216?email_source=notifications&email_token=AALT42QGMUY7AE452WKHJLDQJ5C6FA5CNFSM4IDR45W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6YQAKA#issuecomment-531693608>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AALT42S4S2ZLVGDSDLJEWM3QJ5C6FANCNFSM4IDR45WQ>
.
|
Though frankly, it's not worth losing the "if it compiled before
formatting, it will still compile after formatting" invariant for such a
minor benefit (sorted pragmas).
…On Mon, Sep 16, 2019, 13:23 Artyom Kazak ***@***.***> wrote:
It seems like "don't reorder extensions at all" is safer. Or perhaps we
should put all "NoX" extensions into their own group at the end?
On Mon, Sep 16, 2019, 11:57 Mathieu Boespflug ***@***.***>
wrote:
> In light of this, perhaps we should reorder only inside groups separated
> by a newline.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#216?email_source=notifications&email_token=AALT42QGMUY7AE452WKHJLDQJ5C6FA5CNFSM4IDR45W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6YQAKA#issuecomment-531693608>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AALT42S4S2ZLVGDSDLJEWM3QJ5C6FANCNFSM4IDR45WQ>
> .
>
|
The problem is that a list of language extensions is not always a list of commutative elements, however it often is a list of commutative elements and users will likely expect the alphabetized behavior in the latter case. If one were to take care to note which language extensions were implied by which other ones, we can determine which elements in the list of language extensions could not be commuted "past" one another when alphabetizing. If this bookkeepping was performed, we could indempotently output a mostly alphabetized list of language extensions when one or more elements cannot commute "past" each other or a completely alphabetized list when all elements can be commuted, preserving the module's semantics in either case. While this approach would require much more work to implement and maintain, it is the most correct option for an opinionated code styler. |
I agree we should not abandon sorting with single group of extensions in the output, we just should make it more clever. |
@recursion-ninja Now there is a separate issue about sorting: #404. I think it's a different problem. |
Just noting that the same goes for
|
* update ormolu version * run new ormolu * don't exclude CPP anymore * format Sodium.Crypt.Sign Changelog: https://github.com/tweag/ormolu/blob/master/CHANGELOG.md Most changes are caused by: * Records with a single data constructor are now formatted more compactly. [Issue 425](tweag/ormolu#425). * Added experimental support for simple CPP. [Issue 415](tweag/ormolu#415). Other notable changes we can start making use of: * Grouping of statements in `do`-blocks is now preserved. [Issue 74](tweag/ormolu#74). * Comments on pragmas are now preserved. [Issue 216](tweag/ormolu#216).
Input:
Output:
This means that I can't document tricky/unpleasant exceptions for other code readers.
The text was updated successfully, but these errors were encountered: