@@ -9,13 +9,14 @@ module Ormolu.Imports
11import Data.Bifunctor
11import Data.Bifunctor
12+import Data.Char (isAlphaNum)
12import Data.Function (on)
13import Data.Function (on)
13import Data.Generics (gcompare)
14import Data.Generics (gcompare)
14import Data.List (nubBy, sortBy)
15import Data.List (nubBy, sortBy)
15import GHC hiding (GhcPs, IE)
16import GHC hiding (GhcPs, IE)
16import GHC.Hs.Extension
17import GHC.Hs.Extension
17import GHC.Hs.ImpExp (IE (..))
18import GHC.Hs.ImpExp (IE (..))
18−import Ormolu.Utils (notImplemented)
19+import Ormolu.Utils (notImplemented, showOutputable)
20-- | Sort imports by module name. This also sorts explicit import lists for
21-- | Sort imports by module name. This also sorts explicit import lists for
21-- each declaration.
22-- each declaration.
@@ -77,12 +78,27 @@ getIewn = \case
78-- | Compare two @'IEWrapppedName' 'RdrName'@ things.
79-- | Compare two @'IEWrapppedName' 'RdrName'@ things.
79compareIewn :: IEWrappedName RdrName -> IEWrappedName RdrName -> Ordering
80compareIewn :: IEWrappedName RdrName -> IEWrappedName RdrName -> Ordering
80−compareIewn (IEName x) (IEName y) = unLoc x `compare` unLoc y
81+compareIewn (IEName x) (IEName y) = unLoc x `compareRdrName` unLoc y
81compareIewn (IEName _) (IEPattern _) = LT
82compareIewn (IEName _) (IEPattern _) = LT
82compareIewn (IEName _) (IEType _) = LT
83compareIewn (IEName _) (IEType _) = LT
83compareIewn (IEPattern _) (IEName _) = GT
84compareIewn (IEPattern _) (IEName _) = GT
84−compareIewn (IEPattern x) (IEPattern y) = unLoc x `compare` unLoc y
85+compareIewn (IEPattern x) (IEPattern y) = unLoc x `compareRdrName` unLoc y
85compareIewn (IEPattern _) (IEType _) = LT
86compareIewn (IEPattern _) (IEType _) = LT
86compareIewn (IEType _) (IEName _) = GT
87compareIewn (IEType _) (IEName _) = GT
87compareIewn (IEType _) (IEPattern _) = GT
88compareIewn (IEType _) (IEPattern _) = GT
88−compareIewn (IEType x) (IEType y) = unLoc x `compare` unLoc y
89+compareIewn (IEType x) (IEType y) = unLoc x `compareRdrName` unLoc y
91+compareRdrName :: RdrName -> RdrName -> Ordering
93+ case (getNameStr x, getNameStr y) of
97+ ((x' : _), (y' : _)) ->
98+ case (isAlphaNum x', isAlphaNum y') of
99+ (False, False) -> x `compare` y
102+ (True, True) -> x `compare` y
104+ getNameStr = showOutputable . rdrNameOcc