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-07-12 01:30:06 +00:00
|
|
|
import Language.Haskell.GhcMod.DynFlags
|
2014-04-26 08:54:15 +00:00
|
|
|
import qualified Language.Haskell.GhcMod.Gap as Gap
|
2014-08-14 16:02:58 +00:00
|
|
|
import qualified GHC as G
|
2014-04-28 12:47:08 +00:00
|
|
|
import Language.Haskell.GhcMod.Logger
|
2014-08-14 16:02:58 +00:00
|
|
|
import Language.Haskell.GhcMod.Monad (IOish, GhcModT, withErrorHandler
|
|
|
|
, overrideGhcUserOptions)
|
2014-07-18 05:05:20 +00:00
|
|
|
import Language.Haskell.GhcMod.Target (setTargetFiles)
|
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-07-12 09:16:16 +00:00
|
|
|
checkSyntax :: IOish m
|
|
|
|
=> [FilePath] -- ^ The target files.
|
|
|
|
-> GhcModT m String
|
2014-05-10 13:10:34 +00:00
|
|
|
checkSyntax [] = return ""
|
2014-07-17 08:16:44 +00:00
|
|
|
checkSyntax files = withErrorHandler sessionName $
|
2014-05-10 13:10:34 +00:00
|
|
|
either id id <$> check 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.
|
2014-07-12 09:16:16 +00:00
|
|
|
check :: IOish m
|
|
|
|
=> [FilePath] -- ^ The target files.
|
|
|
|
-> GhcModT m (Either String String)
|
2014-08-14 18:51:49 +00:00
|
|
|
check fileNames = overrideGhcUserOptions $ \ghcOpts -> do
|
|
|
|
withLoggerTwice
|
|
|
|
setAllWaringFlags
|
|
|
|
(do _ <- G.setSessionDynFlags =<< addCmdOpts ghcOpts =<< G.getSessionDynFlags
|
|
|
|
setTargetFiles fileNames)
|
2014-08-15 07:32:28 +00:00
|
|
|
(setAllWaringFlags . setNoMaxRelevantBindings . Gap.setWarnTypedHoles . Gap.setDeferTypeErrors)
|
2014-08-14 18:51:49 +00:00
|
|
|
(do _ <- G.setSessionDynFlags =<< addCmdOpts ghcOpts =<< G.getSessionDynFlags
|
|
|
|
setTargetFiles fileNames)
|
2014-04-26 08:54:15 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2014-04-26 11:24:47 +00:00
|
|
|
-- | Expanding Haskell Template.
|
2014-07-12 09:16:16 +00:00
|
|
|
expandTemplate :: IOish m
|
|
|
|
=> [FilePath] -- ^ The target files.
|
|
|
|
-> GhcModT m String
|
2014-05-14 16:05:40 +00:00
|
|
|
expandTemplate [] = return ""
|
2014-07-17 08:16:44 +00:00
|
|
|
expandTemplate files = withErrorHandler sessionName $
|
2014-05-14 16:05:40 +00:00
|
|
|
either id id <$> expand 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-07-12 09:16:16 +00:00
|
|
|
expand :: IOish m
|
|
|
|
=> [FilePath] -- ^ The target files.
|
|
|
|
-> GhcModT m (Either String String)
|
2014-05-14 16:05:40 +00:00
|
|
|
expand fileNames = withLogger (Gap.setDumpSplices . setNoWaringFlags) $
|
2014-04-28 04:52:28 +00:00
|
|
|
setTargetFiles fileNames
|