packages feed

ormolu 0.3.0.0 → 0.3.0.1

raw patch · 32 files changed

+139/−30 lines, 32 filesdep +temporaryPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: temporary

API changes (from Hackage documentation)

- Ormolu.Processing.Preprocess: preprocess :: RegionDeltas -> String -> [Either Text RegionDeltas]
+ Ormolu.Processing.Preprocess: preprocess :: Bool -> RegionDeltas -> String -> [Either Text RegionDeltas]

Files

CHANGELOG.md view
@@ -1,3 +1,21 @@+## Ormolu 0.3.0.1++* Improvements to `.cabal` file handling:+   * When looking for a `.cabal` file, directories were previously+     erroneously also considered. [Issue 781](+     https://github.com/tweag/ormolu/issues/781).+   * We now print a note if Ormolu was told to consider+     `.cabal` files, but no suitable one could be found.+   * Handle an empty `hs-source-dirs` correctly.+   * Also consider modules which are only conditionally listed+     in the `.cabal` file.++* The special handling of CPP is now only applied if CPP is+  actually enabled. [Issue 782](https://github.com/tweag/ormolu/issues/782).++* The left hand side of the `:` operator now uses braces if+  necessary. [Issue 780](https://github.com/tweag/ormolu/issues/780).+ ## Ormolu 0.3.0.0  * Data declarations with multiline kind signatures are now formatted@@ -29,9 +47,12 @@      673](https://github.com/tweag/ormolu/issues/673).    * Strings like `-}` can now be present in disabled regions.      [Issue 708](https://github.com/tweag/ormolu/issues/708).-   * As a side effect, using the magic comments like in-     [Issue 601](https://github.com/tweag/ormolu/issues/601)-     is no longer supported.++  This means that using CPP or magic comments in certain ways which+  were only supported as a side effect previously (like in+  [Issue 601](https://github.com/tweag/ormolu/issues/601))+  will now result in formatting failures. Also see [Issue 774](+  https://github.com/tweag/ormolu/issues/774).  ## Ormolu 0.2.0.0 
README.md view
@@ -51,17 +51,9 @@ cache][iohk-hydra-binary-cache], otherwise building may take a very long time. -Alternatively, `stack` could be used with a `stack.yaml` file as follows:+Alternatively, `stack` could be used as follows:  ```console-$ cat stack.yaml-resolver: lts-18.6-packages:-- '.'-extra-deps:-- Cabal-3.4.0.0-- ghc-lib-parser-9.0.1.20210324- $ stack build # to build $ stack install # to install ```
data/examples/declaration/splice/quasiquote-out.hs view
@@ -10,3 +10,7 @@ [d|    foo bar  |]++header =+  [here|+#include foo|]
data/examples/declaration/splice/quasiquote.hs view
@@ -9,3 +9,6 @@ [d|    foo bar  |]++header = [here|+#include foo|]
+ data/examples/declaration/value/function/operators-7-out.hs view
@@ -0,0 +1,1 @@+foo c = case c of { _ -> c } : []
+ data/examples/declaration/value/function/operators-7.hs view
@@ -0,0 +1,1 @@+foo c = case c of {_->c} : []
data/examples/other/cpp/continuation-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ foo :: Int foo = 5 
data/examples/other/cpp/continuation.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ foo :: Int foo = 5 
data/examples/other/cpp/lonely-hash-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ module Main (main) where  import Data.Void
data/examples/other/cpp/lonely-hash.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ module Main (main) where  import Data.Void
data/examples/other/cpp/separation-0a-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ instance Stream s => Monad (ParsecT e s m) where   return = pure   (>>=) = pBind
data/examples/other/cpp/separation-0a.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ instance Stream s => Monad (ParsecT e s m) where   return = pure   (>>=)  = pBind
data/examples/other/cpp/separation-0b-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ instance Stream s => Monad (ParsecT e s m) where   return = pure   (>>=) = pBind
data/examples/other/cpp/separation-0b.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ instance Stream s => Monad (ParsecT e s m) where   return = pure   (>>=)  = pBind
data/examples/other/cpp/separation-1a-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ decompressingPipe ::   (PrimMonad m, MonadThrow m, MonadResource m) =>   CompressionMethod ->
data/examples/other/cpp/separation-1a.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ decompressingPipe   :: (PrimMonad m, MonadThrow m, MonadResource m)   => CompressionMethod
data/examples/other/cpp/separation-1b-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ decompressingPipe ::   (PrimMonad m, MonadThrow m, MonadResource m) =>   CompressionMethod ->
data/examples/other/cpp/separation-1b.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ decompressingPipe   :: (PrimMonad m, MonadThrow m, MonadResource m)   => CompressionMethod
data/examples/other/cpp/separation-2a-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ ffff, ffffffff :: Natural #ifdef HASKELL_ZIP_DEV_MODE ffff     = 200
data/examples/other/cpp/separation-2a.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ ffff, ffffffff :: Natural #ifdef HASKELL_ZIP_DEV_MODE ffff     = 200
data/examples/other/cpp/separation-2b-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ ffff, ffffffff :: Natural #ifdef HASKELL_ZIP_DEV_MODE ffff     = 200
data/examples/other/cpp/separation-2b.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ ffff, ffffffff :: Natural #ifdef HASKELL_ZIP_DEV_MODE ffff     = 200
data/examples/other/cpp/shifted-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ sinkData h compression = do   (uncompressedSize, crc32, compressedSize) <-     case compression of
data/examples/other/cpp/shifted.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ sinkData h compression = do   (uncompressedSize, crc32, compressedSize) <-     case compression of
data/examples/other/cpp/simple-import-out.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ module Main (main) where  import Data.Void
data/examples/other/cpp/simple-import.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ module Main (main) where  import Data.Void
ormolu.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               ormolu-version:            0.3.0.0+version:            0.3.0.1 license:            BSD-3-Clause license-file:       LICENSE.md maintainer:         Mark Karpov <mark.karpov@tweag.io>@@ -149,11 +149,13 @@     build-depends:         base >=4.12 && <5.0,         containers >=0.5 && <0.7,+        directory ^>=1.3,         filepath >=1.2 && <1.5,         hspec >=2.0 && <3.0,         ormolu,         path >=0.6 && <0.10,         path-io >=1.4.2 && <2.0,+        temporary ^>=1.3,         text >=0.2 && <1.3      if flag(dev)
src/Ormolu/Parser.hs view
@@ -17,6 +17,7 @@ import qualified Data.List.NonEmpty as NE import Data.Ord (Down (Down)) import GHC.Data.Bag (bagToList)+import qualified GHC.Data.EnumSet as EnumSet import qualified GHC.Data.FastString as GHC import qualified GHC.Data.StringBuffer as GHC import qualified GHC.Driver.CmdLine as GHC@@ -71,7 +72,8 @@                 (mkSrcLoc (GHC.mkFastString path) 1 1)                 (mkSrcLoc (GHC.mkFastString path) 1 1)          in throwIO (OrmoluParsingFailed loc err)-  snippets <- runExceptT . forM (preprocess cfgRegion rawInput) $ \case+  let cppEnabled = EnumSet.member Cpp (GHC.extensionFlags dynFlags)+  snippets <- runExceptT . forM (preprocess cppEnabled cfgRegion rawInput) $ \case     Right region ->       fmap ParsedSnippet . ExceptT $         parseModuleSnippet (config $> region) dynFlags path rawInput
src/Ormolu/Printer/Meat/Declaration/Value.hs view
@@ -1330,7 +1330,7 @@   useRecordDot' <- useRecordDot   if       | gotColon -> do-        lhs+        ub lhs         space         p_op         case placement of
src/Ormolu/Processing/Preprocess.hs view
@@ -27,10 +27,15 @@  -- | Preprocess the specified region of the input into raw snippets -- and subregions to be formatted.-preprocess :: RegionDeltas -> String -> [Either Text RegionDeltas]-preprocess region rawInput = rawSnippetsAndRegionsToFormat+preprocess ::+  -- | Whether CPP is enabled+  Bool ->+  RegionDeltas ->+  String ->+  [Either Text RegionDeltas]+preprocess cppEnabled region rawInput = rawSnippetsAndRegionsToFormat   where-    (linesNotToFormat', replacementLines) = linesNotToFormat region rawInput+    (linesNotToFormat', replacementLines) = linesNotToFormat cppEnabled region rawInput     regionsToFormat =       intSetToRegions rawLineLength $         IntSet.fromAscList [1 .. rawLineLength] IntSet.\\ linesNotToFormat'@@ -81,8 +86,13 @@  -- | All lines we are not supposed to format, and a set of replacements -- for specific lines.-linesNotToFormat :: RegionDeltas -> String -> (IntSet, IntMap String)-linesNotToFormat region@RegionDeltas {..} input =+linesNotToFormat ::+  -- | Whether CPP is enabled+  Bool ->+  RegionDeltas ->+  String ->+  (IntSet, IntMap String)+linesNotToFormat cppEnabled region@RegionDeltas {..} input =   (unconsidered <> magicDisabled <> otherDisabled, lineUpdates)   where     unconsidered =@@ -91,7 +101,9 @@     totalLines = length (lines input)     regionLines = linesInRegion region input     (magicDisabled, lineUpdates) = magicDisabledLines regionLines-    otherDisabled = (cppLines <> shebangLines <> linePragmaLines) regionLines+    otherDisabled = (mconcat allLines) regionLines+      where+        allLines = [shebangLines, linePragmaLines] <> [cppLines | cppEnabled]  -- | Ormolu state. data OrmoluState
src/Ormolu/Utils/Extensions.hs view
@@ -14,18 +14,19 @@ import Control.Exception import Control.Monad.IO.Class import qualified Data.ByteString as B-import Data.List (find) import Data.Map.Lazy (Map) import qualified Data.Map.Lazy as M import Data.Maybe (maybeToList) import qualified Distribution.ModuleName as ModuleName import Distribution.PackageDescription import Distribution.PackageDescription.Parsec+import qualified Distribution.Types.CondTree as CT import Language.Haskell.Extension import Ormolu.Config import Ormolu.Exception import System.Directory import System.FilePath+import System.IO (hPutStrLn, stderr) import System.IO.Error (isDoesNotExistError)  -- | Get a map from Haskell source file paths (without any extensions)@@ -49,12 +50,17 @@       buildMap extractFromBenchmark . snd <$> condBenchmarks     ]   where-    buildMap f a = let (files, exts) = f (condTreeData a) in M.fromList $ (,exts) <$> files+    buildMap f a = let (files, exts) = f mergedA in M.fromList $ (,exts) <$> files+      where+        (mergedA, _) = CT.ignoreConditions a      extractFromBuildInfo extraModules BuildInfo {..} = (,exts) $ do       m <- extraModules ++ (ModuleName.toFilePath <$> otherModules)-      (takeDirectory cabalFile </>) . (</> dropExtensions m) <$> hsSourceDirs+      (takeDirectory cabalFile </>) <$> prependSrcDirs (dropExtensions m)       where+        prependSrcDirs f+          | null hsSourceDirs = [f]+          | otherwise = (</> f) <$> hsSourceDirs         exts = maybe [] langExt defaultLanguage ++ fmap extToDynOption defaultExtensions         langExt =           pure . DynOption . \case@@ -94,11 +100,19 @@   m (Maybe FilePath) findCabalFile p = liftIO $ do   let parentDir = takeDirectory p-  ps <-+  dirEntries <-     listDirectory parentDir `catch` \case       (isDoesNotExistError -> True) -> pure []       e -> throwIO e-  case find ((== ".cabal") . takeExtension) ps of+  let findDotCabal = \case+        [] -> pure Nothing+        e : es+          | takeExtension e == ".cabal" ->+            doesFileExist (parentDir </> e) >>= \case+              True -> pure $ Just e+              False -> findDotCabal es+        _ : es -> findDotCabal es+  findDotCabal dirEntries >>= \case     Just cabalFile -> pure . Just $ parentDir </> cabalFile     Nothing ->       if isDrive parentDir@@ -114,9 +128,18 @@   m [DynOption] getCabalExtensionDynOptions sourceFile' = liftIO $ do   sourceFile <- makeAbsolute sourceFile'-  mCabalFile <- findCabalFile sourceFile-  case mCabalFile of+  findCabalFile sourceFile >>= \case     Just cabalFile -> do       extsByFile <- getExtensionsFromCabalFile cabalFile-      pure $ M.findWithDefault [] (dropExtensions sourceFile) extsByFile-    Nothing -> pure []+      case M.lookup (dropExtensions sourceFile) extsByFile of+        Just exts -> pure exts+        Nothing -> do+          relativeCabalFile <- makeRelativeToCurrentDirectory cabalFile+          note $+            "Found .cabal file "+              <> relativeCabalFile+              <> ", but it did not mention "+              <> sourceFile'+    Nothing -> note $ "Could not find a .cabal file for " <> sourceFile'+  where+    note msg = [] <$ hPutStrLn stderr msg
tests/Ormolu/CabalExtensionsSpec.hs view
@@ -3,6 +3,9 @@ import qualified Data.Map as M import Ormolu.Config import Ormolu.Utils.Extensions+import System.Directory+import System.FilePath+import System.IO.Temp (withSystemTempDirectory) import Test.Hspec  spec :: Spec@@ -23,5 +26,10 @@           cabalFile `shouldBe` Just expectedCabalFile     findsOrmoluCabal "src/Ormolu/Config.hs" "./ormolu.cabal"     findsOrmoluCabal "a/b/c/d/e" "./ormolu.cabal"+  it "do not consider directories as .cabal files" $+    withSystemTempDirectory "" $ \dir -> do+      createDirectory $ dir </> ".cabal"+      cabalFile <- findCabalFile $ dir </> "foo/bar.hs"+      cabalFile `shouldBe` Nothing   where     members as m = all (`M.member` m) as