packages feed

ghc-mod 1.12.2 → 1.12.3

raw patch · 17 files changed

+141/−21 lines, 17 files

Files

CabalApi.hs view
@@ -5,6 +5,7 @@   , cabalParseFile   , cabalBuildInfo   , cabalAllDependPackages+  , cabalAllSourceDirs   , getGHCVersion   ) where @@ -43,7 +44,7 @@     Just cfile = cradleCabalFile  cradle     binfo      = cabalBuildInfo cabal     gopts      = getGHCOptions ghcOptions binfo-    idirs      = includeDirectroies cdir owdir $ hsSourceDirs binfo+    idirs      = includeDirectroies cdir owdir $ cabalAllSourceDirs cabal     depPkgs    = removeMe cfile $ cabalAllDependPackages cabal  removeMe :: FilePath -> [String] -> [String]@@ -78,6 +79,11 @@     toMaybe (x:_) = Just x  ----------------------------------------------------------------++cabalAllSourceDirs :: GenericPackageDescription -> [FilePath]+cabalAllSourceDirs = fromPackageDescription (f libBuildInfo) (f buildInfo) (f testBuildInfo) (f benchmarkBuildInfo)+  where+    f getBuildInfo = concatMap (hsSourceDirs . getBuildInfo . condTreeData)  cabalAllDependPackages :: GenericPackageDescription -> [Package] cabalAllDependPackages pd = uniqueAndSort pkgs
ChangeLog view
@@ -1,3 +1,16 @@+2013-0X-XX v1.12.3++	* "ghc-mod info" and "ghc-mod type" also check Template Haskell.++2013-03-13 v1.12.2++	* New logic to set "-fno-code" using "depanal"+	* Cleaning up the code relating to Doc/SDoc++2013-03-07 v1.12.1++	* Fixing a bug to find a sandbox.+ 2013-03-05 v1.12.0  	* "ghc-mod debug" to see which cabal file and sand box are used
Check.hs view
@@ -23,12 +23,7 @@     checkIt = do         readLog <- initializeFlagsWithCradle opt cradle options True         setTargetFile fileName-        -- To check TH, a session module graph is necessary.-        -- "load" sets a session module graph using "depanal".-        -- But we have to set "-fno-code" to DynFlags before "load".-        -- So, this is necessary redundancy.-        slow <- needsTemplateHaskell <$> depanal [] False-        when slow setSlowDynFlags+        checkSlowAndSet         void $ load LoadAllTargets         liftIO readLog     options
ErrMsg.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE BangPatterns #-}+ module ErrMsg (     LogReader   , setLogger@@ -32,7 +34,9 @@     let newdf = Gap.setLogAction df $ appendLog ref     return (newdf, reverse <$> readIORef ref)   where-    appendLog ref _ sev src _ msg = modifyIORef ref (\ls -> ppMsg src sev df msg : ls)+    appendLog ref _ sev src _ msg = do+        let !l = ppMsg src sev df msg+        modifyIORef ref (\ls -> l : ls)  ---------------------------------------------------------------- @@ -54,15 +58,17 @@      ext = showMsg dflag (errMsgExtraInfo err)  ppMsg :: SrcSpan -> Severity-> DynFlags -> SDoc -> String-ppMsg spn sev dflag msg = fromMaybe def $ do-    (line,col,_,_) <- Gap.getSrcSpan spn-    file <- normalise <$> Gap.getSrcFile spn-    let severityCaption = Gap.showSeverityCaption sev-    return $ file ++ ":" ++ show line ++ ":"-                  ++ show col ++ ":" ++ severityCaption ++ cts ++ "\0"+ppMsg spn sev dflag msg = prefix ++ cts ++ "\0"   where-    def = "ghc-mod:0:0:Probably mutual module import occurred\0"     cts  = showMsg dflag msg+    defaultPrefix+      | dopt Opt_D_dump_splices dflag = ""+      | otherwise                     = "Dummy:0:0:"+    prefix = fromMaybe defaultPrefix $ do+        (line,col,_,_) <- Gap.getSrcSpan spn+        file <- normalise <$> Gap.getSrcFile spn+        let severityCaption = Gap.showSeverityCaption sev+        return $ file ++ ":" ++ show line ++ ":" ++ show col ++ ":" ++ severityCaption  ---------------------------------------------------------------- 
GHCApi.hs view
@@ -5,7 +5,7 @@   , initializeFlagsWithCradle   , setTargetFile   , getDynamicFlags-  , setSlowDynFlags+  , checkSlowAndSet   ) where  import CabalApi@@ -121,6 +121,15 @@ setSlowDynFlags :: Ghc () setSlowDynFlags = (flip setFastOrNot False <$> getSessionDynFlags)                   >>= void . setSessionDynFlags++-- To check TH, a session module graph is necessary.+-- "load" sets a session module graph using "depanal".+-- But we have to set "-fno-code" to DynFlags before "load".+-- So, this is necessary redundancy.+checkSlowAndSet :: Ghc ()+checkSlowAndSet = do+    slow <- needsTemplateHaskell <$> depanal [] False+    when slow setSlowDynFlags  ---------------------------------------------------------------- 
Info.hs view
@@ -4,6 +4,7 @@ module Info (infoExpr, typeExpr) where  import Control.Applicative+import Control.Monad (void) import CoreUtils import Data.Function import Data.Generics@@ -143,14 +144,16 @@     withGHCDummyFile (valid ||> invalid ||> return errmsg)   where     valid = do-        _ <- initializeFlagsWithCradle opt cradle ["-w"] False+        void $ initializeFlagsWithCradle opt cradle ["-w:"] False         setTargetFile fileName-        _ <- load LoadAllTargets+        checkSlowAndSet+        void $ load LoadAllTargets         doif setContextFromTarget action     invalid = do-        _ <- initializeFlagsWithCradle opt cradle ["-w"] False+        void $ initializeFlagsWithCradle opt cradle ["-w:"] False         setTargetBuffer-        _ <- load LoadAllTargets+        checkSlowAndSet+        void $ load LoadAllTargets         doif setContextFromTarget action     setTargetBuffer = do         modgraph <- depanal [mkModuleName modstr] True
ghc-mod.cabal view
@@ -1,5 +1,5 @@ Name:                   ghc-mod-Version:                1.12.2+Version:                1.12.3 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3@@ -33,6 +33,10 @@                         test/data/ghc-mod-check/*.cabal                         test/data/ghc-mod-check/Data/*.hs                         test/data/subdir1/subdir2/dummy+                        test/data/check-test-subdir/*.cabal+                        test/data/check-test-subdir/test/*.hs+                        test/data/check-test-subdir/test/Bar/*.hs+                        test/data/check-test-subdir/src/Check/Test/*.hs Executable ghc-mod   Default-Language:     Haskell2010   Main-Is:              GHCMod.hs
test/CabalApiSpec.hs view
@@ -11,6 +11,11 @@             pkgs <- cabalAllDependPackages <$> cabalParseFile "test/data/cabalapi.cabal"             pkgs `shouldBe` ["Cabal","base","template-haskell"] +    describe "cabalAllSourceDirs" $ do+        it "extracts all hs-source-dirs" $ do+            dirs <- cabalAllSourceDirs <$> cabalParseFile "test/data/check-test-subdir/check-test-subdir.cabal"+            dirs `shouldBe` ["src", "test"]+     describe "cabalBuildInfo" $ do         it "extracts build info" $ do             info <- cabalBuildInfo <$> cabalParseFile "test/data/cabalapi.cabal"
test/CheckSpec.hs view
@@ -3,6 +3,7 @@ import CabalApi import Check import Cradle+import Data.List (isSuffixOf, isInfixOf) import Expectation import Test.Hspec import Types@@ -16,3 +17,17 @@                 cradle <- findCradle Nothing strVer                 res <- checkSyntax defaultOptions cradle "main.hs"                 res `shouldBe` "main.hs:5:1:Warning: Top-level binding with no type signature: main :: IO ()\NUL\n"++        it "can check even if a test module imports another test module located at different directory" $ do+            withDirectory_ "test/data/check-test-subdir" $ do+                cradle <- getGHCVersion >>= findCradle Nothing . fst+                res <- checkSyntax defaultOptions cradle "test/Bar/Baz.hs"+                res `shouldSatisfy` ("test/Foo.hs:3:1:Warning: Top-level binding with no type signature: foo :: [Char]\NUL\n" `isSuffixOf`)++        it "can detect mutually imported modules" $ do+            withDirectory_ "test/data" $ do+                (strVer,_) <- getGHCVersion+                cradle <- findCradle Nothing strVer+                res <- checkSyntax defaultOptions cradle "Mutual1.hs"+                res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)+            
test/InfoSpec.hs view
@@ -2,6 +2,7 @@  import CabalApi import Cradle+import Data.List (isPrefixOf) import Expectation import Info import Test.Hspec@@ -16,3 +17,28 @@                 cradle <- findCradle Nothing strVer                 res <- typeExpr defaultOptions cradle "Data.Foo" 9 5 "Data/Foo.hs"                 res `shouldBe` "9 5 11 40 \"Int -> a -> a -> a\"\n7 1 11 40 \"Int -> Integer\"\n"++        it "works with a module using TemplateHaskell" $ do+            withDirectory_ "test/data" $ do+                cradle <- getGHCVersion >>= findCradle Nothing . fst+                res <- typeExpr defaultOptions cradle "Bar" 5 1 "Bar.hs"+                res `shouldBe` unlines ["5 1 5 20 \"[Char]\""]++        it "works with a module that imports another module using TemplateHaskell" $ do+            withDirectory_ "test/data" $ do+                cradle <- getGHCVersion >>= findCradle Nothing . fst+                res <- typeExpr defaultOptions cradle "Main" 3 8 "Main.hs"+                res `shouldBe` unlines ["3 8 3 16 \"String -> IO ()\"", "3 8 3 20 \"IO ()\"", "3 1 3 20 \"IO ()\""]++    describe "infoExpr" $ do+        it "works with a module using TemplateHaskell" $ do+            withDirectory_ "test/data" $ do+                cradle <- getGHCVersion >>= findCradle Nothing . fst+                res <- infoExpr defaultOptions cradle "Bar" "foo" "Bar.hs"+                res `shouldSatisfy` ("foo :: ExpQ" `isPrefixOf`)++        it "works with a module that imports another module using TemplateHaskell" $ do+            withDirectory_ "test/data" $ do+                cradle <- getGHCVersion >>= findCradle Nothing . fst+                res <- infoExpr defaultOptions cradle "Main" "bar" "Main.hs"+                res `shouldSatisfy` ("bar :: [Char]" `isPrefixOf`)
+ test/data/Mutual1.hs view
@@ -0,0 +1,3 @@+module Mutual1 where++import Mutual2
+ test/data/Mutual2.hs view
@@ -0,0 +1,3 @@+module Mutual2 where++import Mutual1
+ test/data/check-test-subdir/check-test-subdir.cabal view
@@ -0,0 +1,15 @@+name: check-test-subdir+version: 0.1.0+build-type: Simple+cabal-version: >= 1.8++library+  build-depends: base == 4.*+  hs-source-dirs: src+  exposed-modules: Check.Test.Subdir++test-suite test+  type: exitcode-stdio-1.0+  build-depends: base == 4.*+  hs-source-dirs: test+  main-is: Main.hs
+ test/data/check-test-subdir/src/Check/Test/Subdir.hs view
@@ -0,0 +1,4 @@+module Check.Test.Subdir (subdir) where++subdir :: String+subdir = "subdir"
+ test/data/check-test-subdir/test/Bar/Baz.hs view
@@ -0,0 +1,5 @@+module Bar.Baz (baz) where+import Foo (foo)++baz :: String+baz = unwords [foo, "baz"]
+ test/data/check-test-subdir/test/Foo.hs view
@@ -0,0 +1,3 @@+module Foo (foo) where++foo = "foo"
+ test/data/check-test-subdir/test/Main.hs view
@@ -0,0 +1,5 @@+module Main where+import Bar.Baz (baz)++main :: IO ()+main = putStrLn baz