on master help sign in
Render type applications similar to value applications
commit9b342488be5d7d44cd0a05429a78700f5c650813 authorMark Karpov <markkarpov92@gmail.com> dateFri 10 Apr 2020, 14:12 (7 years ago) parent9b7b6eb
6 files changed+27−9
CHANGELOG.md+4 data/examples/declaration/data/field-layout/gadt-out.hs+2−1 data/examples/declaration/data/field-layout/record-out.hs+2−1 data/examples/declaration/instance/data-family-instances-gadt-out.hs+4−2 src/Ormolu/Printer/Meat/Declaration/Value.hs+1−1 src/Ormolu/Printer/Meat/Type.hs+14−4
CHANGELOG.md+4
@@ -19,6 +19,10 @@
1919* Fixed the bug pertaining to rendering of arrow notation with multiline
2020 expressions. [Issue 513](https://github.com/tweag/ormolu/issues/513).
2121
22+* Made rendering of data type definitions, value-level applications, and
23+ application of types use the same style. [Issue
24+ 427](https://github.com/tweag/ormolu/issues/427).
25+
2226* Implemented support for the new language extension `ImportQualifiedPost`.
2327
2428* Implemented support for the new language extension
data/examples/declaration/data/field-layout/gadt-out.hs+2−1
@@ -6,5 +6,6 @@ data Foo a b where
66 Foo :: Foo Int Int
77 -- | Something else
88 Bar ::
9− Foo Char
9+ Foo
10+ Char
1011 Char
data/examples/declaration/data/field-layout/record-out.hs+2−1
@@ -7,6 +7,7 @@ data Foo
77 foo :: Foo Int Int,
88 -- | Something else
99 bar ::
10− Bar Char
10+ Bar
11+ Char
1112 Char
1213 }
data/examples/declaration/instance/data-family-instances-gadt-out.hs+4−2
@@ -3,9 +3,11 @@
33
44data instance Bar Int a where
55 SameBar ::
6− Bar Int
6+ Bar
7+ Int
78 Int
89 CloseBar :: Bar Int Double
910 OtherBar ::
10− Bar Int
11+ Bar
12+ Int
1113 a
src/Ormolu/Printer/Meat/Declaration/Value.hs+1−1
@@ -21,7 +21,7 @@ import Data.Char (isPunctuation, isSymbol)
2121import Data.Data hiding (Infix, Prefix)
2222import Data.Functor ((<&>))
2323import Data.List (intersperse, sortOn)
24−import Data.List.NonEmpty ((<|), NonEmpty ((:|)))
24+import Data.List.NonEmpty ((<|), NonEmpty (..))
2525import qualified Data.List.NonEmpty as NE
2626import Data.Text (Text)
2727import qualified Data.Text as Text
src/Ormolu/Printer/Meat/Type.hs+14−4
@@ -49,10 +49,20 @@ p_hsType' multilineArgs = \case
4949 _ -> return ()
5050 NotPromoted -> return ()
5151 p_rdrName n
52− HsAppTy NoExtField f x -> sitcc $ do
53− located f p_hsType
54− breakpoint
55− inci (located x p_hsType)
52+ HsAppTy NoExtField f x -> do
53+ let -- In order to format type applications with multiple parameters
54+ -- nicer, traverse the AST to gather the function and all the
55+ -- parameters together.
56+ gatherArgs f' knownArgs =
57+ case f' of
58+ L _ (HsAppTy _ l r) -> gatherArgs l (r : knownArgs)
59+ _ -> (f', knownArgs)
60+ (func, args) = gatherArgs f [x]
61+ switchLayout (getLoc f : fmap getLoc args) $ sitcc $ do
62+ located func p_hsType
63+ breakpoint
64+ inci $
65+ sep breakpoint (located' p_hsType) args
5666 HsAppKindTy _ ty kd -> sitcc $ do
5767 -- The first argument is the location of the "@..." part. Not 100% sure,
5868 -- but I think we can ignore it as long as we use 'located' on both the