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

58 lines
1.7 KiB
Haskell
Raw Normal View History

module Language.Haskell.GhcMod.Check (
checkSyntax
, check
, expandTemplate
, expand
) where
2010-03-11 10:03:17 +00:00
2014-04-28 04:52:28 +00:00
import Control.Applicative ((<$>))
2013-05-17 01:00:01 +00:00
import Language.Haskell.GhcMod.GHCApi
import qualified Language.Haskell.GhcMod.Gap as Gap
2014-04-28 12:47:08 +00:00
import Language.Haskell.GhcMod.Logger
2014-05-10 13:10:34 +00:00
import Language.Haskell.GhcMod.Monad
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.
2014-05-10 13:10:34 +00:00
checkSyntax :: [FilePath] -- ^ The target files.
-> GhcMod String
checkSyntax [] = return ""
checkSyntax files = withErrorHandler sessionName $ do
either id id <$> check files
where
sessionName = case files of
[file] -> file
_ -> "MultipleFiles"
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.
2014-05-10 13:10:34 +00:00
check :: [FilePath] -- ^ The target files.
-> GhcMod (Either String String)
check fileNames = do
2014-05-14 16:05:40 +00:00
withLogger setAllWaringFlags $ do
2014-04-28 04:52:28 +00:00
setTargetFiles fileNames
----------------------------------------------------------------
2014-04-26 11:24:47 +00:00
-- | Expanding Haskell Template.
2014-05-14 16:05:40 +00:00
expandTemplate :: [FilePath] -- ^ The target files.
-> GhcMod String
expandTemplate [] = return ""
expandTemplate files = withErrorHandler sessionName $ do
either id id <$> expand files
2010-03-11 10:03:17 +00:00
where
sessionName = case files of
[file] -> file
_ -> "MultipleFiles"
----------------------------------------------------------------
2014-04-26 11:24:47 +00:00
-- | Expanding Haskell Template.
2014-05-14 16:05:40 +00:00
expand :: [FilePath] -- ^ The target files.
-> GhcMod (Either String String)
expand fileNames = withLogger (Gap.setDumpSplices . setNoWaringFlags) $
2014-04-28 04:52:28 +00:00
setTargetFiles fileNames