packages feed

hsimport 0.7.1 → 0.8.0

raw patch · 11 files changed

+145/−133 lines, 11 filesdep ~haskell-src-extsPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: haskell-src-exts

API changes (from Hackage documentation)

- HsImport: After :: ImportDecl -> ImportPos
+ HsImport: After :: HsImportDecl -> ImportPos
- HsImport: Before :: ImportDecl -> ImportPos
+ HsImport: Before :: HsImportDecl -> ImportPos
- HsImport.Config: Config :: (ImportDecl -> String) -> (ImportDecl -> [ImportDecl] -> Maybe ImportPos) -> Maybe String -> Config
+ HsImport.Config: Config :: (HsImportDecl -> String) -> (HsImportDecl -> [HsImportDecl] -> Maybe ImportPos) -> Maybe String -> Config
- HsImport.Config: [findImportPos] :: Config -> ImportDecl -> [ImportDecl] -> Maybe ImportPos
+ HsImport.Config: [findImportPos] :: Config -> HsImportDecl -> [HsImportDecl] -> Maybe ImportPos
- HsImport.Config: [prettyPrint] :: Config -> ImportDecl -> String
+ HsImport.Config: [prettyPrint] :: Config -> HsImportDecl -> String
- HsImport.ImportPos: After :: ImportDecl -> ImportPos
+ HsImport.ImportPos: After :: HsImportDecl -> ImportPos
- HsImport.ImportPos: Before :: ImportDecl -> ImportPos
+ HsImport.ImportPos: Before :: HsImportDecl -> ImportPos
- HsImport.ImportPos: bestMatchingImport :: ModuleName -> [ImportDecl] -> Maybe ImportDecl
+ HsImport.ImportPos: bestMatchingImport :: ModuleName -> [HsImportDecl] -> Maybe HsImportDecl
- HsImport.ImportPos: findImportPos :: ImportDecl -> [ImportDecl] -> Maybe ImportPos
+ HsImport.ImportPos: findImportPos :: HsImportDecl -> [HsImportDecl] -> Maybe ImportPos
- HsImport.ImportPos: matchingImports :: ModuleName -> [ImportDecl] -> [ImportDecl]
+ HsImport.ImportPos: matchingImports :: ModuleName -> [HsImportDecl] -> [HsImportDecl]

Files

