Separating IO and Ghc.

This commit is contained in:
Kazu Yamamoto
2013-05-20 11:29:44 +09:00
parent f2f3b120af
commit 849c308e5c
17 changed files with 70 additions and 75 deletions

View File

@@ -1,22 +1,33 @@
module Language.Haskell.GhcMod (
browseModule
, checkSyntax
, check
, module Language.Haskell.GhcMod.Cradle
, debugInfo
, debug
, infoExpr
, info
, typeExpr
, typeOf
, listLanguages
, lintSyntax
, listModules
, module Language.Haskell.GhcMod.Types
, listFlags
-- * Cradle
Cradle(..)
, findCradle
-- * GHC version
, getGHCVersion
, withGHCDummyFile
-- * Options
, Options(..)
, OutputStyle(..)
, defaultOptions
-- * 'IO' utilities
, browseModule
, checkSyntax
, debugInfo
, infoExpr
, typeExpr
, listModules
, listLanguages
, listFlags
, lintSyntax
-- * Converting the 'Ghc' monad to the 'IO' monad
, withGHC
, withGHCDummyFile
-- * 'Ghc' utilities
, browse
, check
, debug
, info
, typeOf
, list
) where
import Language.Haskell.GhcMod.Browse

View File

@@ -17,8 +17,8 @@ import Var
----------------------------------------------------------------
browseModule :: Options -> String -> Ghc String
browseModule opt mdlName = convert opt . format <$> browse opt mdlName
browseModule :: Options -> String -> IO String
browseModule opt mdlName = convert opt . format <$> withGHCDummyFile (browse opt mdlName)
where
format
| operators opt = formatOps

View File

@@ -12,12 +12,12 @@ import Prelude
----------------------------------------------------------------
checkSyntax :: Options -> Cradle -> String -> Ghc String
checkSyntax opt cradle file = unlines <$> check opt cradle file
checkSyntax :: Options -> Cradle -> FilePath -> IO String
checkSyntax opt cradle file = unlines <$> withGHC file (check opt cradle file)
----------------------------------------------------------------
check :: Options -> Cradle -> String -> Ghc [String]
check :: Options -> Cradle -> FilePath -> Ghc [String]
check opt cradle fileName = checkIt `gcatch` handleErrMsg
where
checkIt = do

View File

@@ -14,10 +14,10 @@ import Prelude
----------------------------------------------------------------
debugInfo :: Options -> Cradle -> String -> String -> Ghc String
debugInfo opt cradle ver fileName = unlines <$> debug opt cradle ver fileName
debugInfo :: Options -> Cradle -> String -> FilePath -> IO String
debugInfo opt cradle ver fileName = unlines <$> withGHC fileName (debug opt cradle ver fileName)
debug :: Options -> Cradle -> String -> String -> Ghc [String]
debug :: Options -> Cradle -> String -> FilePath -> Ghc [String]
debug opt cradle ver fileName = do
(gopts, incDir, pkgs) <-
if cabal then

View File

@@ -36,8 +36,8 @@ data Cmd = Info | Type deriving Eq
----------------------------------------------------------------
infoExpr :: Options -> Cradle -> ModuleString -> Expression -> FilePath -> Ghc String
infoExpr opt cradle modstr expr file = (++ "\n") <$> info opt cradle file modstr expr
infoExpr :: Options -> Cradle -> ModuleString -> Expression -> FilePath -> IO String
infoExpr opt cradle modstr expr file = (++ "\n") <$> withGHCDummyFile (info opt cradle file modstr expr)
info :: Options -> Cradle -> FilePath -> ModuleString -> Expression -> Ghc String
info opt cradle fileName modstr expr =
@@ -67,8 +67,8 @@ instance HasType (LHsBind Id) where
instance HasType (LPat Id) where
getType _ (L spn pat) = return $ Just (spn, hsPatType pat)
typeExpr :: Options -> Cradle -> ModuleString -> Int -> Int -> FilePath -> Ghc String
typeExpr opt cradle modstr lineNo colNo file = typeOf opt cradle file modstr lineNo colNo
typeExpr :: Options -> Cradle -> ModuleString -> Int -> Int -> FilePath -> IO String
typeExpr opt cradle modstr lineNo colNo file = withGHCDummyFile $ typeOf opt cradle file modstr lineNo colNo
typeOf :: Options -> Cradle -> FilePath -> ModuleString -> Int -> Int -> Ghc String
typeOf opt cradle fileName modstr lineNo colNo =

View File

@@ -10,8 +10,8 @@ import UniqFM
----------------------------------------------------------------
listModules :: Options -> Ghc String
listModules opt = convert opt . nub . sort <$> list opt
listModules :: Options -> IO String
listModules opt = convert opt . nub . sort <$> withGHCDummyFile (list opt)
list :: Options -> Ghc [String]
list opt = do