packages feed

ormolu 0.7.1.0 → 0.7.2.0

raw patch · 19 files changed

+127/−39 lines, 19 filesdep ~bytestringdep ~deepseqPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: bytestring, deepseq

API changes (from Hackage documentation)

- Ormolu.Parser.CommentStream: showCommentStream :: CommentStream -> String
+ Ormolu.Imports: instance GHC.Classes.Eq Ormolu.Imports.ImportPkgQual
+ Ormolu.Imports: instance GHC.Classes.Ord Ormolu.Imports.ImportPkgQual

Files

CHANGELOG.md view
@@ -1,3 +1,17 @@+## Ormolu 0.7.2.0++* Preserve necessary braces for final function arguments. [Issue+  1044](https://github.com/tweag/ormolu/issues/1044).++* Put `"this"` `PackageImports` at the end. [Issue+  1048](https://github.com/tweag/ormolu/issues/1048).++* Format parenthesized operators starting with a `#` correctly in the presence+  of `UnboxedSums`. [Issue 1062](https://github.com/tweag/ormolu/issues/1062).++* Fix false positives in AST diffing related to empty Haddock comments in data+  declarations. [Issue 1065](https://github.com/tweag/ormolu/issues/1065).+ ## Ormolu 0.7.1.0  * Include `base` fixity information when formatting a Haskell file that's
README.md view
@@ -279,8 +279,6 @@   works only in simple cases when CPP conditionals surround top-level   declarations. See the [CPP][design-cpp] section in the design notes for a   discussion of the dangers.-* Input modules should be parsable by Haddock, which is a bit stricter-  criterion than just being valid Haskell modules.  ## Running on Hackage 
+ data/examples/declaration/value/function/operator-hash-with-unboxed-sums-out.hs view
@@ -0,0 +1,8 @@+{-# LANGUAGE UnboxedSums #-}++module Foo (( #<| )) where++( #<| ) :: Int -> Int -> Int+( #<| ) = (+)++(+) = (+)
+ data/examples/declaration/value/function/operator-hash-with-unboxed-sums.hs view
@@ -0,0 +1,8 @@+{-# LANGUAGE UnboxedSums #-}++module Foo (( #<| )) where++( #<| ) :: Int -> Int -> Int+( #<| ) = (+)++(+) = (+)
+ data/examples/declaration/value/function/operator-hash-without-unboxed-sums-out.hs view
@@ -0,0 +1,6 @@+module Foo ((#<|)) where++(#<|) :: Int -> Int -> Int+(#<|) = (+)++(+) = (+)
+ data/examples/declaration/value/function/operator-hash-without-unboxed-sums.hs view
@@ -0,0 +1,6 @@+module Foo (( #<| )) where++( #<| ) :: Int -> Int -> Int+( #<| ) = (+)++(+) = (+)
data/examples/import/sorted-package-imports-out.hs view
@@ -5,3 +5,5 @@ import "b" Aa import "b" Bb import "c" Ba+import "zzzz" Z+import "this" Y
data/examples/import/sorted-package-imports.hs view
@@ -5,3 +5,6 @@ import "c" Ba import D import "b" Bb++import "this" Y+import "zzzz" Z
data/examples/other/empty-haddock-out.hs view
@@ -5,3 +5,5 @@  test ::   test++data T = T
data/examples/other/empty-haddock.hs view
@@ -9,3 +9,5 @@ test ::   -- |   test++data T = T {- ^ -}
+ data/examples/other/necessary-brackets-out.hs view
@@ -0,0 +1,3 @@+insertEmDash = Text.concat . map \case { x | x == "--" -> "—"; x -> x } . Text.groupBy ((==) `on` Char.isSpace)++foo f a b c = f do { a } + f do { b } + f do c
+ data/examples/other/necessary-brackets.hs view
@@ -0,0 +1,3 @@+insertEmDash = Text.concat . map \case{ x | x == "--" -> "—"; x -> x } . Text.groupBy ((==) `on` Char.isSpace)++foo f a b c = f do {a} + f do {b} + f do {c}
ormolu.cabal view
@@ -1,10 +1,10 @@ cabal-version:      2.4 name:               ormolu-version:            0.7.1.0+version:            0.7.2.0 license:            BSD-3-Clause license-file:       LICENSE.md maintainer:         Mark Karpov <mark.karpov@tweag.io>-tested-with:        ghc ==9.2.7 ghc ==9.4.4 ghc ==9.6.1+tested-with:        ghc ==9.2.8 ghc ==9.4.5 ghc ==9.6.2 homepage:           https://github.com/tweag/ormolu bug-reports:        https://github.com/tweag/ormolu/issues synopsis:           A formatter for Haskell source code@@ -104,9 +104,9 @@         array >=0.5 && <0.6,         base >=4.14 && <5.0,         binary >=0.8 && <0.9,-        bytestring >=0.2 && <0.12,+        bytestring >=0.2 && <0.13,         containers >=0.5 && <0.7,-        deepseq >=1.4 && <1.5,+        deepseq >=1.4 && <1.6,         directory ^>=1.3,         file-embed >=0.0.15 && <0.1,         filepath >=1.2 && <1.5,
src/Ormolu.hs view
@@ -54,7 +54,7 @@ import Ormolu.Exception import Ormolu.Fixity import Ormolu.Parser-import Ormolu.Parser.CommentStream (showCommentStream)+import Ormolu.Parser.CommentStream (CommentStream (..)) import Ormolu.Parser.Result import Ormolu.Printer import Ormolu.Utils (showOutputable)@@ -91,13 +91,18 @@       fixityMap =         packageFixityMap           (overapproximatedDependencies cfg) -- memoized on the set of dependencies+  when (cfgDebug cfg) $ do+    traceM $ unwords ["*** CONFIG ***", show cfg]   (warnings, result0) <-     parseModule' cfg fixityMap OrmoluParsingFailed path originalInput   when (cfgDebug cfg) $ do-    traceM "warnings:\n"-    traceM (concatMap showWarn warnings)+    forM_ warnings $ \(GHC.Warn reason (L loc msg)) ->+      traceM $ unwords ["*** WARNING ***", showOutputable loc, msg, showOutputable reason]     forM_ result0 $ \case-      ParsedSnippet r -> traceM . showCommentStream . prCommentStream $ r+      ParsedSnippet r -> do+        let CommentStream comments = prCommentStream r+        forM_ comments $ \(L loc comment) ->+          traceM $ unwords ["*** COMMENT ***", showOutputable loc, show comment]       _ -> pure ()   -- We're forcing 'formattedText' here because otherwise errors (such as   -- messages about not-yet-supported functionality) will be thrown later@@ -245,14 +250,6 @@   case r of     Left (spn, err) -> liftIO $ throwIO (mkException spn err)     Right x -> return (warnings, x)---- | Pretty-print a 'GHC.Warn'.-showWarn :: GHC.Warn -> String-showWarn (GHC.Warn reason l) =-  unlines-    [ showOutputable reason,-      unLoc l-    ]  -- | Detect 'SourceType' based on the file extension. detectSourceType :: FilePath -> SourceType
src/Ormolu/Imports.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE ViewPatterns #-}  -- | Manipulations on import lists. module Ormolu.Imports@@ -63,7 +64,7 @@ -- the same 'ImportId' they can be merged. data ImportId = ImportId   { importIsPrelude :: Bool,-    importPkgQual :: Maybe LexicalFastString,+    importPkgQual :: ImportPkgQual,     importIdName :: ModuleName,     importSource :: IsBootInterface,     importSafe :: Bool,@@ -73,6 +74,23 @@   }   deriving (Eq, Ord) +data ImportPkgQual+  = -- | The import is not qualified by a package name.+    NoImportPkgQual+  | -- | The import is qualified by an external package name.+    ImportPkgQual LexicalFastString+  | -- | The import is qualified by the current package being built, using the+    -- special @this@ package name.+    ImportPkgQualThis+  deriving stock (Eq, Ord)++mkImportPkgQual :: RawPkgQual -> ImportPkgQual+mkImportPkgQual = \case+  NoRawPkgQual -> NoImportPkgQual+  RawPkgQual (sl_fs -> fs)+    | fs == mkFastString "this" -> ImportPkgQualThis+    | otherwise -> ImportPkgQual (LexicalFastString fs)+ -- | 'ImportListInterpretation' does not have an 'Ord' instance. newtype ImportListInterpretationOrd = ImportListInterpretationOrd   { unImportListInterpretationOrd :: ImportListInterpretation@@ -91,7 +109,7 @@   ImportId     { importIsPrelude = isPrelude,       importIdName = moduleName,-      importPkgQual = rawPkgQualToLFS ideclPkgQual,+      importPkgQual = mkImportPkgQual ideclPkgQual,       importSource = ideclSource,       importSafe = ideclSafe,       importQualified = case ideclQualified of@@ -104,9 +122,6 @@   where     isPrelude = moduleNameString moduleName == "Prelude"     moduleName = unLoc ideclName-    rawPkgQualToLFS = \case-      RawPkgQual fs -> Just . LexicalFastString . sl_fs $ fs-      NoRawPkgQual -> Nothing  -- | Normalize a collection of import\/export items. normalizeLies :: [LIE GhcPs] -> [LIE GhcPs]
src/Ormolu/Parser.hs view
@@ -177,7 +177,7 @@ normalizeModule :: HsModule GhcPs -> HsModule GhcPs normalizeModule hsmod =   everywhere-    (extT (mkT dropBlankTypeHaddocks) patchContext)+    (mkT dropBlankTypeHaddocks `extT` dropBlankDataDeclHaddocks `extT` patchContext)     hsmod       { hsmodImports =           normalizeImports (hsmodImports hsmod),@@ -204,6 +204,13 @@       L _ (HsDocTy _ ty s) :: LHsType GhcPs         | isBlankDocString s -> ty       a -> a+    dropBlankDataDeclHaddocks = \case+      ConDeclGADT {con_doc = Just s, ..} :: ConDecl GhcPs+        | isBlankDocString s -> ConDeclGADT {con_doc = Nothing, ..}+      ConDeclH98 {con_doc = Just s, ..} :: ConDecl GhcPs+        | isBlankDocString s -> ConDeclH98 {con_doc = Nothing, ..}+      a -> a+     patchContext :: LHsContext GhcPs -> LHsContext GhcPs     patchContext = fmap $ \case       [x@(L _ (HsParTy _ _))] -> [x]
src/Ormolu/Parser/CommentStream.hs view
@@ -7,7 +7,6 @@   ( -- * Comment stream     CommentStream (..),     mkCommentStream,-    showCommentStream,      -- * Comment     LComment,@@ -38,7 +37,7 @@ import GHC.Parser.Annotation qualified as GHC import GHC.Types.SrcLoc import Ormolu.Parser.Pragma-import Ormolu.Utils (onTheSameLine, showOutputable)+import Ormolu.Utils (onTheSameLine)  ---------------------------------------------------------------------------- -- Comment stream@@ -104,14 +103,6 @@               _ -> False     only :: a -> Bool     only _ = True---- | Pretty-print a 'CommentStream'.-showCommentStream :: CommentStream -> String-showCommentStream (CommentStream xs) =-  unlines $-    showComment <$> xs-  where-    showComment (L l str) = showOutputable l ++ " " ++ show str  ---------------------------------------------------------------------------- -- Comment
src/Ormolu/Printer/Meat/Common.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ViewPatterns #-}  -- | Rendering of commonly useful bits. module Ormolu.Printer.Meat.Common@@ -20,8 +21,9 @@ import GHC.Hs.Doc import GHC.Hs.Extension (GhcPs) import GHC.Hs.ImpExp+import GHC.LanguageExtensions.Type (Extension (..)) import GHC.Parser.Annotation-import GHC.Types.Name.Occurrence (OccName (..))+import GHC.Types.Name.Occurrence (OccName (..), occNameString) import GHC.Types.Name.Reader import GHC.Types.SourceText import GHC.Types.SrcLoc@@ -62,15 +64,27 @@ -- | Render a @'LocatedN' 'RdrName'@. p_rdrName :: LocatedN RdrName -> R () p_rdrName l = located l $ \x -> do+  unboxedSums <- isExtensionEnabled UnboxedSums   let wrapper = \case         EpAnn {anns} -> case anns of           NameAnnQuote {nann_quoted} -> tickPrefix . wrapper (ann nann_quoted)-          NameAnn {nann_adornment = NameParens} -> parens N+          NameAnn {nann_adornment = NameParens} ->+            parens N . handleUnboxedSumsAndHashInteraction           NameAnn {nann_adornment = NameBackquotes} -> backticks           -- special case for unboxed unit tuples           NameAnnOnly {nann_adornment = NameParensHash} -> const $ txt "(# #)"           _ -> id         EpAnnNotUsed -> id++      -- When UnboxedSums is enabled, `(#` is a single lexeme, so we have to+      -- insert spaces when we have a parenthesized operator starting with `#`.+      handleUnboxedSumsAndHashInteraction+        | unboxedSums,+          -- Qualified names do not start wth a `#`.+          Unqual (occNameString -> '#' : _) <- x =+            \y -> space *> y <* space+        | otherwise = id+   wrapper (ann . getLoc $ l) $ case x of     Unqual occName ->       atom occName
src/Ormolu/Printer/Meat/Declaration/Value.hs view
@@ -489,9 +489,18 @@ p_stmts isApp placer render es = do   breakpoint   ub <- layoutToBraces <$> getLayout+  let p_stmtExt (relPos, stmt) =+        ub' $ withSpacing (p_stmt' placer render) stmt+        where+          -- We need to set brace usage information for all but the last+          -- statement (e.g.in the case of nested do blocks).+          ub' = case relPos of+            FirstPos -> ub+            MiddlePos -> ub+            LastPos -> id+            SinglePos -> id   inciApplicand isApp . located es $-    sepSemi-      (ub . withSpacing (p_stmt' placer render))+    sepSemi p_stmtExt . attachRelativePos  gatherStmt :: ExprLStmt GhcPs -> [[ExprLStmt GhcPs]] gatherStmt (L _ (ParStmt _ block _ _)) =@@ -654,7 +663,7 @@           located func (p_hsExpr' Applicand s)           breakpoint           sep breakpoint (located' p_hsExpr) initp-        placeHanging placement . dontUseBraces $+        placeHanging placement $           located lastp p_hsExpr   HsAppType _ e _ a -> do     located e p_hsExpr