on master help sign in
An option to display “manual” extensions
commite663070623fea40e605f333223a9336e07744936 authorwaddlaw <ingronze@gmail.com> dateWed 10 Jul 2019, 11:56 (7 years ago) parentfd5cee6
2 files changed+34−20
app/Main.hs+9−1 src/Ormolu/Parser.hs+25−19
app/Main.hs+9−1
@@ -11,6 +11,8 @@ import Data.Version (showVersion)
1111import Development.GitRev
1212import Options.Applicative
1313import Ormolu
14+import Ormolu.Parser (manualExts)
15+import Ormolu.Utils (showOutputable)
1416import Paths_ormolu (version)
1517import System.Exit (ExitCode (..), exitWith)
1618import System.IO (hPutStrLn, stderr)
@@ -68,7 +70,7 @@ data Mode
6870 deriving (Eq, Show)
6971
7072optsParserInfo :: ParserInfo Opts
71−optsParserInfo = info (helper <*> ver <*> optsParser) . mconcat $
73+optsParserInfo = info (helper <*> ver <*> exts <*> optsParser) . mconcat $
7274 [ fullDesc
7375 , progDesc ""
7476 , header ""
@@ -89,6 +91,12 @@ optsParserInfo = info (helper <*> ver <*> optsParser) . mconcat $
8991 ]
9092 , "using ghc " ++ VERSION_ghc
9193 ]
94+ exts :: Parser (a -> a)
95+ exts = infoOption displayExts . mconcat $
96+ [ long "manual-exts"
97+ , help "Display extensions that need to be enabled manually"
98+ ]
99+ displayExts = unlines (showOutputable <$> manualExts)
92100
93101optsParser :: Parser Opts
94102optsParser = Opts
src/Ormolu/Parser.hs+25−19
@@ -6,6 +6,7 @@
66
77module Ormolu.Parser
88 ( parseModule
9+ , manualExts
910 )
1011where
1112
@@ -67,6 +68,28 @@ parseModule dynOpts path input' = liftIO $ do
6768 }
6869 return (ws, r)
6970
71+-- | Extensions that are not enabled automatically and should be activated
72+-- by user.
73+
74+manualExts :: [Extension]
75+manualExts =
76+ [ Arrows -- steals proc
77+ , Cpp -- forbidden
78+ , PatternSynonyms -- steals the pattern keyword
79+ , RecursiveDo -- steals the rec keyword
80+ , StaticPointers -- steals static keyword
81+ , TransformListComp -- steals the group keyword
82+ , UnboxedTuples -- breaks (#) lens operator
83+ , MagicHash -- screws {-# these things #-}
84+ , AlternativeLayoutRule
85+ , AlternativeLayoutRuleTransitional
86+ , MonadComprehensions
87+ , UnboxedSums
88+ , TemplateHaskellQuotes -- enables TH subset of quasi-quotes, this
89+ -- apparently interferes with QuasiQuotes in
90+ -- weird ways
91+ ]
92+
7093----------------------------------------------------------------------------
7194-- Helpers (taken from ghc-exactprint)
7295
@@ -161,26 +184,9 @@ getPragma s@(x:xs)
161184-- default for ease of use.
162185
163186setDefaultExts :: DynFlags -> DynFlags
164−setDefaultExts flags = foldl' GHC.xopt_set flags whitelist
187+setDefaultExts flags = foldl' GHC.xopt_set flags autoExts
165188 where
166− whitelist = allExts \\ blacklist
189+ autoExts = allExts \\ manualExts
167190 allExts = [minBound..maxBound]
168− blacklist =
169− [ Arrows -- steals proc
170− , Cpp -- forbidden
171− , PatternSynonyms -- steals the pattern keyword
172− , RecursiveDo -- steals the rec keyword
173− , StaticPointers -- steals static keyword
174− , TransformListComp -- steals the group keyword
175− , UnboxedTuples -- breaks (#) lens operator
176− , MagicHash -- screws {-# these things #-}
177− , AlternativeLayoutRule
178− , AlternativeLayoutRuleTransitional
179− , MonadComprehensions
180− , UnboxedSums
181− , TemplateHaskellQuotes -- enables TH subset of quasi-quotes, this
182− -- apparently interferes with QuasiQuotes in
183− -- weird ways
184− ]
185191
186192deriving instance Bounded Extension