ghc-mod/Language/Haskell/GhcMod/Check.hs

71 lines
2.1 KiB
Haskell
Raw Normal View History

module Language.Haskell.GhcMod.Check (
checkSyntax
, check
, expandTemplate
, expand
) where
2010-03-11 10:03:17 +00:00
import Exception (ghandle)
2014-04-24 03:15:59 +00:00
import GHC (Ghc)
2013-05-17 01:00:01 +00:00
import Language.Haskell.GhcMod.ErrMsg
import Language.Haskell.GhcMod.GHCApi
import qualified Language.Haskell.GhcMod.Gap as Gap
2013-05-17 01:00:01 +00:00
import Language.Haskell.GhcMod.Types
2010-03-11 10:03:17 +00:00
----------------------------------------------------------------
2013-05-20 05:28:56 +00:00
-- | Checking syntax of a target file using GHC.
-- Warnings and errors are returned.
checkSyntax :: Options
-> Cradle
2013-09-05 05:35:28 +00:00
-> [FilePath] -- ^ The target files.
2013-05-20 05:28:56 +00:00
-> 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
2010-04-28 12:43:32 +00:00
----------------------------------------------------------------
2013-05-20 05:28:56 +00:00
-- | Checking syntax of a target file using GHC.
-- Warnings and errors are returned.
check :: Options
2013-09-05 05:35:28 +00:00
-> [FilePath] -- ^ The target files.
2014-04-21 05:04:58 +00:00
-> 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
2010-03-11 10:03:17 +00:00
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