From 560f081727a72c36dcc21eb715b34f948db517db Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Thu, 19 Sep 2013 16:25:36 +0900 Subject: [PATCH] initializeFlagsWithCradle also retuns PackageDescription. --- Language/Haskell/GhcMod/Check.hs | 2 +- Language/Haskell/GhcMod/GHCApi.hs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Language/Haskell/GhcMod/Check.hs b/Language/Haskell/GhcMod/Check.hs index 28e50eb..c9f585c 100644 --- a/Language/Haskell/GhcMod/Check.hs +++ b/Language/Haskell/GhcMod/Check.hs @@ -37,7 +37,7 @@ check _ _ [] = error "ghc-mod: check: No files given" check opt cradle fileNames = checkIt `gcatch` handleErrMsg ls where checkIt = do - readLog <- initializeFlagsWithCradle opt cradle options True + (readLog,_) <- initializeFlagsWithCradle opt cradle options True setTargetFiles fileNames checkSlowAndSet void $ load LoadAllTargets diff --git a/Language/Haskell/GhcMod/GHCApi.hs b/Language/Haskell/GhcMod/GHCApi.hs index d0ea353..1894056 100644 --- a/Language/Haskell/GhcMod/GHCApi.hs +++ b/Language/Haskell/GhcMod/GHCApi.hs @@ -17,6 +17,7 @@ import Control.Exception import Control.Monad import CoreMonad import Data.Maybe (isJust,fromJust) +import Distribution.PackageDescription (PackageDescription) import DynFlags import Exception import GHC @@ -24,8 +25,8 @@ import GHC.Paths (libdir) import Language.Haskell.GhcMod.CabalApi import Language.Haskell.GhcMod.ErrMsg import Language.Haskell.GhcMod.GHCChoice -import Language.Haskell.GhcMod.Types import qualified Language.Haskell.GhcMod.Gap as Gap +import Language.Haskell.GhcMod.Types import System.Exit import System.IO @@ -60,7 +61,7 @@ data Build = CabalPkg | SingleFile deriving Eq -- | Initialize the 'DynFlags' relating to the compilation of a single -- file or GHC session according to the 'Cradle' and 'Options' -- provided. -initializeFlagsWithCradle :: GhcMonad m => Options -> Cradle -> [GHCOption] -> Bool -> m LogReader +initializeFlagsWithCradle :: GhcMonad m => Options -> Cradle -> [GHCOption] -> Bool -> m (LogReader, Maybe PackageDescription) initializeFlagsWithCradle opt cradle ghcopts logging | cabal = withCabal |||> withoutCabal | otherwise = withoutCabal @@ -70,9 +71,11 @@ initializeFlagsWithCradle opt cradle ghcopts logging withCabal = do pkgDesc <- liftIO $ parseCabalFile $ fromJust mCradleFile compOpts <- liftIO $ getCompilerOptions ghcopts cradle pkgDesc - initSession CabalPkg opt compOpts logging - withoutCabal = - initSession SingleFile opt compOpts logging + logger <- initSession CabalPkg opt compOpts logging + return (logger, Just pkgDesc) + withoutCabal = do + logger <- initSession SingleFile opt compOpts logging + return (logger, Nothing) where compOpts = CompilerOptions ghcopts importDirs []