Skip to content

Format .cabal files with cabal-gild #4229

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented May 13, 2024

Compare with #4230

Closes #4228

@fendor fendor force-pushed the enhance/format-with-cabal-gild branch from b3b4bd4 to dff31ba Compare May 13, 2024 09:52
directory,
extra,
filepath,
ghcide ==2.8.0.0,
Copy link
Collaborator

@jhrcek jhrcek May 13, 2024

Choose a reason for hiding this comment

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

One more reason I prefer cabal-gild, is that it doesn't try to preserve version constraint indentation.
This leads to more diff friendly format (adding/removing dependency with longer than longest name, doesn't lead to indentation changes for other version constraints)
e.g.

short >=1.0
longer >= 2.0   < Adding longer dependency re-indents version constraint for shorter, which makes for longer diffs

@soulomoon
Copy link
Collaborator

can cabal-gild have , prefixing line breaking for items?

Copy link

@tfausak tfausak left a comment

Choose a reason for hiding this comment

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

👋 I'm the author/maintainer of Gild. Let me know if I can do anything to help here!

, unordered-containers >=0.2.10.0
, vector
Diff ^>=0.4.0,
Glob,
Copy link

Choose a reason for hiding this comment

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

I chose to make Gild sort things case sensitively, but I'm not set on it. See tfausak/cabal-gild#46.

@fendor fendor force-pushed the enhance/format-with-cabal-gild branch 2 times, most recently from ac4506d to 7bda10f Compare May 15, 2024 07:35
@fendor
Copy link
Collaborator Author

fendor commented May 15, 2024

Reformatted the .cabal files with cabal-gild-1.3.1.0 for accurate comparison.

@fendor fendor marked this pull request as draft June 13, 2024 21:51
@VeryMilkyJoe VeryMilkyJoe force-pushed the enhance/format-with-cabal-gild branch from 5eb7a78 to cefc2d9 Compare June 8, 2025 17:21
@fendor fendor marked this pull request as ready for review June 8, 2025 17:22
@fendor
Copy link
Collaborator Author

fendor commented Jun 8, 2025

@VeryMilkyJoe Thanks for rebasing this, I think we should merge this PR now and see how annoying it is for future contributors.

Formatted with cabal-gild-1.5.0.1

@fendor fendor changed the title Draft: Format .cabal files with cabal-gild Format .cabal files with cabal-gild Jun 8, 2025
@michaelpj
Copy link
Collaborator

Shipit!

Copy link

@tfausak tfausak left a comment

Choose a reason for hiding this comment

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

bug-reports: https://github.com/haskell/haskell-language-server/issues
tested-with: GHC == {9.12.2, 9.10.1, 9.8.4, 9.6.7}
bug-reports: https://github.com/haskell/haskell-language-server/issues
tested-with: ghc ==9.12.2 || ==9.10.1 || ==9.8.4 || ==9.6.7
Copy link

@tfausak tfausak Jun 9, 2025

Choose a reason for hiding this comment

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

Starting with version 1.5.0.3, Gild will correctly leave this in set notation. See tfausak/cabal-gild#118.

Chart,
Chart-diagrams,
aeson,
base >=4 && <5,
Copy link

Choose a reason for hiding this comment

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

Same note here: Starting with version 1.5.0.3, Gild will correctly retain the wildcard version constraint. tfausak/cabal-gild#118

hls-plugin-api ==2.11.0.0,
hls-test-utils ==2.11.0.0,

if flag(isolatecabalfmttests)
Copy link

Choose a reason for hiding this comment

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

Cabal converts flag names to lowercase. Gild does the same in order to make this conversion obvious. However it could retain the case from the input if desired. See #4230 (comment).

Comment on lines +159 to +160
haskell-language-server:hls-cabal-fmt-plugin,
haskell-language-server:hls-cabal-plugin,
Copy link

Choose a reason for hiding this comment

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

Just so you know, these can use set notation:

Suggested change
haskell-language-server:hls-cabal-fmt-plugin,
haskell-language-server:hls-cabal-plugin,
haskell-language-server:{hls-cabal-fmt-plugin, hls-cabal-plugin},

if os(darwin)
ghc-options: -optl-Wl,-ld_classic
if os(osx)
ghc-options: "-optl-Wl,-ld_classic"
Copy link

@tfausak tfausak Jun 9, 2025

Choose a reason for hiding this comment

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

Hmm, I wonder why this got quoted. Maybe because there's a comma in it?

Also note that darwin and osx are aliases. Gild canonicalizes operating systems (and architectures).

, time

hs-source-dirs: plugins/hls-refactor-plugin/src
build-depends:
-- FIXME: Only needed to workaround for qualified imports in GHC 9.4
Copy link

Choose a reason for hiding this comment

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

This comment got floated up to the top of the build-depends, so it doesn't really make sense anymore. I would suggest something like this:

build-depends:
  bytestring,
  ...

-- FIXME: Only needed to workaround for qualified imports in GHC 9.4
build-depends:
  parser-combinators,
  regex-applicative

, semanticTokens
, notes
import:
-- plugins
Copy link

Choose a reason for hiding this comment

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

Same note here about comment placement.

directory,
extra,
filepath,
ghcide,
Copy link

Choose a reason for hiding this comment

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

In this case I don't think it changes the semantics, but starting with version 1.5.0.3, Gild would keep this as ghcide:{ghcide}. See tfausak/cabal-gild#115.

@VeryMilkyJoe VeryMilkyJoe force-pushed the enhance/format-with-cabal-gild branch from cefc2d9 to 2c69e4c Compare June 9, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Format all .cabal files in the repo with a cabal formatter
6 participants