From 64365807f902d6b15569b44d5b0fb51ab6765df5 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Sat, 26 Apr 2014 23:03:50 +0900 Subject: [PATCH] refactoring. --- Language/Haskell/GhcMod/Info.hs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/Language/Haskell/GhcMod/Info.hs b/Language/Haskell/GhcMod/Info.hs index 3b6d1c9..0c61b2a 100644 --- a/Language/Haskell/GhcMod/Info.hs +++ b/Language/Haskell/GhcMod/Info.hs @@ -9,7 +9,6 @@ module Language.Haskell.GhcMod.Info ( ) where import Control.Applicative ((<$>)) -import Control.Monad (void) import CoreMonad (liftIO) import CoreUtils (exprType) import Data.Function (on) @@ -48,10 +47,8 @@ info :: Options -> Ghc String info opt file expr = convert opt <$> ghandle handler body where - body = inModuleContext file $ do - void $ Gap.setCtx file + body = inModuleContext file $ \_ dflag style -> do sdoc <- Gap.infoThing expr - (dflag, style) <- getFlagStyle return $ showPage dflag style sdoc handler (SomeException _) = return "Cannot show info" @@ -87,12 +84,9 @@ types :: Options -> Ghc String types opt file lineNo colNo = convert opt <$> ghandle handler body where - body = inModuleContext file $ do - modSum <- Gap.setCtx file - (dflag, style) <- getFlagStyle + body = inModuleContext file $ \modSum dflag style -> do srcSpanTypes <- getSrcSpanType modSum lineNo colNo - let tups = map (toTup dflag style) $ sortBy (cmp `on` fst) srcSpanTypes - return tups + return $ map (toTup dflag style) $ sortBy (cmp `on` fst) srcSpanTypes handler (SomeException _) = return [] getSrcSpanType :: G.ModSummary -> Int -> Int -> Ghc [(SrcSpan, Type)] @@ -132,15 +126,10 @@ pretty dflag style = showOneLine dflag style . Gap.typeForUser ---------------------------------------------------------------- -inModuleContext :: FilePath -> Ghc a -> Ghc a +inModuleContext :: FilePath -> (G.ModSummary -> DynFlags -> PprStyle -> Ghc a) -> Ghc a inModuleContext file action = withDynFlags setDeferTypeErrors $ do setTargetFiles [file] - action - ----------------------------------------------------------------- - -getFlagStyle :: Ghc (DynFlags, PprStyle) -getFlagStyle = do + modSum <- Gap.setCtx file dflag <- G.getSessionDynFlags style <- getStyle - return (dflag, style) + action modSum dflag style