ghc-mod/Language/Haskell/GhcMod/Check.hs
2014-04-26 17:54:15 +09:00

71 lines
2.1 KiB
Haskell

module Language.Haskell.GhcMod.Check (
checkSyntax
, check
, expandTemplate
, expand
) where
import Exception (ghandle)
import GHC (Ghc)
import Language.Haskell.GhcMod.ErrMsg
import Language.Haskell.GhcMod.GHCApi
import qualified Language.Haskell.GhcMod.Gap as Gap
import Language.Haskell.GhcMod.Types
----------------------------------------------------------------
-- | Checking syntax of a target file using GHC.
-- Warnings and errors are returned.
checkSyntax :: Options
-> Cradle
-> [FilePath] -- ^ The target files.
-> IO String
checkSyntax _ _ [] = return ""
checkSyntax opt cradle files = withGHC sessionName $ do
initializeFlagsWithCradle opt cradle options
check opt files
where
sessionName = case files of
[file] -> file
_ -> "MultipleFiles"
options = "-Wall" : ghcOpts opt
----------------------------------------------------------------
-- | Checking syntax of a target file using GHC.
-- Warnings and errors are returned.
check :: Options
-> [FilePath] -- ^ The target files.
-> Ghc String
check opt fileNames = ghandle (handleErrMsg opt) $
withLogger opt $ setTargetFiles fileNames
----------------------------------------------------------------
-- | Expanding syntax of a target file using GHC.
-- Warnings and errors are returned.
expandTemplate :: Options
-> Cradle
-> [FilePath] -- ^ The target files.
-> IO String
expandTemplate _ _ [] = return ""
expandTemplate opt cradle files = withGHC sessionName $ do
initializeFlagsWithCradle opt cradle options
expand opt files
where
sessionName = case files of
[file] -> file
_ -> "MultipleFiles"
options = "-w:" : ghcOpts opt
----------------------------------------------------------------
-- | Expanding syntax of a target file using GHC.
-- Warnings and errors are returned.
expand :: Options
-> [FilePath] -- ^ The target files.
-> Ghc String
expand opt fileNames = ghandle (handleErrMsg opt) $
withDynFlags Gap.setDumpSplices $
withLogger opt $ setTargetFiles fileNames