hsimport 0.5 → 0.5.1
raw patch · 10 files changed
+142/−4 lines, 10 filesdep ~lensPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: lens
API changes (from Hackage documentation)
Files
- CHANGELOG +11/−0
- hsimport.cabal +3/−2
- lib/HsImport/Parse.hs +23/−2
- tests/Main.hs +3/−0
- tests/goldenFiles/SymbolTest30.hs +18/−0
- tests/goldenFiles/SymbolTest31.hs +13/−0
- tests/goldenFiles/SymbolTest32.hs +19/−0
- tests/inputFiles/SymbolTest30.hs +17/−0
- tests/inputFiles/SymbolTest31.hs +17/−0
- tests/inputFiles/SymbolTest32.hs +18/−0
+ CHANGELOG view
@@ -0,0 +1,11 @@+0.5.1+-----+* Better handling of multi line imports like:++ import Control.Monad+ (when)++ import Control.Monad+ ( when+ , unless+ )
hsimport.cabal view
@@ -1,5 +1,5 @@ name: hsimport-version: 0.5+version: 0.5.1 cabal-version: >=1.9.2 build-type: Simple license: BSD3@@ -12,6 +12,7 @@ author: Daniel Trstenjak extra-source-files: README.md+ CHANGELOG tests/inputFiles/*.hs tests/goldenFiles/*.hs tests/outputFiles/.gitignore@@ -25,7 +26,7 @@ base >=3 && <5, cmdargs >=0.10.5 && <0.11, haskell-src-exts >=1.14.0 && <1.16,- lens >=3.9.2 && <4.4,+ lens >=3.9.2 && <4.5, mtl >=2.1.2 && <2.3, text >=0.11.3.1 && <1.2, split >=0.2.2 && <0.3,
lib/HsImport/Parse.hs view
@@ -1,4 +1,4 @@-{-# Language ScopedTypeVariables #-}+{-# Language ScopedTypeVariables, PatternGuards #-} module HsImport.Parse ( parseFile@@ -58,7 +58,13 @@ parseImport lastLine | lastLine <= numSrcLines = case parseFileContents source of- HS.ParseOk _ -> Just lastLine+ HS.ParseOk module_+ | oneImportDeclWithoutSymbols module_ && startsWithImportDeclSymbols lastLine+ -> parseImport (lastLine + 1)++ | otherwise+ -> Just lastLine+ HS.ParseFailed _ _ -> parseImport (lastLine + 1) | otherwise@@ -68,6 +74,21 @@ source = unlines $ take lastLine srcLines numSrcLines = length srcLines++ -- | Returns True if the module contains one ImportDecl without any explicitely+ -- listed symbols.+ 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+ | (line : _) <- drop lineNum srcLines+ , (' ' : _) <- line+ , ('(' : _) <- dropWhile (== ' ') line+ = True++ | otherwise+ = False -- | tries to find the maximal part of the source file (from the beginning) that contains
tests/Main.hs view
@@ -86,6 +86,9 @@ , test "SymbolTest27" $ A.defaultArgs { A.moduleName = "Ugah.Blub", A.symbolName = "g" } , test "SymbolTest28" $ A.defaultArgs { A.moduleName = "Ugah.Blub", A.symbolName = "d" } , test_ "SymbolTest29" (C.defaultConfig { C.prettyPrint = prettyPrint }) (A.defaultArgs { A.moduleName = "X.Y", A.symbolName = "x" })+ , test_ "SymbolTest30" (C.defaultConfig { C.prettyPrint = prettyPrint }) (A.defaultArgs { A.moduleName = "X.Y", A.symbolName = "x" })+ , test "SymbolTest31" $ A.defaultArgs { A.moduleName = "Ugah.Blub", A.symbolName = "d" }+ , test "SymbolTest32" $ A.defaultArgs { A.moduleName = "Control.Foo", A.symbolName = "foo" } ]
+ tests/goldenFiles/SymbolTest30.hs view
@@ -0,0 +1,18 @@+{-# Language PatternGuards #-}+module Blub+ ( blub+ , foo+ , bar+ ) where+import Control.Applicative+import Ugah.Blub+ ( a+ , b+ , c+ )+import X.Y ( x )+f :: Int -> Int+f = (+ 3)++r :: Int -> Int+r =
+ tests/goldenFiles/SymbolTest31.hs view
@@ -0,0 +1,13 @@+{-# Language PatternGuards #-}+module Blub+ ( blub+ , foo+ , bar+ ) where+import Control.Applicative+import Ugah.Blub (a, b, c, d)+f :: Int -> Int+f = (+ 3)++r :: Int -> Int+r =
+ tests/goldenFiles/SymbolTest32.hs view
@@ -0,0 +1,19 @@+{-# Language PatternGuards #-}+module Blub+ ( blub+ , foo+ , bar+ ) where+import Control.Applicative+ (r, t, z)+import Control.Foo (foo)+import Ugah.Blub+ ( a+ , b+ , c+ )+f :: Int -> Int+f = (+ 3)++r :: Int -> Int+r =
+ tests/inputFiles/SymbolTest30.hs view
@@ -0,0 +1,17 @@+{-# Language PatternGuards #-}+module Blub+ ( blub+ , foo+ , bar+ ) where+import Control.Applicative+import Ugah.Blub+ ( a+ , b+ , c+ )+f :: Int -> Int+f = (+ 3)++r :: Int -> Int+r =
+ tests/inputFiles/SymbolTest31.hs view
@@ -0,0 +1,17 @@+{-# Language PatternGuards #-}+module Blub+ ( blub+ , foo+ , bar+ ) where+import Control.Applicative+import Ugah.Blub+ ( a+ , b+ , c+ )+f :: Int -> Int+f = (+ 3)++r :: Int -> Int+r =
+ tests/inputFiles/SymbolTest32.hs view
@@ -0,0 +1,18 @@+{-# Language PatternGuards #-}+module Blub+ ( blub+ , foo+ , bar+ ) where+import Control.Applicative+ (r, t, z)+import Ugah.Blub+ ( a+ , b+ , c+ )+f :: Int -> Int+f = (+ 3)++r :: Int -> Int+r =