cleaning up APIs.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
module Language.Haskell.GhcMod.Check (checkSyntax, check) where
|
||||
|
||||
import Control.Applicative ((<$>))
|
||||
import Control.Monad (void)
|
||||
import CoreMonad (liftIO)
|
||||
import GHC (Ghc, LoadHowMuch(LoadAllTargets))
|
||||
@@ -18,7 +17,7 @@ checkSyntax :: Options
|
||||
-> [FilePath] -- ^ The target files.
|
||||
-> IO String
|
||||
checkSyntax _ _ [] = error "ghc-mod: checkSyntax: No files given"
|
||||
checkSyntax opt cradle files = convert opt <$> withGHC sessionName (check opt cradle files)
|
||||
checkSyntax opt cradle files = withGHC sessionName (check opt cradle files)
|
||||
where
|
||||
sessionName = case files of
|
||||
[file] -> file
|
||||
@@ -31,9 +30,9 @@ checkSyntax opt cradle files = convert opt <$> withGHC sessionName (check opt cr
|
||||
check :: Options
|
||||
-> Cradle
|
||||
-> [FilePath] -- ^ The target files.
|
||||
-> Ghc [String]
|
||||
-> Ghc String
|
||||
check _ _ [] = error "ghc-mod: check: No files given"
|
||||
check opt cradle fileNames = checkIt `G.gcatch` handleErrMsg ls
|
||||
check opt cradle fileNames = checkIt `G.gcatch` handleErrMsg opt
|
||||
where
|
||||
checkIt = do
|
||||
(readLog,_) <- initializeFlagsWithCradle opt cradle options True
|
||||
@@ -43,4 +42,3 @@ check opt cradle fileNames = checkIt `G.gcatch` handleErrMsg ls
|
||||
options
|
||||
| expandSplice opt = "-w:" : ghcOpts opt
|
||||
| otherwise = "-Wall" : ghcOpts opt
|
||||
ls = lineSeparator opt
|
||||
|
||||
@@ -17,14 +17,14 @@ import qualified GHC as G
|
||||
import HscTypes (SourceError, srcErrorMessages)
|
||||
import Language.Haskell.GhcMod.Doc (showPage, getStyle)
|
||||
import qualified Language.Haskell.GhcMod.Gap as Gap
|
||||
import Language.Haskell.GhcMod.Types (LineSeparator(..))
|
||||
import Language.Haskell.GhcMod.Types (LineSeparator(..), Options(..), convert)
|
||||
import Outputable (PprStyle, SDoc)
|
||||
import System.FilePath (normalise)
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
-- | A means to read the log.
|
||||
type LogReader = IO [String]
|
||||
type LogReader = IO String
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
@@ -35,11 +35,11 @@ newtype LogRef = LogRef (IORef Builder)
|
||||
newLogRef :: IO LogRef
|
||||
newLogRef = LogRef <$> newIORef id
|
||||
|
||||
readAndClearLogRef :: LogRef -> IO [String]
|
||||
readAndClearLogRef (LogRef ref) = do
|
||||
readAndClearLogRef :: Options -> LogRef -> IO String
|
||||
readAndClearLogRef opt (LogRef ref) = do
|
||||
b <- readIORef ref
|
||||
writeIORef ref id
|
||||
return $! b []
|
||||
return $! convert opt (b [])
|
||||
|
||||
appendLogRef :: DynFlags -> LineSeparator -> LogRef -> DynFlags -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
|
||||
appendLogRef df ls (LogRef ref) _ sev src style msg = do
|
||||
@@ -48,23 +48,28 @@ appendLogRef df ls (LogRef ref) _ sev src style msg = do
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
setLogger :: Bool -> DynFlags -> LineSeparator -> IO (DynFlags, LogReader)
|
||||
setLogger :: Bool -> DynFlags -> Options -> IO (DynFlags, LogReader)
|
||||
setLogger False df _ = return (newdf, undefined)
|
||||
where
|
||||
newdf = Gap.setLogAction df $ \_ _ _ _ _ -> return ()
|
||||
setLogger True df ls = do
|
||||
setLogger True df opt = do
|
||||
logref <- newLogRef
|
||||
let newdf = Gap.setLogAction df $ appendLogRef df ls logref
|
||||
return (newdf, readAndClearLogRef logref)
|
||||
return (newdf, readAndClearLogRef opt logref)
|
||||
where
|
||||
ls = lineSeparator opt
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
-- | Converting 'SourceError' to 'String'.
|
||||
handleErrMsg :: LineSeparator -> SourceError -> Ghc [String]
|
||||
handleErrMsg ls err = do
|
||||
handleErrMsg :: Options -> SourceError -> Ghc String
|
||||
handleErrMsg opt err = do
|
||||
dflag <- G.getSessionDynFlags
|
||||
style <- getStyle
|
||||
return . errBagToStrList dflag ls style . srcErrorMessages $ err
|
||||
let ret = convert opt . errBagToStrList dflag ls style . srcErrorMessages $ err
|
||||
return ret
|
||||
where
|
||||
ls = lineSeparator opt
|
||||
|
||||
errBagToStrList :: DynFlags -> LineSeparator -> PprStyle -> Bag ErrMsg -> [String]
|
||||
errBagToStrList dflag ls style = map (ppErrMsg dflag ls style) . reverse . bagToList
|
||||
|
||||
@@ -113,12 +113,11 @@ initSession build opt compOpts logging = do
|
||||
cmdOpts = ghcOptions compOpts
|
||||
idirs = includeDirs compOpts
|
||||
depPkgs = depPackages compOpts
|
||||
ls = lineSeparator opt
|
||||
setupDynamicFlags df0 = do
|
||||
df1 <- modifyFlagsWithOpts df0 cmdOpts
|
||||
let df2 = modifyFlags df1 idirs depPkgs (expandSplice opt) build
|
||||
df3 <- modifyFlagsWithOpts df2 $ ghcOpts opt
|
||||
liftIO $ setLogger logging df3 ls
|
||||
liftIO $ setLogger logging df3 opt
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -6,14 +6,12 @@ module Language.Haskell.GhcMod.Ghc (
|
||||
, browse
|
||||
, check
|
||||
, info
|
||||
, typeOf
|
||||
, types
|
||||
, modules
|
||||
, lint
|
||||
) where
|
||||
|
||||
import Language.Haskell.GhcMod.Browse
|
||||
import Language.Haskell.GhcMod.Check
|
||||
import Language.Haskell.GhcMod.GHCApi
|
||||
import Language.Haskell.GhcMod.Info
|
||||
import Language.Haskell.GhcMod.Lint
|
||||
import Language.Haskell.GhcMod.List
|
||||
|
||||
@@ -5,7 +5,7 @@ module Language.Haskell.GhcMod.Info (
|
||||
infoExpr
|
||||
, info
|
||||
, typeExpr
|
||||
, typeOf
|
||||
, types
|
||||
) where
|
||||
|
||||
import Control.Applicative ((<$>))
|
||||
@@ -13,7 +13,7 @@ import Control.Monad (void)
|
||||
import CoreMonad (liftIO)
|
||||
import CoreUtils (exprType)
|
||||
import Data.Function (on)
|
||||
import Data.Generics hiding (typeOf)
|
||||
import Data.Generics
|
||||
import Data.List (sortBy)
|
||||
import Data.Maybe (catMaybes, fromMaybe)
|
||||
import Data.Ord as O
|
||||
@@ -72,17 +72,17 @@ typeExpr :: Options
|
||||
-> Int -- ^ Column number.
|
||||
-> IO String
|
||||
typeExpr opt cradle file lineNo colNo = withGHCDummyFile $
|
||||
inModuleContext opt cradle file (typeOf opt file lineNo colNo) errmsg
|
||||
inModuleContext opt cradle file (types opt file lineNo colNo) errmsg
|
||||
where
|
||||
errmsg = convert opt ([] :: [((Int,Int,Int,Int),String)])
|
||||
|
||||
-- | Obtaining type of a target expression. (GHCi's type:)
|
||||
typeOf :: Options
|
||||
-> FilePath -- ^ A target file.
|
||||
-> Int -- ^ Line number.
|
||||
-> Int -- ^ Column number.
|
||||
-> Ghc String
|
||||
typeOf opt file lineNo colNo = do
|
||||
types :: Options
|
||||
-> FilePath -- ^ A target file.
|
||||
-> Int -- ^ Line number.
|
||||
-> Int -- ^ Column number.
|
||||
-> Ghc String
|
||||
types opt file lineNo colNo = do
|
||||
modSum <- Gap.setCtx file
|
||||
(dflag, style) <- getFlagStyle
|
||||
srcSpanTypes <- getSrcSpanType modSum lineNo colNo
|
||||
|
||||
@@ -10,15 +10,8 @@ import Language.Haskell.HLint (hlint)
|
||||
lintSyntax :: Options
|
||||
-> FilePath -- ^ A target file.
|
||||
-> IO String
|
||||
lintSyntax opt file = pack <$> lint hopts file
|
||||
lintSyntax opt file = pack . map show <$> hlint (file : "--quiet" : hopts)
|
||||
where
|
||||
LineSeparator lsep = lineSeparator opt
|
||||
pack = convert opt . map (intercalate lsep . lines)
|
||||
hopts = hlintOpts opt
|
||||
|
||||
-- | Checking syntax of a target file using hlint.
|
||||
-- Warnings and errors are returned.
|
||||
lint :: [String]
|
||||
-> FilePath -- ^ A target file.
|
||||
-> IO [String]
|
||||
lint hopts file = map show <$> hlint (file : "--quiet" : hopts)
|
||||
|
||||
Reference in New Issue
Block a user