-
Notifications
You must be signed in to change notification settings - Fork 5
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
Comments inside ghc-options
are not preserved properly
#70
Comments
Similar to #63 (comment), you can work around this problem by defining ghc-options:
-threaded
-Wno-unticked-promoted-constructors
-- allow user RTS overrides
ghc-options: -rtsopts
-- disable idle GC
-- increase nursery size
-- Enable collection of heap statistics
ghc-options: "-with-rtsopts=-I0 -A128M -T" However unlike #63, it should (in theory) be possible for Gild to leave the comments in the same relative place. It doesn't re-order the options, and a comment can't exist in the middle of an option. I say "in theory" because the entire value of the
|
Actually I think this is not a bug. Instead I think that keeping comments as close as possible to their original position is a feature request. Gild tries hard not to lose comments, but in general it's challenging to avoid moving them. Field values get parsed and re-rendered, which is generally what you want. For example, it's what allows Gild to parse GHC options so that both This issue is about build-depends:
lib-a,
lib-b
-- major version 1
^>= 1.2.3
-- major version 4
|| ^>= 4.5.6 I'm not sure exactly what the algorithm would look like, but Gild could collect all the comments up to the nearest "item" when formatting and end up with something like this: build-depends:
lib-a,
-- major version 1
-- major version 4
lib-b ^>=1.2.3 || ^>=4.5.6 It would also have to re-indent comments, but it does that already. It's unclear to me how much this veers into the territory of haskell/cabal#7544. |
Hmm. So perhaps I was misled by the fact that it seems that |
Hmm I'm not sure what you mean about Gild should only move comments that are inside field values that it knows how to parse. Those are listed here:
Anything else should get passed through more or less unchanged, although Gild will re-indent and strip trailing blank spaces. |
I commented on the HLS diff where it happens: https://github.com/haskell/haskell-language-server/pull/4229/files#r1600078367
I see, that's exactly what happens. To a naive user "re-indent and fix whitespace" looks a lot like "reformat", so I wouldn't have realised that was different! |
Ah right, that is confusing. Thanks for the example! To reproduce it inline: import:
foo
, bar
-- baz
, qux Gild will not reformat that. This is confusing because if you replace I'm honestly not sure if this is a bug or a feature request 😆 Gild could try to be more consistent by always floating comments to the top. Or it could try to be smarter by keeping comments close(r) to where they came from. |
Yeah. I'm not really sure what the best thing is here either. If anything, I slightly lean towards making the comment-floating consistent so that if you do add support for a new field like |
I agree. I think the correct behavior here is to always float comments to the top of field values. That way users don't have to know/care about which fields Gild actually parses. In the future if Gild wants to try to keep comments close(r) to where they were originally, that can be a separate enhancement. |
There are two places that will need to change. First is the place where there's no parser for the field:
Currently it passes the field through unchanged. It will need to float all comments up instead. The second place is when there is a parser for the field, but parsing the field failed:
It needs to do the same thing: keep the field contents the same, but float the comments up to the top. The comment floating logic is here:
|
Sometimes you want to document why you're setting them. At the moment this:
gets turned into this:
The text was updated successfully, but these errors were encountered: