@@ -10,6 +10,7 @@ where
11import Data.Bifunctor
11import Data.Bifunctor
12import Data.Function (on)
12import Data.Function (on)
13+import Data.Generics (gcompare)
13import Data.List (sortBy)
14import Data.List (sortBy)
14import GHC hiding (GhcPs, IE)
15import GHC hiding (GhcPs, IE)
15import HsExtension
16import HsExtension
@@ -31,11 +32,11 @@ sortImports = sortBy compareIdecl . fmap (fmap sortImportLists)
32compareIdecl :: LImportDecl GhcPs -> LImportDecl GhcPs -> Ordering
33compareIdecl :: LImportDecl GhcPs -> LImportDecl GhcPs -> Ordering
33compareIdecl (L _ m0) (L _ m1) =
34compareIdecl (L _ m0) (L _ m1) =
34− if isPrelude n0
35+ case (isPrelude n0, isPrelude n1) of
35− then GT
36+ (False, False) -> n0 `compare` n1
36− else if isPrelude n1
37+ (True, False) -> GT
37− then LT
38+ (False, True) -> LT
38− else n0 `compare` n1
39+ (True, True) -> m0 `gcompare` m1
40 n0 = unLoc (ideclName m0)
41 n0 = unLoc (ideclName m0)
41 n1 = unLoc (ideclName m1)
42 n1 = unLoc (ideclName m1)