ormolu 0.1.1.0 → 0.1.2.0
raw patch · 16 files changed
+67/−23 lines, 16 filesdep ~dlistdep ~optparse-applicativePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: dlist, optparse-applicative
API changes (from Hackage documentation)
Files
- CHANGELOG.md +11/−0
- README.md +2/−2
- app/Main.hs +13/−7
- data/examples/declaration/signature/type/infix-promoted-type-constructor-out.hs +0/−1
- data/examples/declaration/signature/type/unrelated-out.hs +4/−0
- data/examples/declaration/signature/type/unrelated.hs +4/−0
- data/examples/declaration/value/function/implicit-params-out.hs +1/−0
- data/examples/declaration/value/function/implicit-params.hs +2/−0
- data/examples/other/argument-comment-out.hs +0/−1
- data/examples/other/comment-glued-together-out.hs +7/−0
- data/examples/other/comment-glued-together.hs +6/−0
- ormolu.cabal +1/−1
- src/Ormolu/Printer/Comments.hs +2/−2
- src/Ormolu/Printer/Meat/Declaration.hs +14/−4
- src/Ormolu/Printer/Meat/Declaration.hs-boot +0/−1
- src/Ormolu/Printer/Meat/Declaration/Value.hs-boot +0/−4
CHANGELOG.md view
@@ -1,3 +1,14 @@+## Ormolu 0.1.2.0++* Fixed the bug when comments in different styles got glued together after+ formatting. [Issue 589](https://github.com/tweag/ormolu/issues/589).++* Added `-i` as a shortcut for `--mode inplace`. [Issue+ 467](https://github.com/tweag/ormolu/issues/467).++* Improved grouping of top-level declarations. [Issue+ 466](https://github.com/tweag/ormolu/issues/466).+ ## Ormolu 0.1.1.0 * Imports in a import lists are now normalized: duplicate imports are
README.md view
@@ -49,8 +49,8 @@ packages: - '.' -$ stack build -- to build-$ stack install -- to install+$ stack build # to build+$ stack install # to install ``` To use Ormolu directly from GitHub with Nix, this snippet may come in handy:
app/Main.hs view
@@ -8,6 +8,7 @@ import Control.Exception (SomeException, displayException, try) import Control.Monad+import Data.Bool (bool) import Data.Either (lefts) import Data.List (intercalate, sort) import qualified Data.Text.IO as TIO@@ -134,13 +135,18 @@ optsParser :: Parser Opts optsParser = Opts- <$> (option parseMode . mconcat)- [ long "mode",- short 'm',- metavar "MODE",- value Stdout,- help "Mode of operation: 'stdout' (default), 'inplace', or 'check'"- ]+ <$> ( (fmap (bool Stdout InPlace) . switch . mconcat)+ [ short 'i',+ help "A shortcut for --mode inplace"+ ]+ <|> (option parseMode . mconcat)+ [ long "mode",+ short 'm',+ metavar "MODE",+ value Stdout,+ help "Mode of operation: 'stdout' (default), 'inplace', or 'check'"+ ]+ ) <*> configParser <*> (many . strArgument . mconcat) [ metavar "FILE",
data/examples/declaration/signature/type/infix-promoted-type-constructor-out.hs view
@@ -1,3 +1,2 @@ fun1 :: Def ('[Ref s (Stored Uint32), IBool] 'T.:-> IBool)- fun2 :: Def ('[Ref s (Stored Uint32), IBool] ':-> IBool)
@@ -0,0 +1,4 @@+clientFunc1 :: SomeType1+clientFunc2 :: SomeType2+clientFunc3 :: SomeType3+clientFunc1 :<|> clientFunc2 :<|> clientFunc3 = hoistClient foo bar baz
@@ -0,0 +1,4 @@+clientFunc1 :: SomeType1+clientFunc2 :: SomeType2+clientFunc3 :: SomeType3+clientFunc1 :<|> clientFunc2 :<|> clientFunc3 = hoistClient foo bar baz
data/examples/declaration/value/function/implicit-params-out.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE ImplicitParams #-} sortBy :: (a -> a -> Bool) -> [a] -> [a]+sortBy = undefined sort :: (?cmp :: a -> a -> Bool) => [a] -> [a] sort = sortBy ?cmp
data/examples/declaration/value/function/implicit-params.hs view
@@ -1,6 +1,8 @@ {-# LANGUAGE ImplicitParams #-} sortBy :: (a -> a -> Bool) -> [a] -> [a] +sortBy = undefined+ sort :: (?cmp :: a -> a -> Bool) => [a] -> [a] sort = sortBy ?cmp
data/examples/other/argument-comment-out.hs view
@@ -9,7 +9,6 @@ -- | Foo Int -> Int- foo :: Foo a => -- | Foo
+ data/examples/other/comment-glued-together-out.hs view
@@ -0,0 +1,7 @@+module Main (main) where++-- | Foo.++-- Bar+main :: IO ()+main = return ()
+ data/examples/other/comment-glued-together.hs view
@@ -0,0 +1,6 @@+module Main (main) where++{- | Foo. -}+-- Bar+main :: IO ()+main = return ()
ormolu.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: ormolu-version: 0.1.1.0+version: 0.1.2.0 license: BSD3 license-file: LICENSE.md maintainer: Mark Karpov <mark.karpov@tweag.io>
src/Ormolu/Printer/Comments.hs view
@@ -154,6 +154,7 @@ -- | Last printed comment span Maybe SpanMark -> Bool+needsNewlineBefore _ (Just (HaddockSpan _ _)) = True needsNewlineBefore l mlastMark = case spanMarkSpan <$> mlastMark of Nothing -> False@@ -238,8 +239,7 @@ -- lexemes in front of it and goes right after the previous comment. not (hasAtomsBefore comment) && ( case mlastMark of- Just (HaddockSpan _ spn) ->- srcSpanEndLine spn + 1 == srcSpanStartLine l+ Just (HaddockSpan _ _) -> False Just (CommentSpan spn) -> srcSpanEndLine spn + 1 == srcSpanStartLine l _ -> False
src/Ormolu/Printer/Meat/Declaration.hs view
@@ -85,9 +85,6 @@ isHaddock _ = False -- | Group relevant declarations together.------ Add a declaration to a group iff it is relevant to either the first or--- the preceding declaration in the group. groupDecls :: [LHsDecl GhcPs] -> [NonEmpty (LHsDecl GhcPs)] groupDecls [] = [] groupDecls (l@(L _ DocNext) : xs) =@@ -100,7 +97,8 @@ let (grp, rest) = flip span (zip (header : xs) xs) $ \(previous, current) -> let relevantToHdr = groupedDecls header current relevantToPrev = groupedDecls previous current- in relevantToHdr || relevantToPrev+ isDeclSeries = declSeries previous current+ in isDeclSeries || relevantToHdr || relevantToPrev in (header :| map snd grp) : groupDecls (map snd rest) p_hsDecl :: FamilyStyle -> HsDecl GhcPs -> R ()@@ -195,6 +193,18 @@ -- This looks only at Haddocks, normal comments are handled elsewhere (DocNext, _) -> True (_, DocPrev) -> True+ _ -> False++-- | Detect declaration series that should not have blanks between them.+declSeries ::+ LHsDecl GhcPs ->+ LHsDecl GhcPs ->+ Bool+declSeries (L _ x) (L _ y) =+ case (x, y) of+ ( SigD NoExtField (TypeSig NoExtField _ _),+ SigD NoExtField (TypeSig NoExtField _ _)+ ) -> True _ -> False intersects :: Ord a => [a] -> [a] -> Bool
src/Ormolu/Printer/Meat/Declaration.hs-boot view
@@ -9,5 +9,4 @@ import Ormolu.Printer.Meat.Common p_hsDecls :: FamilyStyle -> [LHsDecl GhcPs] -> R ()- p_hsDeclsRespectGrouping :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
src/Ormolu/Printer/Meat/Declaration/Value.hs-boot view
@@ -11,11 +11,7 @@ import Ormolu.Printer.Combinators p_valDecl :: HsBindLR GhcPs GhcPs -> R ()- p_pat :: Pat GhcPs -> R ()- p_hsExpr :: HsExpr GhcPs -> R ()- p_hsSplice :: HsSplice GhcPs -> R ()- p_stringLit :: String -> R ()