Start migrating Ghc -> GhcMod monad
This commit is contained in:
@@ -2,27 +2,25 @@ module Language.Haskell.GhcMod.Boot where
|
||||
|
||||
import Control.Applicative ((<$>))
|
||||
import CoreMonad (liftIO, liftIO)
|
||||
import GHC (Ghc)
|
||||
import Language.Haskell.GhcMod.Browse
|
||||
import Language.Haskell.GhcMod.Flag
|
||||
import Language.Haskell.GhcMod.GHCApi
|
||||
import Language.Haskell.GhcMod.Lang
|
||||
import Language.Haskell.GhcMod.List
|
||||
import Language.Haskell.GhcMod.Monad
|
||||
import Language.Haskell.GhcMod.Types
|
||||
|
||||
-- | Printing necessary information for front-end booting.
|
||||
bootInfo :: Options -> Cradle -> IO String
|
||||
bootInfo opt cradle = withGHC' $ do
|
||||
initializeFlagsWithCradle opt cradle
|
||||
boot opt
|
||||
bootInfo :: Options -> IO String
|
||||
bootInfo opt = runGhcMod opt $ boot
|
||||
|
||||
-- | Printing necessary information for front-end booting.
|
||||
boot :: Options -> Ghc String
|
||||
boot opt = do
|
||||
mods <- modules opt
|
||||
boot :: GhcMod String
|
||||
boot = do
|
||||
opt <- options
|
||||
mods <- modules
|
||||
langs <- liftIO $ listLanguages opt
|
||||
flags <- liftIO $ listFlags opt
|
||||
pre <- concat <$> mapM (browse opt) preBrowsedModules
|
||||
pre <- concat <$> mapM (toGhcMod . browse opt) preBrowsedModules
|
||||
return $ mods ++ langs ++ flags ++ pre
|
||||
|
||||
preBrowsedModules :: [String]
|
||||
|
||||
@@ -3,9 +3,8 @@ module Language.Haskell.GhcMod.List (listModules, modules) where
|
||||
import Control.Applicative ((<$>))
|
||||
import Control.Exception (SomeException(..))
|
||||
import Data.List (nub, sort)
|
||||
import GHC (Ghc)
|
||||
import qualified GHC as G
|
||||
import Language.Haskell.GhcMod.GHCApi
|
||||
import Language.Haskell.GhcMod.Monad
|
||||
import Language.Haskell.GhcMod.Types
|
||||
import Packages (pkgIdMap, exposedModules, sourcePackageId, display)
|
||||
import UniqFM (eltsUFM)
|
||||
@@ -14,13 +13,13 @@ import UniqFM (eltsUFM)
|
||||
|
||||
-- | Listing installed modules.
|
||||
listModules :: Options -> Cradle -> IO String
|
||||
listModules opt cradle = withGHC' $ do
|
||||
initializeFlagsWithCradle opt cradle
|
||||
modules opt
|
||||
listModules opt _ = runGhcMod opt $ modules
|
||||
|
||||
-- | Listing installed modules.
|
||||
modules :: Options -> Ghc String
|
||||
modules opt = convert opt . arrange <$> (getModules `G.gcatch` handler)
|
||||
modules :: GhcMod String
|
||||
modules = do
|
||||
opt <- options
|
||||
convert opt . (arrange opt) <$> (getModules `G.gcatch` handler)
|
||||
where
|
||||
getModules = getExposedModules <$> G.getSessionDynFlags
|
||||
getExposedModules = concatMap exposedModules'
|
||||
@@ -29,8 +28,8 @@ modules opt = convert opt . arrange <$> (getModules `G.gcatch` handler)
|
||||
map G.moduleNameString (exposedModules p)
|
||||
`zip`
|
||||
repeat (display $ sourcePackageId p)
|
||||
arrange = nub . sort . map dropPkgs
|
||||
dropPkgs (name, pkg)
|
||||
arrange opt = nub . sort . map (dropPkgs opt)
|
||||
dropPkgs opt (name, pkg)
|
||||
| detailed opt = name ++ " " ++ pkg
|
||||
| otherwise = name
|
||||
handler (SomeException _) = return []
|
||||
|
||||
@@ -8,6 +8,7 @@ module Language.Haskell.GhcMod.Monad (
|
||||
, runGhcMod'
|
||||
, runGhcMod
|
||||
, toGhcMod
|
||||
, options
|
||||
, module Control.Monad.Reader.Class
|
||||
, module Control.Monad.Writer.Class
|
||||
, module Control.Monad.State.Class
|
||||
@@ -99,6 +100,9 @@ toGhcMod a = do
|
||||
s <- gmGhcSession <$> ask
|
||||
liftIO $ unGhc a $ Session s
|
||||
|
||||
options :: GhcMod Options
|
||||
options = gmOptions <$> ask
|
||||
|
||||
instance MonadBase IO GhcMod where
|
||||
liftBase = GhcMod . liftBase
|
||||
|
||||
|
||||
Reference in New Issue
Block a user