@@ -15,17 +15,16 @@ where
1515import BasicTypes
1616import Control.Arrow
1717import Data.Foldable
18−import Data.Function
1918import Data.List (sortBy)
19+import Data.Ord (comparing)
2020import GHC
2121import Ormolu.Printer.Combinators
2222import Ormolu.Printer.Meat.Common
2323import Ormolu.Printer.Meat.Declaration.Data
24−import Ormolu.Printer.Meat.Declaration.Signature
2524import Ormolu.Printer.Meat.Declaration.TypeFamily
26−import Ormolu.Printer.Meat.Declaration.Value
2725import Ormolu.Printer.Meat.Type
2826import Ormolu.Utils
27+import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration
2928
3029p_standaloneDerivDecl :: DerivDecl GhcPs -> R ()
3130p_standaloneDerivDecl DerivDecl {..} = do
@@ -75,26 +74,24 @@ p_clsInstDecl = \case
7574 -- location order. This happens because different declarations are stored in
7675 -- different lists. Consequently, to get all the declarations in proper
7776 -- order, they need to be manually sorted.
78− let binds = (getLoc &&& located' p_valDecl) <$> cid_binds
79− sigs = (getLoc &&& located' p_sigDecl) <$> cid_sigs
80− tyfam_insts =
81− (getLoc &&& located' (p_tyFamInstDecl Associated)) <$>
82− cid_tyfam_insts
83− datafam_insts =
84− (getLoc &&& located' (p_dataFamInstDecl Associated)) <$>
85− cid_datafam_insts
86− decls =
77+ let sigs = (getLoc &&& fmap (SigD NoExt)) <$> cid_sigs
78+ vals = (getLoc &&& fmap (ValD NoExt)) <$> toList cid_binds
79+ tyFamInsts =
80+ ( getLoc &&& fmap (InstD NoExt . TyFamInstD NoExt)
81+ ) <$> cid_tyfam_insts
82+ dataFamInsts =
83+ ( getLoc &&& fmap (InstD NoExt . DataFamInstD NoExt)
84+ ) <$> cid_datafam_insts
85+ allDecls =
8786 snd <$>
88− sortBy
89− (compare `on` fst)
90− (toList binds <> sigs <> tyfam_insts <> datafam_insts)
91− if not (null decls)
92− then do
93− txt " where"
94− newline
95− inci (sequence_ decls)
96− else do
97− newline
87+ sortBy (comparing fst) (sigs <> vals <> tyFamInsts <> dataFamInsts)
88+ if not (null allDecls)
89+ then do
90+ txt " where"
91+ newline -- Ensure line is added after where clause.
92+ newline -- Add newline before first declaration.
93+ inci (p_hsDecls Associated allDecls)
94+ else newline
9895 XClsInstDecl NoExt -> notImplemented "XClsInstDecl"
9996
10097p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()