on master help sign in
Improve grouping of top-level type signatures
commit68c3147f5ed37a71ac850889c12dddd0757d5968 authorMark Karpov <markkarpov92@gmail.com> dateFri 26 Jun 2020, 11:54 (6 years ago) parente5bbfdd
13 files changed+30−14
CHANGELOG.md+3 data/examples/declaration/signature/type/infix-promoted-type-constructor-out.hs−1 data/examples/declaration/signature/type/unrelated-out.hs+4 data/examples/declaration/signature/type/unrelated.hs+4 data/examples/declaration/value/function/implicit-params-out.hs+1 data/examples/declaration/value/function/implicit-params.hs+2 data/examples/other/argument-comment-out.hs−1 data/examples/other/cpp/separation-2b-out.hs−1 expected-failures/Agda.txt+1−1 expected-failures/intero.txt+1−1 src/Ormolu/Printer/Meat/Declaration.hs+14−4 src/Ormolu/Printer/Meat/Declaration.hs-boot−1 src/Ormolu/Printer/Meat/Declaration/Value.hs-boot−4
CHANGELOG.md+3
@@ -6,6 +6,9 @@
66* Added `-i` as a shortcut for `--mode inplace`. [Issue
77 467](https://github.com/tweag/ormolu/issues/467).
88
9+* Improved grouping of top-level declarations. [Issue
10+ 466](https://github.com/tweag/ormolu/issues/466).
11+
912## Ormolu 0.1.1.0
1013
1114* Imports in a import lists are now normalized: duplicate imports are
data/examples/declaration/signature/type/infix-promoted-type-constructor-out.hs−1
@@ -1,3 +1,2 @@
11fun1 :: Def ('[Ref s (Stored Uint32), IBool] 'T.:-> IBool)
2−
32fun2 :: Def ('[Ref s (Stored Uint32), IBool] ':-> IBool)
data/examples/declaration/signature/type/unrelated-out.hsnew file+4
@@ -0,0 +1,4 @@
1+clientFunc1 :: SomeType1
2+clientFunc2 :: SomeType2
3+clientFunc3 :: SomeType3
4+clientFunc1 :<|> clientFunc2 :<|> clientFunc3 = hoistClient foo bar baz
data/examples/declaration/signature/type/unrelated.hsnew file+4
@@ -0,0 +1,4 @@
1+clientFunc1 :: SomeType1
2+clientFunc2 :: SomeType2
3+clientFunc3 :: SomeType3
4+clientFunc1 :<|> clientFunc2 :<|> clientFunc3 = hoistClient foo bar baz
data/examples/declaration/value/function/implicit-params-out.hs+1
@@ -1,6 +1,7 @@
11{-# LANGUAGE ImplicitParams #-}
22
33sortBy :: (a -> a -> Bool) -> [a] -> [a]
4+sortBy = undefined
45
56sort :: (?cmp :: a -> a -> Bool) => [a] -> [a]
67sort = sortBy ?cmp
data/examples/declaration/value/function/implicit-params.hs+2
@@ -1,6 +1,8 @@
11{-# LANGUAGE ImplicitParams #-}
22sortBy :: (a -> a -> Bool) -> [a] -> [a]
33
4+sortBy = undefined
5+
46sort :: (?cmp :: a -> a -> Bool) => [a] -> [a]
57sort = sortBy ?cmp
68
data/examples/other/argument-comment-out.hs−1
@@ -9,7 +9,6 @@ foo ::
99 -- | Foo
1010 Int ->
1111 Int
12−
1312foo ::
1413 Foo a =>
1514 -- | Foo
data/examples/other/cpp/separation-2b-out.hs−1
@@ -1,5 +1,4 @@
11ffff, ffffffff :: Natural
2−
32#ifdef HASKELL_ZIP_DEV_MODE
43ffff = 200
54ffffffff = 5000
expected-failures/Agda.txt+1−1
@@ -1,5 +1,5 @@
11Formatting is not idempotent:
2− dist/build/Agda/Syntax/Parser/Lexer.hs<rendered>:1597:17
2+ dist/build/Agda/Syntax/Parser/Lexer.hs<rendered>:1602:17
33 before: " = (check_ac"
44 after: " =\n "
55Please, consider reporting the bug.
expected-failures/intero.txt+1−1
@@ -1,5 +1,5 @@
11Formatting is not idempotent:
2− src/InteractiveUI.hs<rendered>:3757:33
2+ src/InteractiveUI.hs<rendered>:3748:33
33 before: "text \"Try\" <+> doWha"
44 after: "text \"Try\"\n "
55Please, consider reporting the bug.
src/Ormolu/Printer/Meat/Declaration.hs+14−4
@@ -85,9 +85,6 @@ isDocumented = any (isHaddock . unLoc)
8585 isHaddock _ = False
8686
8787-- | Group relevant declarations together.
88−--
89−-- Add a declaration to a group iff it is relevant to either the first or
90−-- the preceding declaration in the group.
9188groupDecls :: [LHsDecl GhcPs] -> [NonEmpty (LHsDecl GhcPs)]
9289groupDecls [] = []
9390groupDecls (l@(L _ DocNext) : xs) =
@@ -100,7 +97,8 @@ groupDecls (header : xs) =
10097 let (grp, rest) = flip span (zip (header : xs) xs) $ \(previous, current) ->
10198 let relevantToHdr = groupedDecls header current
10299 relevantToPrev = groupedDecls previous current
103− in relevantToHdr || relevantToPrev
100+ isDeclSeries = declSeries previous current
101+ in isDeclSeries || relevantToHdr || relevantToPrev
104102 in (header :| map snd grp) : groupDecls (map snd rest)
105103
106104p_hsDecl :: FamilyStyle -> HsDecl GhcPs -> R ()
@@ -197,6 +195,18 @@ groupedDecls (L l_x x') (L l_y y') =
197195 (_, DocPrev) -> True
198196 _ -> False
199197
198+-- | Detect declaration series that should not have blanks between them.
199+declSeries ::
200+ LHsDecl GhcPs ->
201+ LHsDecl GhcPs ->
202+ Bool
203+declSeries (L _ x) (L _ y) =
204+ case (x, y) of
205+ ( SigD NoExtField (TypeSig NoExtField _ _),
206+ SigD NoExtField (TypeSig NoExtField _ _)
207+ ) -> True
208+ _ -> False
209+
200210intersects :: Ord a => [a] -> [a] -> Bool
201211intersects a b = go (sort a) (sort b)
202212 where
src/Ormolu/Printer/Meat/Declaration.hs-boot−1
@@ -9,5 +9,4 @@ import Ormolu.Printer.Combinators
99import Ormolu.Printer.Meat.Common
1010
1111p_hsDecls :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
12−
1312p_hsDeclsRespectGrouping :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
src/Ormolu/Printer/Meat/Declaration/Value.hs-boot−4
@@ -11,11 +11,7 @@ import GHC
1111import Ormolu.Printer.Combinators
1212
1313p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
14−
1514p_pat :: Pat GhcPs -> R ()
16−
1715p_hsExpr :: HsExpr GhcPs -> R ()
18−
1916p_hsSplice :: HsSplice GhcPs -> R ()
20−
2117p_stringLit :: String -> R ()