vyorkin / ormolu.el

A formatter for Haskell source code
36 stars 10 forks source link

Ask ghc/cabal for --ghc-opts #8

Closed fisx closed 3 years ago

fisx commented 4 years ago

Issue description (and possibly discussion) here: https://github.com/tweag/ormolu/issues/517, but perhaps there is some simple work-around for this in the emacs mode.

This is currently my work-around:

(add-hook 'haskell-mode-hook
          '(lambda nil
             (ormolu-format-on-save-mode t)
             (set (make-local-variable 'ormolu-extra-args)
                  '("--ghc-opt" "-XAllowAmbiguousTypes"
                    "--ghc-opt" "-XBangPatterns"
                    "--ghc-opt" "-XConstraintKinds"
                    "--ghc-opt" "-XDataKinds"
                    "--ghc-opt" "-XDefaultSignatures"
                    "--ghc-opt" "-XDerivingStrategies"
                    "--ghc-opt" "-XDeriveFunctor"
                    "--ghc-opt" "-XDeriveGeneric"
                    "--ghc-opt" "-XDeriveLift"
                    "--ghc-opt" "-XDeriveTraversable"
                    "--ghc-opt" "-XEmptyCase"
                    "--ghc-opt" "-XFlexibleContexts"
                    "--ghc-opt" "-XFlexibleInstances"
                    "--ghc-opt" "-XFunctionalDependencies"
                    "--ghc-opt" "-XGADTs"
                    "--ghc-opt" "-XInstanceSigs"
                    "--ghc-opt" "-XKindSignatures"
                    "--ghc-opt" "-XLambdaCase"
                    "--ghc-opt" "-XMultiParamTypeClasses"
                    "--ghc-opt" "-XMultiWayIf"
                    "--ghc-opt" "-XNamedFieldPuns"
                    "--ghc-opt" "-XNoImplicitPrelude"
                    "--ghc-opt" "-XOverloadedStrings"
                    "--ghc-opt" "-XPackageImports"
                    "--ghc-opt" "-XPatternSynonyms"
                    "--ghc-opt" "-XPolyKinds"
                    "--ghc-opt" "-XQuasiQuotes"
                    "--ghc-opt" "-XRankNTypes"
                    "--ghc-opt" "-XScopedTypeVariables"
                    "--ghc-opt" "-XStandaloneDeriving"
                    "--ghc-opt" "-XTemplateHaskell"
                    "--ghc-opt" "-XTupleSections"
                    "--ghc-opt" "-XTypeApplications"
                    "--ghc-opt" "-XTypeFamilies"
                    "--ghc-opt" "-XTypeFamilyDependencies"
                    "--ghc-opt" "-XTypeOperators"
                    "--ghc-opt" "-XUndecidableInstances"
                    "--ghc-opt" "-XViewPatterns"))
             ))
vyorkin commented 3 years ago

I'm a bit late, but:

Many cabal and stack projects use default-extensions to enable GHC language extensions in all source files. With the --cabal-default-extensions flag, Ormolu will take them into consideration during formatting.

https://github.com/tweag/ormolu#account-for-cabal-files https://github.com/tweag/ormolu/pull/759 https://github.com/vyorkin/ormolu.el/pull/14

fisx commented 3 years ago

hehe, i completely forgot about this issue, but --cabal-default-extensions looks like my answer. i'll try that out soon, thanks!