2013-05-19 01:16:37 +04:00
|
|
|
module Language.Haskell.GhcMod.Check (checkSyntax, check) where
|
2010-03-11 19:03:17 +09:00
|
|
|
|
|
|
|
|
import Control.Applicative
|
2013-03-13 13:17:22 +09:00
|
|
|
import Control.Monad
|
2011-08-24 15:58:12 +09:00
|
|
|
import CoreMonad
|
2011-08-24 16:50:26 +09:00
|
|
|
import Exception
|
2010-04-28 21:43:32 +09:00
|
|
|
import GHC
|
2013-05-17 10:00:01 +09:00
|
|
|
import Language.Haskell.GhcMod.ErrMsg
|
|
|
|
|
import Language.Haskell.GhcMod.GHCApi
|
|
|
|
|
import Language.Haskell.GhcMod.Types
|
2012-10-16 03:27:35 -07:00
|
|
|
import Prelude
|
2010-03-11 19:03:17 +09:00
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
2013-05-20 14:28:56 +09:00
|
|
|
-- | Checking syntax of a target file using GHC.
|
|
|
|
|
-- Warnings and errors are returned.
|
|
|
|
|
checkSyntax :: Options
|
|
|
|
|
-> Cradle
|
2013-09-05 14:35:28 +09:00
|
|
|
-> [FilePath] -- ^ The target files.
|
2013-05-20 14:28:56 +09:00
|
|
|
-> IO String
|
2013-08-21 17:21:49 +09:00
|
|
|
checkSyntax _ _ [] = error "ghc-mod: checkSyntax: No files given"
|
|
|
|
|
checkSyntax opt cradle files = unlines <$> withGHC sessionName (check opt cradle files)
|
|
|
|
|
where
|
|
|
|
|
sessionName = case files of
|
|
|
|
|
[file] -> file
|
|
|
|
|
_ -> "MultipleFiles"
|
2010-04-28 21:43:32 +09:00
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
2013-05-20 14:28:56 +09:00
|
|
|
-- | Checking syntax of a target file using GHC.
|
|
|
|
|
-- Warnings and errors are returned.
|
|
|
|
|
check :: Options
|
|
|
|
|
-> Cradle
|
2013-09-05 14:35:28 +09:00
|
|
|
-> [FilePath] -- ^ The target files.
|
2013-05-20 14:28:56 +09:00
|
|
|
-> Ghc [String]
|
2013-08-21 17:21:49 +09:00
|
|
|
check _ _ [] = error "ghc-mod: check: No files given"
|
|
|
|
|
check opt cradle fileNames = checkIt `gcatch` handleErrMsg ls
|
2010-03-11 19:03:17 +09:00
|
|
|
where
|
2011-08-24 16:50:26 +09:00
|
|
|
checkIt = do
|
2013-09-19 16:25:36 +09:00
|
|
|
(readLog,_) <- initializeFlagsWithCradle opt cradle options True
|
2013-08-21 17:21:49 +09:00
|
|
|
setTargetFiles fileNames
|
2013-03-15 14:40:36 +09:00
|
|
|
checkSlowAndSet
|
2013-03-13 13:17:22 +09:00
|
|
|
void $ load LoadAllTargets
|
2011-08-24 16:50:26 +09:00
|
|
|
liftIO readLog
|
2012-02-27 11:23:56 +09:00
|
|
|
options
|
2013-02-12 14:21:48 +09:00
|
|
|
| expandSplice opt = "-w:" : ghcOpts opt
|
|
|
|
|
| otherwise = "-Wall" : ghcOpts opt
|
2013-09-03 14:40:51 +09:00
|
|
|
ls = lineSeparator opt
|