2014-04-26 08:54:15 +00:00
|
|
|
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 ((<$>))
|
2014-04-24 03:15:59 +00:00
|
|
|
import GHC (Ghc)
|
2013-05-17 01:00:01 +00:00
|
|
|
import Language.Haskell.GhcMod.GHCApi
|
2014-04-26 08:54:15 +00:00
|
|
|
import qualified Language.Haskell.GhcMod.Gap as Gap
|
2014-04-28 12:47:08 +00:00
|
|
|
import Language.Haskell.GhcMod.Logger
|
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
|
2014-04-26 08:54:15 +00:00
|
|
|
checkSyntax _ _ [] = return ""
|
|
|
|
checkSyntax opt cradle files = withGHC sessionName $ do
|
2014-04-28 04:00:25 +00:00
|
|
|
initializeFlagsWithCradle opt cradle
|
2014-04-28 04:52:28 +00:00
|
|
|
either id id <$> check opt files
|
2013-08-21 08:21:49 +00:00
|
|
|
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.
|
|
|
|
check :: Options
|
2013-09-05 05:35:28 +00:00
|
|
|
-> [FilePath] -- ^ The target files.
|
2014-04-28 04:52:28 +00:00
|
|
|
-> Ghc (Either String String)
|
|
|
|
check opt fileNames = withLogger opt setAllWaringFlags $
|
|
|
|
setTargetFiles fileNames
|
2014-04-26 08:54:15 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2014-04-26 11:24:47 +00:00
|
|
|
-- | Expanding Haskell Template.
|
2014-04-26 08:54:15 +00:00
|
|
|
expandTemplate :: Options
|
|
|
|
-> Cradle
|
|
|
|
-> [FilePath] -- ^ The target files.
|
|
|
|
-> IO String
|
|
|
|
expandTemplate _ _ [] = return ""
|
|
|
|
expandTemplate opt cradle files = withGHC sessionName $ do
|
2014-04-28 04:00:25 +00:00
|
|
|
initializeFlagsWithCradle opt cradle
|
2014-04-28 04:52:28 +00:00
|
|
|
either id id <$> expand opt files
|
2010-03-11 10:03:17 +00:00
|
|
|
where
|
2014-04-26 08:54:15 +00:00
|
|
|
sessionName = case files of
|
|
|
|
[file] -> file
|
|
|
|
_ -> "MultipleFiles"
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2014-04-26 11:24:47 +00:00
|
|
|
-- | Expanding Haskell Template.
|
2014-04-26 08:54:15 +00:00
|
|
|
expand :: Options
|
|
|
|
-> [FilePath] -- ^ The target files.
|
2014-04-28 04:52:28 +00:00
|
|
|
-> Ghc (Either String String)
|
|
|
|
expand opt fileNames = withLogger opt (Gap.setDumpSplices . setNoWaringFlags) $
|
|
|
|
setTargetFiles fileNames
|