@@ -15,17 +15,16 @@ where
15import BasicTypes
15import BasicTypes
16import Control.Arrow
16import Control.Arrow
17import Data.Foldable
17import Data.Foldable
19import Data.List (sortBy)
18import Data.List (sortBy)
19+import Data.Ord (comparing)
21import Ormolu.Printer.Combinators
21import Ormolu.Printer.Combinators
22import Ormolu.Printer.Meat.Common
22import Ormolu.Printer.Meat.Common
23import Ormolu.Printer.Meat.Declaration.Data
23import Ormolu.Printer.Meat.Declaration.Data
24−import Ormolu.Printer.Meat.Declaration.Signature
25import Ormolu.Printer.Meat.Declaration.TypeFamily
24import Ormolu.Printer.Meat.Declaration.TypeFamily
26−import Ormolu.Printer.Meat.Declaration.Value
27import Ormolu.Printer.Meat.Type
25import Ormolu.Printer.Meat.Type
28import Ormolu.Utils
26import Ormolu.Utils
27+import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration
30p_standaloneDerivDecl :: DerivDecl GhcPs -> R ()
29p_standaloneDerivDecl :: DerivDecl GhcPs -> R ()
31p_standaloneDerivDecl DerivDecl {..} = do
30p_standaloneDerivDecl DerivDecl {..} = do
@@ -75,26 +74,24 @@ p_clsInstDecl = \case
75 -- location order. This happens because different declarations are stored in
74 -- location order. This happens because different declarations are stored in
76 -- different lists. Consequently, to get all the declarations in proper
75 -- different lists. Consequently, to get all the declarations in proper
77 -- order, they need to be manually sorted.
76 -- order, they need to be manually sorted.
78− let binds = (getLoc &&& located' p_valDecl) <$> cid_binds
79− sigs = (getLoc &&& located' p_sigDecl) <$> cid_sigs
77+ let sigs = (getLoc &&& fmap (SigD NoExt)) <$> cid_sigs
80− tyfam_insts =
78+ vals = (getLoc &&& fmap (ValD NoExt)) <$> toList cid_binds
81− (getLoc &&& located' (p_tyFamInstDecl Associated)) <$>
79+ tyFamInsts =
80+ ( getLoc &&& fmap (InstD NoExt . TyFamInstD NoExt)
82− cid_tyfam_insts
81+ ) <$> cid_tyfam_insts
83− datafam_insts =
82+ dataFamInsts =
84− (getLoc &&& located' (p_dataFamInstDecl Associated)) <$>
83+ ( getLoc &&& fmap (InstD NoExt . DataFamInstD NoExt)
85− cid_datafam_insts
84+ ) <$> cid_datafam_insts
86− decls =
85+ allDecls =
88− sortBy
87+ sortBy (comparing fst) (sigs <> vals <> tyFamInsts <> dataFamInsts)
90− (toList binds <> sigs <> tyfam_insts <> datafam_insts)
91− if not (null decls)
88+ if not (null allDecls)
93− txt " where"
90+ txt " where"
94− newline
91+ newline -- Ensure line is added after where clause.
95− inci (sequence_ decls)
92+ newline -- Add newline before first declaration.
96− else do
93+ inci (p_hsDecls Associated allDecls)
97− newline
94+ else newline
98 XClsInstDecl NoExt -> notImplemented "XClsInstDecl"
95 XClsInstDecl NoExt -> notImplemented "XClsInstDecl"
100p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()
97p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()