-
Notifications
You must be signed in to change notification settings - Fork 696
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
cabal format
inlines and removes common
stanzas
#5734
Comments
This is by design. Parser produces a Asking to preserve common stanzas is in the same spirit as asking GHC to be able to pretty-print Core into surface Haskell language (analogy: type class instances, there are no such things in Core). That said, having more intermediate structures would be reasonable; so e.g. |
I label this as wontfix. Please don't be discouraged, If someone have time and willingness to pursuit this task, be my guest. But I don't feel this is important enough to have any priority. |
Thanks for the info. I feel like this behaviour living under the command |
So what should we do, any suggestions? |
My 2cents:
The idea would be that this could start out as something not very fancy, just enforce things like:
This could even start as a project outside of |
I think we do need to fix this, otherwise Why would anybody want to reformat their files if it messes up common stanzas and deletes comments? I mention in one of the above tickets the ghc-exactprint approach and "reprinting". For comments, we don't need to mess with the existing nice parser. We just need to augment it with a "reprinter" in some fashion. For common stanzas, I think its fair enough to toss in just enough intermediate structure in the parsed output to not "merge" them in the same pass, but preserve them at first, and then collapse them down before feeding them to Solver and friends. As such, I'd like to remove the |
I'd personally remove |
Without going all the way to exactprint, I think just resolving the inlined stanzas should be a minor refactor without big performance implications. I have a few (well more than a few) other things on my plate, but at some point I could maybe take a look. |
FWIW |
I have some more time to look at this now, I think in general we should separate the parsing of the cabal file to some "source representation", and then perform the common stanza inlining in a separate transformation from the "source representation" to I have a very much WIP change that I'll make a PR tomorrow to get feedback on. Specifically I really have no idea what the difference between
I think all of these are reasonable things to do to put the spec into some normal form. The things that should be preserved are a) common stanzas, b) comments (although at lower priority imo). Would appreciate feedback on the PR when it's up. |
I think the won't fix is misleading, as it contains an interesting discussion about the alternatives to actual |
Right and this it related to the hot exact-print challenge. |
This helps, in particular, when developping with ghcid, which otherwise doesn't raise warnings. I've had to deactivate `cabal` format in the formatting script due to the fact that it inlines `common` stanzas, which I'm using to ensure consistent warning settings in every target. See [haskell/cabal#5734](haskell/cabal#5734).
Overview
When running
cabal format
, allcommon
stanzas are inlined into the blocks they're referenced from.Example
Before:
After:
/cc @phadej @hvr
The text was updated successfully, but these errors were encountered: