2013-05-18 21:16:37 +00:00
|
|
|
module Language.Haskell.GhcMod.Check (checkSyntax, check) where
|
2010-03-11 10:03:17 +00:00
|
|
|
|
2014-03-27 06:08:07 +00:00
|
|
|
import Control.Applicative ((<$>))
|
|
|
|
import Control.Monad (void)
|
|
|
|
import CoreMonad (liftIO)
|
2014-03-27 06:21:18 +00:00
|
|
|
import GHC (Ghc, LoadHowMuch(LoadAllTargets))
|
|
|
|
import qualified GHC as G
|
2013-05-17 01:00:01 +00:00
|
|
|
import Language.Haskell.GhcMod.ErrMsg
|
|
|
|
import Language.Haskell.GhcMod.GHCApi
|
|
|
|
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
|
2013-08-21 08:21:49 +00:00
|
|
|
checkSyntax _ _ [] = error "ghc-mod: checkSyntax: No files given"
|
2014-04-18 08:28:12 +00:00
|
|
|
checkSyntax opt cradle files = convert opt <$> withGHC sessionName (check opt cradle 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
|
|
|
|
-> Cradle
|
2013-09-05 05:35:28 +00:00
|
|
|
-> [FilePath] -- ^ The target files.
|
2013-05-20 05:28:56 +00:00
|
|
|
-> Ghc [String]
|
2013-08-21 08:21:49 +00:00
|
|
|
check _ _ [] = error "ghc-mod: check: No files given"
|
2014-03-27 06:21:18 +00:00
|
|
|
check opt cradle fileNames = checkIt `G.gcatch` handleErrMsg ls
|
2010-03-11 10:03:17 +00:00
|
|
|
where
|
2011-08-24 07:50:26 +00:00
|
|
|
checkIt = do
|
2013-09-19 07:25:36 +00:00
|
|
|
(readLog,_) <- initializeFlagsWithCradle opt cradle options True
|
2013-08-21 08:21:49 +00:00
|
|
|
setTargetFiles fileNames
|
2014-03-27 06:21:18 +00:00
|
|
|
void $ G.load LoadAllTargets
|
2011-08-24 07:50:26 +00:00
|
|
|
liftIO readLog
|
2012-02-27 02:23:56 +00:00
|
|
|
options
|
2013-02-12 05:21:48 +00:00
|
|
|
| expandSplice opt = "-w:" : ghcOpts opt
|
|
|
|
| otherwise = "-Wall" : ghcOpts opt
|
2013-09-03 05:40:51 +00:00
|
|
|
ls = lineSeparator opt
|