CHANGELOG view
@@ -1,3 +1,8 @@+0.8.0+-----+* Changes for haskell-src-exts 1.18.0+* Support GHC 8.0.1+ 0.7.1 ----- * Switch from lens to microlens (for faster compiling)
hsimport.cabal view
@@ -1,5 +1,5 @@ name: hsimport-version: 0.7.1+version: 0.8.0 cabal-version: >=1.9.2 build-type: Simple license: BSD3@@ -11,7 +11,7 @@ category: Utils, Development author: Daniel Trstenjak tested-with: GHC ==7.6.2 GHC ==7.6.3 GHC ==7.8.3 GHC ==7.10.1-             GHC ==7.10.2+             GHC ==7.10.2 GHC ==8.0.1 extra-source-files:     README.md     CHANGELOG@@ -33,7 +33,7 @@     build-depends:         base >=3 && <5,         cmdargs >=0.10.5 && <0.11,-        haskell-src-exts >=1.17.0 && <1.18,+        haskell-src-exts >=1.18.0 && <1.19,         ilist >=0.1 && <0.3,         microlens ==0.4.*,         mtl >=2.1.2 && <2.3,@@ -73,7 +73,7 @@         tasty >=0.9.0.1 && <0.12,         tasty-golden >=2.2.0.1 && <2.4,         filepath >=1.3.0.1 && <1.5,-        haskell-src-exts >=1.17.0 && <1.18,+        haskell-src-exts >=1.18.0 && <1.19,         hsimport -any     hs-source-dirs: tests     ghc-options: -W
lib/HsImport/Config.hs view
@@ -8,12 +8,14 @@ import qualified HsImport.PrettyPrint as PP import qualified HsImport.ImportPos as IP +type HsImportDecl = HS.ImportDecl HS.SrcSpanInfo+ -- | User definable configuration for hsImport. data Config = Config    { -- | function for pretty printing of the import declarations-     prettyPrint :: HS.ImportDecl -> String+     prettyPrint :: HsImportDecl -> String      -- | function for finding the position of new import declarations-   , findImportPos :: HS.ImportDecl -> [HS.ImportDecl] -> Maybe IP.ImportPos+   , findImportPos :: HsImportDecl -> [HsImportDecl] -> Maybe IP.ImportPos      -- | error during configuration of hsimport    , configError :: Maybe String    }
lib/HsImport/ImportChange.hs view
@@ -15,18 +15,20 @@ import HsImport.ImportPos (matchingImports) import HsImport.Utils -type SrcLine = Int+type SrcLine      = Int+type HsImportDecl = HS.ImportDecl HS.SrcSpanInfo+type HsModule     = HS.Module HS.SrcSpanInfo  -- | How the import declarations should be changed-data ImportChange = ReplaceImportAt SrcLine HS.ImportDecl -- ^ replace the import declaration at SrcLine-                  | AddImportAfter SrcLine HS.ImportDecl  -- ^ add import declaration after SrcLine-                  | AddImportAtEnd HS.ImportDecl          -- ^ add import declaration at end of source file-                  | FindImportPos HS.ImportDecl           -- ^ search for an insert position for the import declaration-                  | NoImportChange                        -- ^ no changes of the import declarations+data ImportChange = ReplaceImportAt SrcLine HsImportDecl -- ^ replace the import declaration at SrcLine+                  | AddImportAfter SrcLine HsImportDecl  -- ^ add import declaration after SrcLine+                  | AddImportAtEnd HsImportDecl          -- ^ add import declaration at end of source file+                  | FindImportPos HsImportDecl           -- ^ search for an insert position for the import declaration+                  | NoImportChange                       -- ^ no changes of the import declarations                   deriving (Show)  -importChanges :: Module -> Maybe Symbol -> HS.Module -> [ImportChange]+importChanges :: Module -> Maybe Symbol -> HsModule -> [ImportChange] importChanges (Module moduleName False Nothing) Nothing hsModule =    [ importModule moduleName hsModule ] @@ -42,7 +44,7 @@    ]  -importModule :: String -> HS.Module -> ImportChange+importModule :: String -> HsModule -> ImportChange importModule moduleName module_    | matching@(_:_) <- matchingImports moduleName (importDecls module_) =       if any entireModuleImported matching@@ -58,14 +60,14 @@            Nothing      -> AddImportAtEnd (importDecl moduleName)  -importModuleWithSymbol :: String -> Symbol -> HS.Module -> ImportChange+importModuleWithSymbol :: String -> Symbol -> HsModule -> ImportChange importModuleWithSymbol moduleName symbol module_    | matching@(_:_) <- matchingImports moduleName (importDecls module_) =       if any entireModuleImported matching || any (symbolImported symbol) matching          then NoImportChange          else case find hasImportedSymbols matching of                    Just impDecl ->-                      ReplaceImportAt (srcLine impDecl) (addSymbol impDecl symbol)+                      ReplaceImportAt (importDeclSrcLine impDecl) (addSymbol impDecl symbol)                     Nothing      ->                       FindImportPos $ importDeclWithSymbol moduleName symbol@@ -79,10 +81,13 @@            Nothing      -> AddImportAtEnd (importDeclWithSymbol moduleName symbol)    where       addSymbol (id@HS.ImportDecl {HS.importSpecs = specs}) symbol =-         id {HS.importSpecs = specs & _Just . _2 %~ (++ [importSpec symbol])}+         id {HS.importSpecs = specs & _Just %~ extendSpecList symbol} +      extendSpecList symbol (HS.ImportSpecList srcSpan hid specs) =+         HS.ImportSpecList srcSpan hid (specs ++ [importSpec symbol]) -importQualifiedModule :: String -> String -> HS.Module -> ImportChange++importQualifiedModule :: String -> String -> HsModule -> ImportChange importQualifiedModule moduleName qualifiedName module_    | matching@(_:_) <- matchingImports moduleName (importDecls module_) =       if any (hasQualifiedImport qualifiedName) matching@@ -98,7 +103,7 @@            Nothing      -> AddImportAtEnd (qualifiedImportDecl moduleName qualifiedName)  -importModuleAs :: String -> String -> HS.Module -> ImportChange+importModuleAs :: String -> String -> HsModule -> ImportChange importModuleAs moduleName asName module_    | matching@(_:_) <- matchingImports moduleName (importDecls module_) =       if any (hasAsImport asName) matching@@ -114,25 +119,25 @@            Nothing      -> AddImportAtEnd (asImportDecl moduleName asName)  -entireModuleImported :: HS.ImportDecl -> Bool+entireModuleImported :: HsImportDecl -> Bool entireModuleImported import_ =    not (HS.importQualified import_) && isNothing (HS.importSpecs import_)  -hasQualifiedImport :: String -> HS.ImportDecl -> Bool+hasQualifiedImport :: String -> HsImportDecl -> Bool hasQualifiedImport qualifiedName import_    | HS.importQualified import_-   , Just (HS.ModuleName importAs) <- HS.importAs import_+   , Just (HS.ModuleName _ importAs) <- HS.importAs import_    , importAs == qualifiedName    = True     | otherwise = False  -hasAsImport :: String -> HS.ImportDecl -> Bool+hasAsImport :: String -> HsImportDecl -> Bool hasAsImport asName import_    | not $ HS.importQualified import_-   , Just (HS.ModuleName importAs) <- HS.importAs import_+   , Just (HS.ModuleName _ importAs) <- HS.importAs import_    , importAs == asName    = True @@ -140,43 +145,45 @@    = False  -symbolImported :: Symbol -> HS.ImportDecl -> Bool+symbolImported :: Symbol -> HsImportDecl -> Bool symbolImported symbol import_-   | Just (False, hsSymbols) <- HS.importSpecs import_+   | Just (HS.ImportSpecList _ False hsSymbols) <- HS.importSpecs import_    , any (imports symbol) hsSymbols    = True     | otherwise    = False    where-      imports (Symbol symName)             (HS.IVar name)                    = symName == nameString name-      imports (Symbol symName)             (HS.IAbs _ name)                  = symName == nameString name-      imports (Symbol symName)             (HS.IThingAll name)               = symName == nameString name-      imports (Symbol symName)             (HS.IThingWith name _)            = symName == nameString name-      imports (AllOfSymbol symName)        (HS.IThingAll name)               = symName == nameString name-      imports (SomeOfSymbol symName _    ) (HS.IThingAll name)               = symName == nameString name-      imports (SomeOfSymbol symName names) (HS.IThingWith hsSymName hsNames) =+      imports (Symbol symName)             (HS.IVar _ name)                    = symName == nameString name+      imports (Symbol symName)             (HS.IAbs _ _ name)                  = symName == nameString name+      imports (Symbol symName)             (HS.IThingAll _ name)               = symName == nameString name+      imports (Symbol symName)             (HS.IThingWith _ name _)            = symName == nameString name+      imports (AllOfSymbol symName)        (HS.IThingAll _ name)               = symName == nameString name+      imports (SomeOfSymbol symName _    ) (HS.IThingAll _ name)               = symName == nameString name+      imports (SomeOfSymbol symName names) (HS.IThingWith _ hsSymName hsNames) =          symName == nameString hsSymName && null (names \\ (map (nameString . toName) hsNames))        imports _ _ = False -      nameString (HS.Ident  id)  = id-      nameString (HS.Symbol sym) = sym+      nameString (HS.Ident _ id)   = id+      nameString (HS.Symbol _ sym) = sym -      toName (HS.VarName name) = name-      toName (HS.ConName name) = name+      toName (HS.VarName _ name) = name+      toName (HS.ConName _ name) = name  -hasImportedSymbols :: HS.ImportDecl -> Bool+hasImportedSymbols :: HsImportDecl -> Bool hasImportedSymbols import_-   | Just (False, _:_) <- HS.importSpecs import_ = True-   | otherwise                                   = False+   | Just (HS.ImportSpecList _ False (_:_)) <- HS.importSpecs import_+   = True +   | otherwise+   = False -importDecl :: String -> HS.ImportDecl+importDecl :: String -> HsImportDecl importDecl moduleName = HS.ImportDecl-   { HS.importLoc       = HS.SrcLoc "" 0 0-   , HS.importModule    = HS.ModuleName moduleName+   { HS.importAnn       = HS.noSrcSpan+   , HS.importModule    = HS.ModuleName HS.noSrcSpan moduleName    , HS.importQualified = False    , HS.importSrc       = False    , HS.importSafe      = False@@ -186,48 +193,61 @@    }  -importDeclWithSymbol :: String -> Symbol -> HS.ImportDecl+importDeclWithSymbol :: String -> Symbol -> HsImportDecl importDeclWithSymbol moduleName symbol =-   (importDecl moduleName) { HS.importSpecs = Just (False, [importSpec symbol]) }+   (importDecl moduleName) { HS.importSpecs = Just (HS.ImportSpecList HS.noSrcSpan+                                                                      False+                                                                      [importSpec symbol])+                           }  -qualifiedImportDecl :: String -> String -> HS.ImportDecl+qualifiedImportDecl :: String -> String -> HsImportDecl qualifiedImportDecl moduleName qualifiedName =    (importDecl moduleName) { HS.importQualified = True                            , HS.importAs        = if moduleName /= qualifiedName-                                                     then Just $ HS.ModuleName qualifiedName+                                                     then Just $ HS.ModuleName HS.noSrcSpan qualifiedName                                                      else Nothing                            }  -asImportDecl :: String -> String -> HS.ImportDecl+asImportDecl :: String -> String -> HsImportDecl asImportDecl moduleName asName =    (importDecl moduleName) { HS.importQualified = False-                           , HS.importAs        = Just $ HS.ModuleName asName+                           , HS.importAs        = Just $ HS.ModuleName HS.noSrcSpan asName                            }  -importSpec :: Symbol -> HS.ImportSpec-importSpec (Symbol symName)             = HS.IVar $ hsName symName-importSpec (AllOfSymbol symName)        = HS.IThingAll $ hsName symName-importSpec (SomeOfSymbol symName names) = HS.IThingWith (hsName symName) (map (HS.VarName . hsName) names)+importSpec :: Symbol -> HS.ImportSpec HS.SrcSpanInfo+importSpec (Symbol symName)             = HS.IVar HS.noSrcSpan (hsName symName)+importSpec (AllOfSymbol symName)        = HS.IThingAll HS.noSrcSpan (hsName symName)+importSpec (SomeOfSymbol symName names) = HS.IThingWith HS.noSrcSpan+                                                        (hsName symName)+                                                        (map ((HS.VarName HS.noSrcSpan) . hsName) names)  -hsName :: String -> HS.Name+hsName :: String -> HS.Name HS.SrcSpanInfo hsName symbolName-   | isSymbol  = HS.Symbol symbolName-   | otherwise = HS.Ident symbolName+   | isSymbol  = HS.Symbol HS.noSrcSpan symbolName+   | otherwise = HS.Ident HS.noSrcSpan symbolName    where       isSymbol = any (A.notInClass "a-zA-Z0-9_'") symbolName  -srcLineForNewImport :: HS.Module -> Maybe SrcLine-srcLineForNewImport (HS.Module modSrcLoc _ _ _ _ imports decls)-   | not $ null imports = Just (srcLine $ last imports)+srcLineForNewImport :: HsModule -> Maybe SrcLine+srcLineForNewImport module_ =+   case module_ of+        HS.Module srcSpan _ _ imports decls            -> newSrcLine srcSpan imports decls+        HS.XmlPage _ _ _ _ _ _ _                       -> Nothing+        HS.XmlHybrid srcSpan _ _ imports decls _ _ _ _ -> newSrcLine srcSpan imports decls+   where+      newSrcLine srcSpan imports decls+         | not $ null imports+         = Just (importDeclSrcLine $ last imports) -   | (decl:_)  <- decls-   , Just sLoc <- declSrcLoc decl-   , HS.srcLine sLoc >= HS.srcLine modSrcLoc-   = Just $ max 0 (HS.srcLine sLoc - 1)+         | (decl:_) <- decls+         , sLoc <- declSrcLoc decl+         , HS.srcLine sLoc >= spanSrcLine srcSpan+         = Just $ max 0 (HS.srcLine sLoc - 1) -   | otherwise = Nothing+         | otherwise+         = Nothing
lib/HsImport/ImportPos.hs view
@@ -15,27 +15,28 @@ import Control.Applicative ((<$>)) #endif -type ModuleName = String+type ModuleName   = String+type HsImportDecl = HS.ImportDecl HS.SrcSpanInfo  -- | Where a new import declaration should be added.-data ImportPos = Before HS.ImportDecl -- ^ before the specified import declaration-               | After  HS.ImportDecl -- ^ after the specified import declaration+data ImportPos = Before HsImportDecl -- ^ before the specified import declaration+               | After  HsImportDecl -- ^ after the specified import declaration                deriving (Show, Eq)   -- | Returns the position where the import declaration for the --   new import should be put into the list of import declarations.-findImportPos :: HS.ImportDecl -> [HS.ImportDecl] -> Maybe ImportPos+findImportPos :: HsImportDecl -> [HsImportDecl] -> Maybe ImportPos findImportPos newImport imports = After <$> bestMatchingImport name imports    where-      HS.ModuleName name = HS.importModule newImport+      HS.ModuleName _ name = HS.importModule newImport   -- | Returns all import declarations having the same module name.-matchingImports :: ModuleName -> [HS.ImportDecl] -> [HS.ImportDecl]+matchingImports :: ModuleName -> [HsImportDecl] -> [HsImportDecl] matchingImports moduleName imports =    [ i-   | i@HS.ImportDecl {HS.importModule = HS.ModuleName name} <- imports+   | i@HS.ImportDecl {HS.importModule = HS.ModuleName _ name} <- imports    , moduleName == name    ] @@ -43,7 +44,7 @@ -- | Returns the best matching import declaration for the given module name. --   E.g. if the module name is "Foo.Bar.Boo", then "Foo.Bar" is considered --   better matching than "Foo".-bestMatchingImport :: ModuleName -> [HS.ImportDecl] -> Maybe HS.ImportDecl+bestMatchingImport :: ModuleName -> [HsImportDecl] -> Maybe HsImportDecl bestMatchingImport _          []      = Nothing bestMatchingImport moduleName imports =    case ifoldl' computeMatches Nothing splittedMods of@@ -71,5 +72,5 @@        splittedMod  = splitOn "." moduleName       splittedMods = [ splitOn "." name-                     | HS.ImportDecl {HS.importModule = HS.ModuleName name} <- imports+                     | HS.ImportDecl {HS.importModule = HS.ModuleName _ name} <- imports                      ]
lib/HsImport/ImportSpec.hs view
@@ -15,7 +15,7 @@  data ImportSpec = ImportSpec    { sourceFile     :: FilePath-   , parsedSrcFile  :: HS.Module+   , parsedSrcFile  :: HS.Module HS.SrcSpanInfo    , moduleToImport :: Module    , symbolToImport :: Maybe Symbol    , saveToFile     :: Maybe FilePath
lib/HsImport/Main.hs view
@@ -82,9 +82,12 @@        applyChange srcLines (FindImportPos importDecl) =          case findImportPos importDecl allImportDecls of-              Just (After impDecl)  -> applyChange srcLines (AddImportAfter (srcLine impDecl) importDecl)-              Just (Before impDecl) -> applyChange srcLines (AddImportAfter (max 0 (srcLine impDecl - 1)) importDecl)-              _                     -> applyChange srcLines (AddImportAfter (srcLine . last $ allImportDecls) importDecl)+              Just (After impDecl)  -> applyChange srcLines (AddImportAfter (importDeclSrcLine impDecl)+                                                                            importDecl)+              Just (Before impDecl) -> applyChange srcLines (AddImportAfter (max 0 (importDeclSrcLine impDecl - 1))+                                                                            importDecl)+              _                     -> applyChange srcLines (AddImportAfter (importDeclSrcLine . last $ allImportDecls)+                                                                            importDecl)        applyChange srcLines NoImportChange = srcLines 
lib/HsImport/Parse.hs view
@@ -16,9 +16,10 @@ import Control.Applicative ((<$>)) #endif -type Error = String+type Error         = String+type HsParseResult = HS.ParseResult (HS.Module HS.SrcSpanInfo) -parseFile :: FilePath -> IO (Either Error (HS.ParseResult HS.Module))+parseFile :: FilePath -> IO (Either Error HsParseResult) parseFile file = do    srcFile <- unlines. replaceCPPByComment . lines . T.unpack <$> TIO.readFile file    catch (do let result = parseFileContents srcFile@@ -80,8 +81,8 @@        -- | Returns True if the module contains one ImportDecl without any explicitely       --   listed symbols.-      oneImportDeclWithoutSymbols (HS.Module _ _ _ _ _ [HS.ImportDecl {HS.importSpecs = Nothing}] _) = True-      oneImportDeclWithoutSymbols _                                                                  = False+      oneImportDeclWithoutSymbols (HS.Module _ _ _ [HS.ImportDecl {HS.importSpecs = Nothing}] _) = True+      oneImportDeclWithoutSymbols _                                                              = False        -- | Returns True if the line represents the starting of a ImportDecl symbol list.       startsWithImportDeclSymbols lineNum@@ -96,11 +97,11 @@  -- | tries to find the maximal part of the source file (from the beginning) that contains --   valid/complete Haskell code-parseInvalidSource :: [String] -> Int -> IO (Maybe (HS.ParseResult HS.Module))+parseInvalidSource :: [String] -> Int -> IO (Maybe HsParseResult) parseInvalidSource srcLines firstInvalidLine = do    parseInvalidSource' 1 firstInvalidLine Nothing 0    where-      parseInvalidSource' :: Int -> Int -> Maybe (Int, HS.ParseResult HS.Module) -> Int -> IO (Maybe (HS.ParseResult HS.Module))+      parseInvalidSource' :: Int -> Int -> Maybe (Int, HsParseResult) -> Int -> IO (Maybe HsParseResult)       parseInvalidSource' lastValidLine currLastLine maxParseOk iteration          | null srcLines || lastValidLine >= currLastLine          = return Nothing@@ -137,7 +138,7 @@                     _ -> Just (nextLine, nextResult)  -parseFileContents :: String -> HS.ParseResult HS.Module+parseFileContents :: String -> HsParseResult parseFileContents = HS.parseFileContentsWithMode parseMode    where       parseMode = HS.defaultParseMode { HS.fixities = Just [] }
lib/HsImport/PrettyPrint.hs view
@@ -11,7 +11,7 @@ #endif  -prettyPrint :: HS.ImportDecl -> String+prettyPrint :: HS.ImportDecl HS.SrcSpanInfo -> String prettyPrint importDecl =    -- remove newlines from pretty printed ImportDecl    case lines $ HS.prettyPrint importDecl of
lib/HsImport/Utils.hs view
@@ -1,6 +1,7 @@  module HsImport.Utils-   ( srcLine+   ( importDeclSrcLine+   , spanSrcLine    , declSrcLoc    , importDecls    ) where@@ -9,47 +10,24 @@  type SrcLine = Int -srcLine :: HS.ImportDecl -> SrcLine-srcLine = HS.srcLine . HS.importLoc+importDeclSrcLine :: HS.ImportDecl HS.SrcSpanInfo -> SrcLine+importDeclSrcLine = spanSrcLine . HS.importAnn  -declSrcLoc :: HS.Decl -> Maybe HS.SrcLoc-declSrcLoc decl =-   case decl of-        HS.TypeDecl srcLoc _ _ _            -> Just srcLoc-        HS.TypeFamDecl srcLoc _ _ _         -> Just srcLoc-        HS.ClosedTypeFamDecl srcLoc _ _ _ _ -> Just srcLoc-        HS.DataDecl srcLoc _ _ _ _ _ _      -> Just srcLoc-        HS.GDataDecl srcLoc _ _ _ _ _ _ _   -> Just srcLoc-        HS.DataFamDecl srcLoc _ _ _ _       -> Just srcLoc-        HS.TypeInsDecl srcLoc _ _           -> Just srcLoc-        HS.DataInsDecl srcLoc _ _ _ _       -> Just srcLoc-        HS.GDataInsDecl srcLoc _ _ _ _ _    -> Just srcLoc-        HS.ClassDecl srcLoc _ _ _ _ _       -> Just srcLoc-        HS.InstDecl srcLoc _ _ _ _ _ _      -> Just srcLoc-        HS.DerivDecl srcLoc _ _ _ _ _       -> Just srcLoc-        HS.InfixDecl srcLoc _ _ _           -> Just srcLoc-        HS.DefaultDecl srcLoc _             -> Just srcLoc-        HS.SpliceDecl srcLoc _              -> Just srcLoc-        HS.TypeSig srcLoc _ _               -> Just srcLoc-        HS.PatSynSig srcLoc _ _ _ _ _       -> Just srcLoc-        HS.FunBind _                        -> Nothing-        HS.PatBind srcLoc _ _ _             -> Just srcLoc-        HS.ForImp srcLoc _ _ _ _ _          -> Just srcLoc-        HS.ForExp srcLoc _ _ _ _            -> Just srcLoc-        HS.PatSyn srcLoc _ _ _              -> Just srcLoc-        HS.RulePragmaDecl srcLoc _          -> Just srcLoc-        HS.DeprPragmaDecl srcLoc _          -> Just srcLoc-        HS.WarnPragmaDecl srcLoc _          -> Just srcLoc-        HS.InlineSig srcLoc _ _ _           -> Just srcLoc-        HS.InlineConlikeSig srcLoc _ _      -> Just srcLoc-        HS.SpecSig srcLoc _ _ _             -> Just srcLoc-        HS.SpecInlineSig srcLoc _ _ _ _     -> Just srcLoc-        HS.InstSig srcLoc _ _ _ _           -> Just srcLoc-        HS.AnnPragma srcLoc _               -> Just srcLoc-        HS.MinimalPragma srcLoc _           -> Just srcLoc-        HS.RoleAnnotDecl srcLoc _ _         -> Just srcLoc+spanSrcLine :: HS.SrcSpanInfo -> SrcLine+spanSrcLine = HS.srcSpanStartLine . HS.srcInfoSpan  -importDecls :: HS.Module -> [HS.ImportDecl]-importDecls (HS.Module _ _ _ _ _ imports _) = imports+declSrcLoc :: HS.Decl HS.SrcSpanInfo -> HS.SrcLoc+declSrcLoc decl = HS.SrcLoc srcFile srcLine srcCol+   where+      srcSpan = HS.srcInfoSpan . HS.ann $ decl+      srcFile = HS.srcSpanFilename srcSpan+      srcLine = HS.srcSpanStartLine srcSpan+      srcCol  = HS.srcSpanStartColumn srcSpan+++importDecls :: HS.Module HS.SrcSpanInfo -> [HS.ImportDecl HS.SrcSpanInfo]+importDecls (HS.Module _ _ _ imports _)            = imports+importDecls (HS.XmlPage _ _ _ _ _ _ _)             = []+importDecls (HS.XmlHybrid _ _ _ imports _ _ _ _ _) = imports
tests/Main.hs view
@@ -9,6 +9,8 @@ import qualified Language.Haskell.Exts as HS import qualified HsImport as HI +type ImportDecl = HS.ImportDecl HS.SrcSpanInfo+ main = defaultMain tests  tests :: TestTree@@ -110,34 +112,34 @@       inputFile  = "tests" </> "inputFiles"  </> testName <.> "hs"  -prettyPrint :: HS.ImportDecl -> String-prettyPrint HS.ImportDecl { HS.importModule = HS.ModuleName modName, HS.importSpecs = Just (False, syms) } =+prettyPrint :: ImportDecl -> String+prettyPrint HS.ImportDecl { HS.importModule = HS.ModuleName _ modName, HS.importSpecs = Just (HS.ImportSpecList _ False syms) } =    "import " ++ modName ++ " ( " ++ ppSyms ++ " )"    where       ppSyms = intercalate " , " symNames       symNames = map symName syms -      symName (HS.IVar (HS.Ident name)) = name+      symName (HS.IVar _ (HS.Ident _ name)) = name       symName _ = ""  prettyPrint _ = "Uupps"  -importPosAfterLast :: HS.ImportDecl -> [HS.ImportDecl] -> Maybe HI.ImportPos+importPosAfterLast :: ImportDecl -> [ImportDecl] -> Maybe HI.ImportPos importPosAfterLast _ []      = Nothing importPosAfterLast _ imports = Just . HI.After . last $ imports  -importPosBeforeLast :: HS.ImportDecl -> [HS.ImportDecl] -> Maybe HI.ImportPos+importPosBeforeLast :: ImportDecl -> [ImportDecl] -> Maybe HI.ImportPos importPosBeforeLast _ []      = Nothing importPosBeforeLast _ imports = Just . HI.Before . last $ imports  -importPosAfterFirst :: HS.ImportDecl -> [HS.ImportDecl] -> Maybe HI.ImportPos+importPosAfterFirst :: ImportDecl -> [ImportDecl] -> Maybe HI.ImportPos importPosAfterFirst _ []      = Nothing importPosAfterFirst _ imports = Just . HI.After . head $ imports  -importPosBeforeFirst :: HS.ImportDecl -> [HS.ImportDecl] -> Maybe HI.ImportPos+importPosBeforeFirst :: ImportDecl -> [ImportDecl] -> Maybe HI.ImportPos importPosBeforeFirst _ []      = Nothing importPosBeforeFirst _ imports = Just . HI.Before . head $ imports