removing withGHCDummyFile.

This commit is contained in:
Kazu Yamamoto
2014-04-23 16:37:24 +09:00
parent b9d4b9b66f
commit 79946f9a3d
5 changed files with 36 additions and 35 deletions

View File

@@ -37,19 +37,22 @@ infoExpr :: Options
-> FilePath -- ^ A target file.
-> Expression -- ^ A Haskell expression.
-> IO String
infoExpr opt cradle file expr = (++ "\n") <$> withGHCDummyFile
(inModuleContext opt cradle file (info opt file expr) "Cannot show info")
infoExpr opt cradle file expr = withGHC' $
inModuleContext opt cradle file (info opt file expr)
-- | Obtaining information of a target expression. (GHCi's info:)
info :: Options
-> FilePath -- ^ A target file.
-> Expression -- ^ A Haskell expression.
-> Ghc String
info opt file expr = do
void $ Gap.setCtx file
sdoc <- Gap.infoThing expr
(dflag, style) <- getFlagStyle
return $ convert opt $ showPage dflag style sdoc
info opt file expr = convert opt <$> ghandle handler body
where
body = do
void $ Gap.setCtx file
sdoc <- Gap.infoThing expr
(dflag, style) <- getFlagStyle
return $ showPage dflag style sdoc
handler (SomeException e) = return $ "Cannot show info (" ++ show e ++ ")"
----------------------------------------------------------------
@@ -71,10 +74,8 @@ typeExpr :: Options
-> Int -- ^ Line number.
-> Int -- ^ Column number.
-> IO String
typeExpr opt cradle file lineNo colNo = withGHCDummyFile $
inModuleContext opt cradle file (types opt file lineNo colNo) errmsg
where
errmsg = convert opt ([] :: [((Int,Int,Int,Int),String)])
typeExpr opt cradle file lineNo colNo = withGHC' $
inModuleContext opt cradle file (types opt file lineNo colNo)
-- | Obtaining type of a target expression. (GHCi's type:)
types :: Options
@@ -82,12 +83,16 @@ types :: Options
-> Int -- ^ Line number.
-> Int -- ^ Column number.
-> Ghc String
types opt file lineNo colNo = do
modSum <- Gap.setCtx file
(dflag, style) <- getFlagStyle
srcSpanTypes <- getSrcSpanType modSum lineNo colNo
let tups = map (toTup dflag style) $ sortBy (cmp `on` fst) srcSpanTypes
return $ convert opt tups
types opt file lineNo colNo = convert opt <$> ghandle handler body
where
body = do
modSum <- Gap.setCtx file
(dflag, style) <- getFlagStyle
srcSpanTypes <- getSrcSpanType modSum lineNo colNo
let tups = map (toTup dflag style) $ sortBy (cmp `on` fst) srcSpanTypes
return $ tups
handler (SomeException _) = return errmsg
errmsg = [] :: [((Int,Int,Int,Int),String)]
getSrcSpanType :: G.ModSummary -> Int -> Int -> Ghc [(SrcSpan, Type)]
getSrcSpanType modSum lineNo colNo = do
@@ -129,14 +134,12 @@ pretty dflag style = showOneLine dflag style . Gap.typeForUser
noWaringOptions :: [String]
noWaringOptions = ["-w:"]
inModuleContext :: Options -> Cradle -> FilePath -> Ghc String -> String -> Ghc String
inModuleContext opt cradle file action errmsg = ghandle handler $ do
inModuleContext :: Options -> Cradle -> FilePath -> Ghc String -> Ghc String
inModuleContext opt cradle file action = do
void $ initializeFlagsWithCradle opt cradle noWaringOptions False
setTargetFiles [file]
void $ G.load LoadAllTargets
action
where
handler (SomeException _) = return errmsg
----------------------------------------------------------------