ghc-mod 2.1.2 → 3.0.0
raw patch · 14 files changed
+142/−60 lines, 14 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- ChangeLog +4/−0
- Language/Haskell/GhcMod/Browse.hs +2/−0
- Language/Haskell/GhcMod/Check.hs +2/−2
- Language/Haskell/GhcMod/Cradle.hs +68/−21
- Language/Haskell/GhcMod/Debug.hs +2/−2
- Language/Haskell/GhcMod/ErrMsg.hs +1/−1
- Language/Haskell/GhcMod/GHCApi.hs +5/−5
- Language/Haskell/GhcMod/Info.hs +14/−14
- Language/Haskell/GhcMod/Types.hs +14/−11
- ghc-mod.cabal +3/−2
- src/GHCMod.hs +1/−1
- test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d/dummy +1/−0
- test/data/cabal-dev/packages-7.6.2.conf/dummy +0/−1
- test/data/cabal.sandbox.config +25/−0
ChangeLog view
@@ -1,3 +1,7 @@+2013-09-06 v3.0.0+ * Supporting the sandbox of cabal 1.18.+ * Obsoleting the support for cabal-dev+ 2013-09-04 v2.1.2 * Supporting multiple target files. (@nh2)
Language/Haskell/GhcMod/Browse.hs view
@@ -19,6 +19,7 @@ -- | Getting functions, classes, etc from a module. -- If 'detailed' is 'True', their types are also obtained.+-- If 'operators' is 'True', operators are also returned. browseModule :: Options -> ModuleString -- ^ A module name. (e.g. \"Data.List\") -> IO String@@ -38,6 +39,7 @@ -- | Getting functions, classes, etc from a module. -- If 'detailed' is 'True', their types are also obtained.+-- If 'operators' is 'True', operators are also returned. browse :: Options -> ModuleString -- ^ A module name. (e.g. \"Data.List\") -> Ghc [String]
Language/Haskell/GhcMod/Check.hs view
@@ -16,7 +16,7 @@ -- Warnings and errors are returned. checkSyntax :: Options -> Cradle- -> [FilePath] -- ^ The target files+ -> [FilePath] -- ^ The target files. -> IO String checkSyntax _ _ [] = error "ghc-mod: checkSyntax: No files given" checkSyntax opt cradle files = unlines <$> withGHC sessionName (check opt cradle files)@@ -31,7 +31,7 @@ -- Warnings and errors are returned. check :: Options -> Cradle- -> [FilePath] -- ^ The target files+ -> [FilePath] -- ^ The target files. -> Ghc [String] check _ _ [] = error "ghc-mod: check: No files given" check opt cradle fileNames = checkIt `gcatch` handleErrMsg ls
Language/Haskell/GhcMod/Cradle.hs view
@@ -2,19 +2,24 @@ import Control.Applicative ((<$>)) import Control.Exception (throwIO)-import Control.Monad+import Control.Monad (unless, filterM) import Data.List (isSuffixOf)+import Distribution.System (buildPlatform)+import qualified Distribution.Text as Text (display) import Language.Haskell.GhcMod.Types-import System.Directory+import System.Directory (getCurrentDirectory, getDirectoryContents, doesFileExist, doesDirectoryExist) import System.FilePath ((</>),takeDirectory) +----------------------------------------------------------------+ -- | Finding 'Cradle'. -- An error would be thrown.-findCradle :: Maybe FilePath -- ^ A 'FilePath' for a sandbox+findCradle :: Maybe FilePath -- ^ A 'FilePath' for a sandbox. -> GHCVersion -> IO Cradle findCradle (Just sbox) strver = do- pkgConf <- checkPackageConf sbox strver+ (pkgConf,exist) <- checkPackageConf sbox strver+ unless exist $ throwIO $ userError $ pkgConf ++ " not found" wdir <- getCurrentDirectory cfiles <- cabalDir wdir return $ case cfiles of@@ -24,7 +29,7 @@ , cradleCabalFile = Nothing , cradlePackageConf = Just pkgConf }- Just (cdir,cfile) -> Cradle {+ Just (cdir,cfile,_) -> Cradle { cradleCurrentDir = wdir , cradleCabalDir = Just cdir , cradleCabalFile = Just cfile@@ -40,18 +45,36 @@ , cradleCabalFile = Nothing , cradlePackageConf = Nothing }- Just (cdir,cfile) -> do- let sbox = cdir </> "cabal-dev"- pkgConf = packageConfName sbox strver- exist <- doesDirectoryExist pkgConf+ Just (cdir,cfile,Nothing) -> do return Cradle { cradleCurrentDir = wdir , cradleCabalDir = Just cdir , cradleCabalFile = Just cfile+ , cradlePackageConf = Nothing+ }+ Just (cdir,cfile,Just sbox) -> do+ (pkgConf,exist) <- checkPackageConf sbox strver+ return Cradle {+ cradleCurrentDir = wdir+ , cradleCabalDir = Just cdir+ , cradleCabalFile = Just cfile , cradlePackageConf = if exist then Just pkgConf else Nothing } -cabalDir :: FilePath -> IO (Maybe (FilePath,FilePath))+----------------------------------------------------------------++cabalSuffix :: String+cabalSuffix = ".cabal"++cabalSuffixLength :: Int+cabalSuffixLength = length cabalSuffix++-- Finding a Cabal file up to the root directory+-- Input: a directly to investigate+-- Output: (the path to the directory containing a Cabal file+-- ,the path to the Cabal file+-- ,Just the path to the sandbox directory)+cabalDir :: FilePath -> IO (Maybe (FilePath,FilePath,Maybe FilePath)) cabalDir dir = do cnts <- (filter isCabal <$> getDirectoryContents dir) >>= filterM (\file -> doesFileExist (dir </> file))@@ -59,18 +82,42 @@ case cnts of [] | dir' == dir -> return Nothing | otherwise -> cabalDir dir'- cfile:_ -> return $ Just (dir,dir </> cfile)+ cfile:_ -> do+ msbox <- checkSandbox dir+ return $ Just (dir,dir </> cfile, msbox) where- isCabal name = ".cabal" `isSuffixOf` name && length name > 6+ isCabal name = cabalSuffix `isSuffixOf` name+ && length name > cabalSuffixLength -packageConfName :: FilePath -> String -> FilePath-packageConfName path ver = path </> "packages-" ++ ver ++ ".conf"+---------------------------------------------------------------- -checkPackageConf :: FilePath -> String -> IO FilePath-checkPackageConf path ver = do- let conf = packageConfName path ver- exist <- doesDirectoryExist conf- if exist then- return conf+sandboxConfig :: String+sandboxConfig = "cabal.sandbox.config"++sandboxDir :: String+sandboxDir = ".cabal-sandbox"++checkSandbox :: FilePath -> IO (Maybe FilePath)+checkSandbox dir = do+ let conf = dir </> sandboxConfig+ sbox = dir </> sandboxDir+ sandboxConfigExists <- doesFileExist conf+ sandboxExists <- doesDirectoryExist sbox+ if sandboxConfigExists && sandboxExists then+ return (Just sbox) else- throwIO $ userError $ conf ++ " not found"+ return Nothing++----------------------------------------------------------------++packageConfName :: GHCVersion -> FilePath+packageConfName strver = Text.display buildPlatform+ ++ "-ghc-"+ ++ strver+ ++ "-packages.conf.d"++checkPackageConf :: FilePath -> GHCVersion -> IO (FilePath, Bool)+checkPackageConf path strver = do+ let dir = path </> packageConfName strver+ exist <- doesDirectoryExist dir+ return (dir,exist)
Language/Haskell/GhcMod/Debug.hs view
@@ -18,7 +18,7 @@ debugInfo :: Options -> Cradle -> GHCVersion- -> FilePath -- ^ A target file+ -> FilePath -- ^ A target file. -> IO String debugInfo opt cradle ver fileName = unlines <$> withGHC fileName (debug opt cradle ver fileName) @@ -26,7 +26,7 @@ debug :: Options -> Cradle -> GHCVersion- -> FilePath -- ^ A target file+ -> FilePath -- ^ A target file. -> Ghc [String] debug opt cradle ver fileName = do (gopts, incDir, pkgs) <-
Language/Haskell/GhcMod/ErrMsg.hs view
@@ -22,7 +22,7 @@ ---------------------------------------------------------------- --- | A means to read the log+-- | A means to read the log. type LogReader = IO [String] ----------------------------------------------------------------
Language/Haskell/GhcMod/GHCApi.hs view
@@ -32,13 +32,13 @@ ---------------------------------------------------------------- -- | Converting the 'Ghc' monad to the 'IO' monad.-withGHCDummyFile :: Alternative m => Ghc (m a) -- ^ 'Ghc' actions created by the Ghc utilities+withGHCDummyFile :: Alternative m => Ghc (m a) -- ^ 'Ghc' actions created by the Ghc utilities. -> IO (m a) withGHCDummyFile = withGHC "Dummy" -- | Converting the 'Ghc' monad to the 'IO' monad.-withGHC :: Alternative m => FilePath -- ^ A target file displayed in an error message- -> Ghc (m a) -- ^ 'Ghc' actions created by the Ghc utilities+withGHC :: Alternative m => FilePath -- ^ A target file displayed in an error message.+ -> Ghc (m a) -- ^ 'Ghc' actions created by the Ghc utilities. -> IO (m a) withGHC file body = ghandle ignore $ runGhc (Just libdir) $ do dflags <- getSessionDynFlags@@ -154,7 +154,7 @@ ---------------------------------------------------------------- --- | Set the files that GHC will load / compile+-- | Set the files that GHC will load / compile. setTargetFiles :: (GhcMonad m) => [String] -> m () setTargetFiles [] = error "ghc-mod: setTargetFiles: No target files given" setTargetFiles files = do@@ -163,7 +163,7 @@ ---------------------------------------------------------------- --- | Return the 'DynFlags' currently in use in the GHC session+-- | Return the 'DynFlags' currently in use in the GHC session. getDynamicFlags :: IO DynFlags getDynamicFlags = runGhc (Just libdir) getSessionDynFlags
Language/Haskell/GhcMod/Info.hs view
@@ -42,18 +42,18 @@ -- | Obtaining information of a target expression. (GHCi's info:) infoExpr :: Options -> Cradle- -> FilePath -- ^ A target file- -> ModuleString -- ^ A module name- -> Expression -- ^ A Haskell expression+ -> FilePath -- ^ A target file.+ -> ModuleString -- ^ A module name.+ -> Expression -- ^ A Haskell expression. -> IO String infoExpr opt cradle file modstr expr = (++ "\n") <$> withGHCDummyFile (info opt cradle file modstr expr) -- | Obtaining information of a target expression. (GHCi's info:) info :: Options -> Cradle- -> FilePath -- ^ A target file- -> ModuleString -- ^ A module name- -> Expression -- ^ A Haskell expression+ -> FilePath -- ^ A target file.+ -> ModuleString -- ^ A module name.+ -> Expression -- ^ A Haskell expression. -> Ghc String info opt cradle file modstr expr = inModuleContext Info opt cradle file modstr exprToInfo "Cannot show info"@@ -83,20 +83,20 @@ -- | Obtaining type of a target expression. (GHCi's type:) typeExpr :: Options -> Cradle- -> FilePath -- ^ A target file- -> ModuleString -- ^ A odule name- -> Int -- ^ Line number- -> Int -- ^ Column number+ -> FilePath -- ^ A target file.+ -> ModuleString -- ^ A odule name.+ -> Int -- ^ Line number.+ -> Int -- ^ Column number. -> IO String typeExpr opt cradle file modstr lineNo colNo = withGHCDummyFile $ typeOf opt cradle file modstr lineNo colNo -- | Obtaining type of a target expression. (GHCi's type:) typeOf :: Options -> Cradle- -> FilePath -- ^ A target file- -> ModuleString -- ^ A odule name- -> Int -- ^ Line number- -> Int -- ^ Column number+ -> FilePath -- ^ A target file.+ -> ModuleString -- ^ A odule name.+ -> Int -- ^ Line number.+ -> Int -- ^ Column number. -> Ghc String typeOf opt cradle file modstr lineNo colNo = inModuleContext Type opt cradle file modstr exprToType errmsg
Language/Haskell/GhcMod/Types.hs view
@@ -3,15 +3,17 @@ module Language.Haskell.GhcMod.Types where -- | Output style.-data OutputStyle = LispStyle -- ^ S expression style- | PlainStyle -- ^ Plain textstyle+data OutputStyle = LispStyle -- ^ S expression style.+ | PlainStyle -- ^ Plain textstyle. +-- | The type for line separator. Historically, a Null string is used. newtype LineSeparator = LineSeparator String data Options = Options { outputStyle :: OutputStyle , hlintOpts :: [String] , ghcOpts :: [String]+ -- | If 'True', 'browse' also returns operators. , operators :: Bool -- | If 'True', 'browse' also returns types. , detailed :: Bool@@ -19,6 +21,7 @@ , expandSplice :: Bool -- | The sandbox directory. , sandbox :: Maybe FilePath+ -- | Line separator string. , lineSeparator :: LineSeparator } @@ -74,33 +77,33 @@ ---------------------------------------------------------------- --- | The environment where this library is used+-- | The environment where this library is used. data Cradle = Cradle {- -- | The directory where this library is executed+ -- | The directory where this library is executed. cradleCurrentDir :: FilePath- -- | The directory where a cabal file is found+ -- | The directory where a cabal file is found. , cradleCabalDir :: Maybe FilePath- -- | The file name of the found cabal file+ -- | The file name of the found cabal file. , cradleCabalFile :: Maybe FilePath- -- | The sandbox directory (e.g. \"\/foo\/bar\/packages-\<ver\>.conf/\")+ -- | The sandbox directory. (e.g. \"\/foo\/bar\/packages-\<ver\>.conf/\") , cradlePackageConf :: Maybe FilePath } deriving (Eq, Show) ---------------------------------------------------------------- --- | A single GHC option, as it would appear on the command line+-- | A single GHC option, as it would appear on the command line. type GHCOption = String type IncludeDir = FilePath type Package = String --- | GHC version in 'String'+-- | GHC version in 'String'. type GHCVersion = String --- | Haskell expression+-- | Haskell expression. type Expression = String --- | Module name+-- | Module name. type ModuleString = String data CheckSpeed = Slow | Fast
ghc-mod.cabal view
@@ -1,5 +1,5 @@ Name: ghc-mod-Version: 2.1.2+Version: 3.0.0 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3@@ -26,7 +26,8 @@ Extra-Source-Files: ChangeLog test/data/*.cabal test/data/*.hs- test/data/cabal-dev/packages-7.6.2.conf/dummy+ test/data/cabal.sandbox.config+ test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d/dummy test/data/ghc-mod-check/*.hs test/data/ghc-mod-check/*.cabal test/data/ghc-mod-check/Data/*.hs
src/GHCMod.hs view
@@ -57,7 +57,7 @@ "print detailed info" , Option "s" ["sandbox"] (ReqArg (\s opts -> opts { sandbox = Just s }) "path")- "specify cabal-dev sandbox (default 'cabal-dev`)"+ "specify a sandbox" , Option "b" ["boundary"] (ReqArg (\s opts -> opts { lineSeparator = LineSeparator s }) "sep") "specify line separator (default is Nul string)"
+ test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d/dummy view
@@ -0,0 +1,1 @@+dummy
− test/data/cabal-dev/packages-7.6.2.conf/dummy
@@ -1,1 +0,0 @@-dummy
+ test/data/cabal.sandbox.config view
@@ -0,0 +1,25 @@+-- This is a Cabal package environment file.+-- THIS FILE IS AUTO-GENERATED. DO NOT EDIT DIRECTLY.+-- Please create a 'cabal.config' file in the same directory+-- if you want to change the default settings for this sandbox.+++local-repo: /Users/kazu/work/ghc-mod/test/data/.cabal-sandbox/packages+logs-dir: /Users/kazu/work/ghc-mod/test/data/.cabal-sandbox/logs+world-file: /Users/kazu/work/ghc-mod/test/data/.cabal-sandbox/world+user-install: False+package-db: /Users/kazu/work/ghc-mod/test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d+build-summary: /Users/kazu/work/ghc-mod/test/data/.cabal-sandbox/logs/build.log++install-dirs + prefix: /Users/kazu/work/ghc-mod/test/data/.cabal-sandbox+ bindir: $prefix/bin+ libdir: $prefix/lib+ libsubdir: $arch-$os-$compiler/$pkgid+ libexecdir: $prefix/libexec+ datadir: $prefix/share+ datasubdir: $arch-$os-$compiler/$pkgid+ docdir: $datadir/doc/$arch-$os-$compiler/$pkgid+ htmldir: $docdir/html+ haddockdir: $htmldir+ sysconfdir: $prefix/etc