@@ -23,6 +23,7 @@ module Language.Haskell.Stylish.Step.Imports
23
23
) where
24
24
25
25
--------------------------------------------------------------------------------
26
+ import Control.Applicative ((<|>) )
26
27
import Control.Monad (forM_ , void , when )
27
28
import qualified Data.Aeson as A
28
29
import Data.Foldable (toList )
@@ -507,19 +508,19 @@ printQualified Options{..} padNames stats ldecl = do
507
508
508
509
--------------------------------------------------------------------------------
509
510
printImport :: Bool -> GHC. IE GHC. GhcPs -> P ()
510
- printImport _ (GHC. IEVar _ name) = do
511
+ printImport _ (GHC. IEVar _ name _ ) = do
511
512
printIeWrappedName name
512
- printImport _ (GHC. IEThingAbs _ name) = do
513
+ printImport _ (GHC. IEThingAbs _ name _ ) = do
513
514
printIeWrappedName name
514
- printImport separateLists (GHC. IEThingAll _ name) = do
515
+ printImport separateLists (GHC. IEThingAll _ name _ ) = do
515
516
printIeWrappedName name
516
517
when separateLists space
517
518
putText " (..)"
518
519
printImport _ (GHC. IEModuleContents _ modu) = do
519
520
putText " module"
520
521
space
521
522
putText . GHC. moduleNameString $ GHC. unLoc modu
522
- printImport separateLists (GHC. IEThingWith _ name wildcard imps) = do
523
+ printImport separateLists (GHC. IEThingWith _ name wildcard imps _ ) = do
523
524
printIeWrappedName name
524
525
when separateLists space
525
526
let ellipsis = case wildcard of
@@ -637,24 +638,24 @@ prepareImportList =
637
638
prepareInner :: GHC. IE GHC. GhcPs -> GHC. IE GHC. GhcPs
638
639
prepareInner = \ case
639
640
-- Simplify `A ()` to `A`.
640
- GHC. IEThingWith x n GHC. NoIEWildcard [] -> GHC. IEThingAbs x n
641
- GHC. IEThingWith x n w ns ->
642
- GHC. IEThingWith x n w (sortBy (compareWrappedName `on` GHC. unLoc) ns)
641
+ GHC. IEThingWith x n GHC. NoIEWildcard [] md -> GHC. IEThingAbs x n md
642
+ GHC. IEThingWith x n w ns md ->
643
+ GHC. IEThingWith x n w (sortBy (compareWrappedName `on` GHC. unLoc) ns) md
643
644
ie -> ie
644
645
645
646
-- Merge two import items, assuming they have the same name.
646
647
ieMerge :: GHC. IE GHC. GhcPs -> GHC. IE GHC. GhcPs -> Maybe (GHC. IE GHC. GhcPs )
647
- ieMerge l@ (GHC. IEVar _ _) _ = Just l
648
- ieMerge _ r@ (GHC. IEVar _ _) = Just r
649
- ieMerge (GHC. IEThingAbs _ _) r = Just r
650
- ieMerge l (GHC. IEThingAbs _ _) = Just l
651
- ieMerge l@ (GHC. IEThingAll _ _) _ = Just l
652
- ieMerge _ r@ (GHC. IEThingAll _ _) = Just r
653
- ieMerge (GHC. IEThingWith x0 n0 w0 ns0) (GHC. IEThingWith _ _ w1 ns1)
648
+ ieMerge l@ (GHC. IEVar _ _ _ ) _ = Just l
649
+ ieMerge _ r@ (GHC. IEVar _ _ _ ) = Just r
650
+ ieMerge (GHC. IEThingAbs _ _ _ ) r = Just r
651
+ ieMerge l (GHC. IEThingAbs _ _ _ ) = Just l
652
+ ieMerge l@ (GHC. IEThingAll _ _ _ ) _ = Just l
653
+ ieMerge _ r@ (GHC. IEThingAll _ _ _ ) = Just r
654
+ ieMerge (GHC. IEThingWith x0 n0 w0 ns0 me0 ) (GHC. IEThingWith _ _ w1 ns1 me1 )
654
655
| w0 /= w1 = Nothing
655
656
| otherwise = Just $
656
657
-- TODO: sort the `ns0 ++ ns1`?
657
- GHC. IEThingWith x0 n0 w0 (nubOn GHC. lieWrappedName $ ns0 ++ ns1)
658
+ GHC. IEThingWith x0 n0 w0 (nubOn GHC. lieWrappedName $ ns0 ++ ns1) (me0 <|> me1)
658
659
ieMerge _ _ = Nothing
659
660
660
661
0 commit comments